# \#MG5 Test Case Issue

**URL:** <https://forum.codecrafters.io/t/mg5-test-case-issue/15410>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [October 16, 2025, 8:18pm UTC](https://forum.codecrafters.io/t/mg5-test-case-issue/15410 "2025-10-16T20:18:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scramblerdoodle](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/scramblerdoodle/32/18688_2.png) [@scramblerdoodle](https://forum.codecrafters.io/u/scramblerdoodle)\
**Post date:** [October 16, 2025, 8:18pm UTC](https://forum.codecrafters.io/t/mg5-test-case-issue/15410/1 "2025-10-16T20:18:29Z")

</div>

I’m getting a test failure on Stage #MG5.

According to the logs, PATH is `/tmp/baz:/tmp/bar:/tmp/qux:...`.

My code is returning that the custom executable `my_exe` is in `/tmp/baz`, but the expected response is that it’s in `/tmp/bar`.

From my code logic, I reckon this would only happen if `/tmp/baz/my_exe` also exists, in which case this test case should not be failing since it’s following the correct order of looking through PATH (`baz` is in PATH before `bar`).

Here are my logs:

```auto
[compile] Compiling codecrafters-shell v0.1.0 (/app)
[compile] Finished `release` profile [optimized] target(s) in 0.54s
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#MG5] Running tests for Stage #MG5 (The type builtin: executable files)
[tester::#MG5] [setup] export PATH=/tmp/qux:$PATH
[tester::#MG5] [setup] export PATH=/tmp/bar:$PATH
[tester::#MG5] [setup] export PATH=/tmp/baz:$PATH
[tester::#MG5] [setup] PATH is now: /tmp/baz:/tmp/bar:/tmp/qux:...
[tester::#MG5] [setup] Available executables:
[tester::#MG5] [setup] - my_exe
[tester::#MG5] Running ./your_program.sh
[your-program] $ type cat
[your-program] cat is /usr/bin/cat
[tester::#MG5] ✓ Received expected response
[your-program] $ type cp
[your-program] cp is /usr/bin/cp
[tester::#MG5] ✓ Received expected response
[your-program] $ type mkdir
[your-program] mkdir is /usr/bin/mkdir
[tester::#MG5] ✓ Received expected response
[your-program] $ type my_exe
[your-program] my_exe is /tmp/baz/my_exe
[tester::#MG5] ^ Line does not match expected value.
[tester::#MG5] Expected: "my_exe is /tmp/bar/my_exe"
[tester::#MG5] Received: "my_exe is /tmp/baz/my_exe"
[your-program] $ 
[tester::#MG5] Assertion failed.
[tester::#MG5] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

Code is written in Rust.

Here’s the snippet for reading PATH from env:

```rust
    let env_path = env::var("PATH").unwrap_or("".to_string());
    let path: Vec<&str> = env_path.split(":").collect();

```

And here’s the snippet that handles traversing the folders in PATH:

```rust
    for &dir in path {
        let paths = fs::read_dir(dir);
        match paths {
            Ok(dir_contents) => {
                for bin_path in dir_contents {
                    let bin = bin_path.as_ref().unwrap().file_name();
                    let bin_str = bin.to_str().unwrap();

                    if bin_str == args[0] {
                        let path_str = bin_path.unwrap().path();
                        println!("{} is {}", bin_str, path_str.display());

                        return Ok(());
                    }
                }
            }
            Err(_e) => (), // TODO: improve error handling
        }
    }

```

---

<div class="post-metadata">

**Author:** ![scramblerdoodle](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/scramblerdoodle/32/18688_2.png) [@scramblerdoodle](https://forum.codecrafters.io/u/scramblerdoodle)\
**Post date:** [October 16, 2025, 8:24pm UTC](https://forum.codecrafters.io/t/mg5-test-case-issue/15410/3 "2025-10-16T20:24:01Z")

</div>

Might have figured it out – `my_exe` might be a folder in `/tmp/baz`, I’m not checking if it’s an executable. Will update in a bit.

Edit: Yup. Needs to be an executable file. Sorry!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [October 21, 2025, 8:24pm UTC](https://forum.codecrafters.io/t/mg5-test-case-issue/15410/6 "2025-10-21T20:24:54Z")

</div>

Closed on October 21, 2025, 8:24pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
