I’m stuck on Stage #JV1
I believe I have implemented the solution correctly and I see the correct output when I run the test locally. However, I see a different out put when running codecrafters test
and I cannot explain the difference.
When I run codecrafters test
, I get:
remote: [tester::#JV1] Running tests for Stage #JV1 (Redirection - Redirect stdout)
remote: [tester::#JV1] Running ./your_program.sh
remote: [tester::#JV1] Writing file "/tmp/foo/apple" with content "apple"
remote: [tester::#JV1] Writing file "/tmp/foo/grape" with content "grape"
remote: [tester::#JV1] Writing file "/tmp/foo/orange" with content "orange"
remote: [your-program] $ ls /tmp/foo > /tmp/quz/baz.md
remote: [your-program] $ cat /tmp/quz/baz.md
remote: [your-program] apple
remote: [your-program] grape
remote: [your-program] orange
remote: [tester::#JV1] ✓ Received redirected file content
remote: [your-program] $ echo 'Hello Emily' 1> /tmp/quz/qux.md
remote: [your-program] $ cat /tmp/quz/qux.md
remote: [your-program] Hello Emily
remote: [tester::#JV1] ✓ Received redirected file content
remote: [your-program] $ cat /tmp/foo/grape nonexistent 1> /tmp/quz/quz.md
remote: [your-program] /usr/bin/cat: nonexistent: No such file or directory
remote: [tester::#JV1] Output does not match expected value.
remote: [tester::#JV1] Expected: "cat: nonexistent: No such file or directory"
remote: [tester::#JV1] Received: "/usr/bin/cat: nonexistent: No such file or directory"
remote: [your-program] $
remote: [tester::#JV1] Assertion failed.
remote: [tester::#JV1] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
Note the problem is that the difference between the expected and the received output is that in the expected output, the name of the program is cat
and in the received output, the name of the output is /usr/bin/cat
.
When I run the test locally, I cannot reproduce the same issue, e.g.:
➜ codecrafters-shell-rust git:(master) ./your_program.sh
Finished `release` profile [optimized] target(s) in 0.00s
$ mkdir /tmp/foo
$ echo grape > /tmp/foo/grape
$ cat /tmp/foo/grape
grape
$ cat /tmp/foo/grape nonexistent 1> /tmp/a
cat: nonexistent: No such file or directory
And here’s a snippet of my code:
fn handle_other_command(
mut stdout: Box<dyn io::Write>,
mut stderr: Box<dyn io::Write>,
path: &[String],
argv0: String,
argv: &[String],
) {
match look_in_path(path, &argv0) {
Some(argv0) => {
let res = Command::new(argv0).args(argv).output().unwrap();
let out = String::from_utf8_lossy(&res.stdout);
let err = String::from_utf8_lossy(&res.stderr);
write!(stdout, "{}", out).unwrap();
write!(stderr, "{}", err).unwrap();
}
None => writeln!(stdout, "{}: command not found", argv0).unwrap(),
}
}
I am wondering if somehow there is an unexpected difference between the test machine and my local setup and that is causing the problem.