First I thought I am loosing my mind, but the logs clearly show the testing process is incorrect
I am currently in the pwd builtin section, which is fairly easy task but my code is getting stuck in the type testcase which I have already passed before. I then hard coded the paths and tried to check if there is my_exe is expected in them, but the path my program shows seems to be the correct one and the expected path doesn’t have the my_exe file. Moreover, I have no idea why I am suddenly getting error in this testcase which I have already passed before
Any help is appreciated
Here are my logs:
remote: [your-program] $ type mkdir
remote: [tester::#MG5] ✓ Received expected response
remote: [your-program] $ type my_exe
remote: [your-program] my_exe is /tmp/quz/my_exe
remote: [tester::#MG5] Output does not match expected value.
remote: [tester::#MG5] Expected: "my_exe is /tmp/bar/my_exe"
remote: [tester::#MG5] Received: "my_exe is /tmp/quz/my_exe"
remote: [your-program] True
remote: [your-program] False
remote: [your-program] False
remote: [your-program] False
remote: [your-program] $
remote: [tester::#MG5] Assertion failed.
remote: [tester::#MG5] Test failed`
And here’s a snippet of my relevant code:
elif split_command[0] == "type":
PATH = os.environ.get("PATH")
PATH_SPLIT = PATH.split(":") #separated by : in codecrafter's server
command_path = 0
for path in PATH_SPLIT:
# print("currently in:",str(path) + "/" + str(split_command[1]))
if os.path.isfile(str(path) + "/" + str(split_command[1])):
# print(str(path) + "/" + str(split_command[1]))
command_path = str(path) + "/" + str(split_command[1])
if split_command[1] in ['echo','type','exit','pwd']:
print(split_command[1],"is a shell builtin")
elif split_command[1] == "my_exe":
print("my_exe is",command_path)
print(os.path.isfile(command_path))
print(os.path.isfile("/tmp/bar/my_exe"))
print(os.path.isfile("/tmp/qux/my_exe"))
print(os.path.isfile("/tmp/foo/my_exe"))
elif command_path:
print(split_command[1],"is",command_path)
else:
print(split_command[1],": not found", sep="")
Hey, I’m having the same problem in C. What’s interesting, the bug is floating: the test runner throws an error from time to time, I’d say 50% cases or more
[tester::#MG5] Running tests for Stage #MG5 (The type builtin: executable files)
[tester::#MG5] [setup] export PATH=/tmp/foo:$PATH
[tester::#MG5] [setup] export PATH=/tmp/qux:$PATH
[tester::#MG5] [setup] Available executables:
[tester::#MG5] [setup] - my_exe
[tester::#MG5] Running ./your_program.sh
[your-program] $ type cat
[your-program] cat is /bin/cat
[tester::#MG5] ✓ Received expected response
[your-program] $ type cp
[your-program] cp is /bin/cp
[tester::#MG5] ✓ Received expected response
[your-program] $ type mkdir
[your-program] mkdir is /bin/mkdir
[tester::#MG5] ✓ Received expected response
[your-program] $ type my_exe
[your-program] my_exe is /tmp/foo/my_exe
[tester::#MG5] Output does not match expected value.
[tester::#MG5] Expected: "my_exe is /tmp/qux/my_exe"
[tester::#MG5] Received: "my_exe is /tmp/foo/my_exe"
Hi @Shreayan, please note that my_exe can exist in multiple locations, and the first one found in PATH should be selected. However, if you loop through PATH without an early stop, later entries can overwrite the correct path.
well thanks for the clarification, but the problem statement fails to do a clear job explaining that we must print the first occurrence where my_exe is found. But thanks for your time tho