Local output different from test logs

I’m stuck on “The type builtin: executable files #mg5” challenge
Here are my logs:

[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/baz:$PATH
[tester::#MG5] [setup] Available executables:
[tester::#MG5] [setup] - my_exe
[tester::#MG5] Running ./your_program.sh
[your-program] $ type cat
[tester::#MG5] Output does not match expected value.
[tester::#MG5] Expected: "cat is /bin/cat"
[tester::#MG5] Received: ""
[tester::#MG5] Assertion failed.
[tester::#MG5] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
include relevant logs here (please make sure to keep the backticks around this!)

Here is my local output:

$ type cat
cat is /usr/bin/cat   
cat: is not a built in

And here’s a snippet of my code:

int check_executable(const char *path){
   return access(path, X_OK) == 0;
}

char *find_in_path(char *arguments){
  char *path=getenv("PATH");
  if(path==NULL){
    perror("error not found");
    return NULL;
  }
  char *path_buffer=malloc(sizeof(char)*strlen(path)+1);
    strncpy(path_buffer,path,GENERAL_BUFF_SIZE-1);
    char *full_path=malloc(sizeof(char)*GENERAL_BUFF_SIZE);
    if(full_path==NULL){
      perror("error in allocation");
      free(path_buffer);
      exit(1);
    }
    char *DIR = strtok(path_buffer,":");
    while( DIR != NULL){
      snprintf(full_path,GENERAL_BUFF_SIZE,"%s/%s",DIR,arguments);
      if(check_executable(full_path)){
        free(path_buffer);
        return full_path;
      }
        DIR=strtok(NULL,":");
    }
    free(path_buffer);
    free(full_path);
    return NULL;
}
else if(strncmp(input,"type ",strlen("type "))==0){
    size_t length=sizeof(built_ins)/sizeof(built_ins[0]);
    char *arguments= input+strlen("type ");
    char* path=find_in_path(arguments);
    if(path){
      printf("%s is %s\n",arguments,path);
    }
    else{
      printf("%s is not found\n",arguments);
    }
include relevant code here (please make sure to keep the backticks around this!)

Hi @Fruitpunch44, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Hi @Fruitpunch44, I tried running your code against the previous stages, but it’s actually no longer passing the stage #CZ2 (Handle invalid commands).

Suggestions:

  1. Use our CLI to test against previous stages by running:
codecrafters test --previous
  1. Focus on fixing the early stages first, as later stages depend on them.