# Test bug works fine localy

**URL:** <https://forum.codecrafters.io/t/test-bug-works-fine-localy/875>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [June 28, 2024, 1:42pm UTC](https://forum.codecrafters.io/t/test-bug-works-fine-localy/875 "2024-06-28T13:42:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![giofiocco](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/giofiocco/32/799_2.png) [@giofiocco](https://forum.codecrafters.io/u/giofiocco)\
**Post date:** [June 28, 2024, 1:42pm UTC](https://forum.codecrafters.io/t/test-bug-works-fine-localy/875/1 "2024-06-28T13:42:52Z")

</div>

I’m stuck on Stage #MG5.

the code works fine locally but when submitting it fails

Here are my logs:

```auto
[tester::#MG5] Running tests for Stage #MG5 (The type builtin: executable files)
# command-line-arguments
loadinternal: cannot find runtime/cgo
[tester::#MG5] Running ./your_shell.sh
[your-program] $
[tester::#MG5] > type cat
[your-program] cat is /tmp/blueberry/blueberry/strawberry/cat
[your-program] $
[tester::#MG5] Expected first line of output to match "cat is /bin/cat", got "cat is /tmp/blueberry/blueberry/strawberry/cat"
[tester::#MG5] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

And this is the code to get the file path if the file is an executable

```c
char *getfilepath(char *file) {
  char *PATH = getenv("PATH");
  assert(PATH);
  char *path = strtok(PATH, ":");
  do {
    if (access(path, X_OK) == 0) {
      char *str = malloc(strlen(path) + 1 + strlen(file) + 1);
      sprintf(str, "%s/%s", path, file);
      return str;
    }
  } while (path = strtok(NULL, ":"));
  return NULL;
}

```

---

<div class="post-metadata">

**Author:** ![fre-ros](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/fre-ros/32/528_2.png) [@fre-ros](https://forum.codecrafters.io/u/fre-ros)\
**Post date:** [June 28, 2024, 1:51pm UTC](https://forum.codecrafters.io/t/test-bug-works-fine-localy/875/2 "2024-06-28T13:51:19Z")

</div>

You are not checking if the file exists in the paths you are iterating.

You just check if the path exist and if it does you append the filename to that path and return it, which is incorrect.

---

<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:** [July 3, 2024, 1:52pm UTC](https://forum.codecrafters.io/t/test-bug-works-fine-localy/875/3 "2024-07-03T13:52:15Z")

</div>

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