Chicken and egg problem: test doesn't pass if I prepend path to executable or not

When running an external executable I can

  1. add the path to exec name: /usr/bin/wc -l
  2. or just use the exec name: wc -l

The tester has tests that pass only with (1) and tests that pass only with (2)

logs from test

If I put only the executable name on arg#0 I get a failure: ‘ls’ not found (because it is not on the path I think)

[tester::#NY9] Running tests for Stage #NY9 (Pipelines - Pipelines with built-ins)
[tester::#NY9] [setup] export PATH=/tmp/pear/grape/banana:$PATH
[tester::#NY9] Running ./your_program.sh
[your-program] $ echo apple-strawberry | wc
[your-program] 1 1 17
[tester::#NY9] ✓ Received expected output
[your-program] $ ls | type exit
[your-program] exit is a shell builtin
[your-program] sh: 1: ls: not found
[tester::#NY9] ^ Expected prompt ("$ ") but received “sh: 1: ls: not found”
[your-program] $
[tester::#NY9] Assertion failed.
[tester::#NY9] Test failed

If I put the full path of executable on arg#0 I get a failure on another test:

[tester::#IP1] Running tests for Stage #IP1 (Run a program)
[tester::#IP1] [setup] export PATH=/tmp/bee:$PATH
[tester::#IP1] [setup] Available executables:
[tester::#IP1] [setup] - custom_exe_4797
[tester::#IP1] [setup] - custom_exe_6254
[tester::#IP1] Running ./your_program.sh
[your-program] $ custom_exe_4797 James Alice
[your-program] Program was passed 3 args (including program name).
[your-program] Arg #0 (program name): /tmp/bee/custom_exe_4797
[tester::#IP1] ^ Line does not match expected value.
[tester::#IP1] Expected: “Arg #0 (program name): custom_exe_4797”
[tester::#IP1] Received: “Arg #0 (program name): /tmp/bee/custom_exe_4797”

Are you sure you trying the PATHs in the expected order?

2 Likes

I was using system() to execute external commands.

Now I am using execvp() and the problem is resolved.

1 Like

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