-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move pager configuration near render logic #231
Conversation
Could you write a test so that the discussed refactor later doesn't break this again? I think it would be really cool if you mocked the pager with some shell script that just writes a file to a tempdir when called. Then you would just have to set the script as the pager through the environment variable. If you don't want to, we can also open a new issue for someone else to write the test though :) |
@niklasmohrin I'd be happy to, just a few issues I can see:
|
Hm, that actually sounds like a useful combination though. If you want, you could change that behavior in a separate PR:
I'm not sure what @niklasmohrin had in mind, but cleanup sounds like a good thing. The thing is that it'll be a bit tricky. You cannot write the file to a static path, because then multiple tests would overwrite the file. And if you use a random path, you need some way to communicate that path between the test and the mock pager. Ideally you would somehow be able to pass a filepath from the test to the mock pager. Then the test could reuse the Oh, and the mock pager script doesn't necessarily need to be a hard-to-port shell script, it could be a new Rust crate in a subdirectory as well ( |
I'm not sure what you have in mind, when we just want to run an update, a pager seems completely unnecessary anyway |
@tranzystorek-io uh, sorry, you're right. I was thinking of |
Why is that? I think it should work. |
Nevermind, I misunderstood how |
AFAIK a binary crate cannot be a dependency, unfortunately |
@tranzystorek-io hm, you're right. you can have both a bin.rs and a lib.rs in your crate, but if you add a dependency, then only the lib part will be built. |
My initial idea was to have a short script that creates a file (it would be even easier with #[test]
fn test_pager_is_called() {
let testenv = TestEnv::new();
testenv.add_entry("thecommand", "thecontent");
let logfile = testenv.cache_dir.path().join("tealdeer_log.txt");
assert!(!logfile.exists());
testenv
.command()
.env("PAGER", format!("touch {}", logfile.display()))
.arg("--pager") // <- Comment and uncomment this line
.arg("thecommand")
.stdout(unsafe { std::process::Stdio::from_raw_fd(std::io::stdout().as_raw_fd()) })
.assert()
.success();
assert!(logfile.exists());
} |
@tranzystorek-io @dbrgn I guess testing is too difficult for now, let's leave this for later / never |
Since both calls are directly followed by |
Sounds like a good idea, we should probably make sure to a) check whether we can call |
One thing I'm worrying is that |
The |
I agree that (even without the proposed addition) |
I don't really see an issue with However, if you feel this could be improved, feel free to propose an improvement in a PR 🙂 |
In any case, the goal here is to fix #169, and moving the pager setup logic into |
I can't find it in |
Uhh, sorry @tranzystorek-io, you're right of course (I was mixing up Maybe we should handle styles for printing error messages differently instead of passing around the flag everywhere (maybe a global static or thread-local variable?). However, for now I'd say passing it to |
Didn't we discuss an |
7057d03
to
329ca93
Compare
For now, I moved the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last change request.
329ca93
to
91a2896
Compare
91a2896
to
cdb6f27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
I also ran a quick benchmark, Once
doesn't seem to make any difference 👍
cdb6f27
to
4a9763a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Fixes #169