Here is my Repo. The repsonsible Classes are FileSearcher and Builtins::registerBuiltinCommands() that implements the type command.
Here are the test results:
[compile] Compilation successful.
[tester::#WH6] Running tests for Stage #WH6 (Autocompletion - Multiple completions)
[tester::#WH6] [setup] export PATH=/tmp/quz:$PATH
[tester::#WH6] [setup] export PATH=/tmp/foo:$PATH
[tester::#WH6] [setup] export PATH=/tmp/quz:$PATH
[tester::#WH6] [setup] Available executables:
[tester::#WH6] [setup] - xyz_foo
[tester::#WH6] [setup] - xyz_baz
[tester::#WH6] [setup] - xyz_quz
[tester::#WH6] Running ./your_program.sh
[tester::#WH6] β Received prompt ($ )
[tester::#WH6] Typed "xyz_"
[your-program] $ xyz_
[tester::#WH6] β Prompt line matches "$ xyz_"
[tester::#WH6] Pressed "<TAB>" (expecting autocomplete to "xyz_baz xyz_foo xyz_quz")
[tester::#WH6] Pressed "<TAB>" (expecting autocomplete to "xyz_baz xyz_foo xyz_quz")
[tester::#WH6] β Received bell
[your-program] xyz_baz xyz_foo xyz_quz
[tester::#WH6] β Prompt line matches "xyz_baz xyz_foo xyz_quz"
[tester::#WH6] Received completion for "xyz_"
[your-program] $ xyz_
[tester::#WH6] Test passed.
[tester::#GY5] Running tests for Stage #GY5 (Autocompletion - Executable completion)
[tester::#GY5] [setup] export PATH=/tmp/quz:$PATH
[tester::#GY5] [setup] Available executables:
[tester::#GY5] [setup] - custom_exe_9078
[tester::#GY5] Running ./your_program.sh
[tester::#GY5] β Received prompt ($ )
[tester::#GY5] Typed "custom"
[tester::#GY5] β Prompt line matches "$ custom"
[tester::#GY5] Pressed "<TAB>" (expecting autocomplete to "custom_exe_9078")
[tester::#GY5] β Prompt line matches "custom_exe_9078"
[your-program] $ custom_exe_9078
[tester::#GY5] Test passed.
[tester::#QM8] Running tests for Stage #QM8 (Autocompletion - Missing completions)
[tester::#QM8] Running ./your_program.sh
[tester::#QM8] β Received prompt ($ )
[tester::#QM8] Typed "xyz"
[tester::#QM8] β Prompt line matches "$ xyz"
[tester::#QM8] Pressed "<TAB>" (expecting autocomplete to "xyz")
[tester::#QM8] β Prompt line matches "xyz"
[tester::#QM8] β Received bell
[your-program] $ xyz
[tester::#QM8] Test passed.
[tester::#GM9] Running tests for Stage #GM9 (Autocompletion - Completion with arguments)
[tester::#GM9] Running ./your_program.sh
[tester::#GM9] β Received prompt ($ )
[tester::#GM9] Typed "ech"
[tester::#GM9] β Prompt line matches "$ ech"
[tester::#GM9] Pressed "<TAB>" (expecting autocomplete to "echo")
[tester::#GM9] β Prompt line matches "echo"
[tester::#GM9] Typed "hello"
[tester::#GM9] Pressed "<ENTER>"
[your-program] $ echo hello
[your-program] hello
[tester::#GM9] β Received "hello"
[your-program] $
[tester::#GM9] Tearing down shell
[tester::#GM9] Running ./your_program.sh
[tester::#GM9] β Received prompt ($ )
[tester::#GM9] Typed "exi"
[tester::#GM9] β Prompt line matches "$ exi"
[tester::#GM9] Pressed "<TAB>" (expecting autocomplete to "exit")
[tester::#GM9] β Prompt line matches "exit"
[tester::#GM9] Typed "0"
[tester::#GM9] Pressed "<ENTER>"
[your-program] $ exit 0
[tester::#GM9] Tearing down shell
[tester::#GM9] Test passed.
[tester::#QP2] Running tests for Stage #QP2 (Autocompletion - Builtin completion)
[tester::#QP2] Running ./your_program.sh
[tester::#QP2] β Received prompt ($ )
[tester::#QP2] Typed "ech"
[tester::#QP2] β Prompt line matches "$ ech"
[tester::#QP2] Pressed "<TAB>" (expecting autocomplete to "echo")
[tester::#QP2] β Prompt line matches "echo"
[your-program] $ echo
[tester::#QP2] Tearing down shell
[tester::#QP2] Running ./your_program.sh
[tester::#QP2] β Received prompt ($ )
[tester::#QP2] Typed "exi"
[tester::#QP2] β Prompt line matches "$ exi"
[tester::#QP2] Pressed "<TAB>" (expecting autocomplete to "exit")
[tester::#QP2] β Prompt line matches "exit"
[your-program] $ exit
[tester::#QP2] Tearing down shell
[tester::#QP2] Test passed.
[tester::#UN3] Running tests for Stage #UN3 (Redirection - Append stderr)
[tester::#UN3] [setup] export PATH=/tmp/pear/apple/strawberry:$PATH
[tester::#UN3] Running ./your_program.sh
[your-program] $ ls -1 nonexistent >> /tmp/quz/bar.md
[your-program] ls: nonexistent: No such file or directory
[tester::#UN3] β Received error message
[tester::#UN3] β File: /tmp/quz/bar.md is empty
[your-program] $ ls -1 nonexistent 2>> /tmp/quz/qux.md
[your-program] $ cat /tmp/quz/qux.md
[your-program] ls: nonexistent: No such file or directory
[tester::#UN3] β Received redirected file content
[your-program] $ echo "Maria says Error" 2>> /tmp/quz/quz.md
[your-program] Maria says Error
[tester::#UN3] β Received redirected file content
[your-program] $ cat nonexistent 2>> /tmp/quz/quz.md
[your-program] $ ls -1 nonexistent 2>> /tmp/quz/quz.md
[your-program] $ cat /tmp/quz/quz.md
[your-program] cat: nonexistent: No such file or directory
[your-program] ls: nonexistent: No such file or directory
[tester::#UN3] β Received redirected file content
[your-program] $
[tester::#UN3] Test passed.
[tester::#EL9] Running tests for Stage #EL9 (Redirection - Append stdout)
[tester::#EL9] [setup] export PATH=/tmp/orange/blueberry/apple:$PATH
[tester::#EL9] Running ./your_program.sh
[tester::#EL9] [setup] echo -n "banana" > "/tmp/bar/banana"
[tester::#EL9] [setup] echo -n "pear" > "/tmp/bar/pear"
[tester::#EL9] [setup] echo -n "pineapple" > "/tmp/bar/pineapple"
[your-program] $ ls -1 /tmp/bar >> /tmp/quz/baz.md
[your-program] $ cat /tmp/quz/baz.md
[your-program] banana
[your-program] pear
[your-program] pineapple
[tester::#EL9] β Received redirected file content
[your-program] $ echo 'Hello Alice' 1>> /tmp/quz/foo.md
[your-program] $ echo 'Hello Emily' 1>> /tmp/quz/foo.md
[your-program] $ cat /tmp/quz/foo.md
[your-program] Hello Alice
[your-program] Hello Emily
[tester::#EL9] β Received redirected file content
[your-program] $ echo "List of files: " > /tmp/quz/quz.md
[your-program] $ ls -1 /tmp/bar >> /tmp/quz/quz.md
[your-program] $ cat /tmp/quz/quz.md
[your-program] List of files:
[your-program] banana
[your-program] pear
[your-program] pineapple
[tester::#EL9] β Received redirected file content
[your-program] $
[tester::#EL9] Test passed.
[tester::#VZ4] Running tests for Stage #VZ4 (Redirection - Redirect stderr)
[tester::#VZ4] [setup] export PATH=/tmp/blueberry/blueberry/pineapple:$PATH
[tester::#VZ4] Running ./your_program.sh
[tester::#VZ4] [setup] echo -n "banana" > "/tmp/qux/banana"
[your-program] $ ls -1 nonexistent 2> /tmp/baz/bar.md
[your-program] $ cat /tmp/baz/bar.md
[your-program] ls: nonexistent: No such file or directory
[tester::#VZ4] β Received redirected error message
[your-program] $ echo 'Alice file cannot be found' 2> /tmp/baz/baz.md
[your-program] Alice file cannot be found
[tester::#VZ4] β Received redirected error message
[tester::#VZ4] β File: /tmp/baz/baz.md is empty
[your-program] $ cat /tmp/qux/banana nonexistent 2> /tmp/baz/foo.md
[your-program] banana
[tester::#VZ4] β Received file content
[your-program] $ cat /tmp/baz/foo.md
[your-program] cat: nonexistent: No such file or directory
[tester::#VZ4] β Received redirected error message
[your-program] $
[tester::#VZ4] Test passed.
[tester::#JV1] Running tests for Stage #JV1 (Redirection - Redirect stdout)
[tester::#JV1] [setup] export PATH=/tmp/pineapple/pineapple/pear:$PATH
[tester::#JV1] Running ./your_program.sh
[tester::#JV1] [setup] echo -n "blueberry" > "/tmp/baz/blueberry"
[tester::#JV1] [setup] echo -n "grape" > "/tmp/baz/grape"
[tester::#JV1] [setup] echo -n "strawberry" > "/tmp/baz/strawberry"
[your-program] $ ls -1 /tmp/baz > /tmp/bar/bar.md
[your-program] $ cat /tmp/bar/bar.md
[your-program] blueberry
[your-program] grape
[your-program] strawberry
[tester::#JV1] β Received redirected file content
[your-program] $ echo 'Hello Alice' 1> /tmp/bar/foo.md
[your-program] $ cat /tmp/bar/foo.md
[your-program] Hello Alice
[tester::#JV1] β Received redirected file content
[your-program] $ cat /tmp/baz/grape nonexistent 1> /tmp/bar/quz.md
[your-program] cat: nonexistent: No such file or directory
[tester::#JV1] β Received error message
[your-program] $ cat /tmp/bar/quz.md
[your-program] grape
[tester::#JV1] β Received redirected file content
[your-program] $
[tester::#JV1] Test passed.
[tester::#QJ0] Running tests for Stage #QJ0 (Quoting - Executing a quoted executable)
[tester::#QJ0] [setup] export PATH=/tmp/qux:$PATH
[tester::#QJ0] [setup] Available executables:
[tester::#QJ0] [setup] - 'exe with space'
[tester::#QJ0] [setup] - 'exe with "quotes"'
[tester::#QJ0] [setup] - "exe with \'single quotes\'"
[tester::#QJ0] [setup] - 'exe with \n newline'
[tester::#QJ0] Running ./your_program.sh
[tester::#QJ0] [setup] echo -n "orange strawberry." > "/tmp/qux/f1"
[tester::#QJ0] [setup] echo -n "grape apple." > "/tmp/qux/f2"
[tester::#QJ0] [setup] echo -n "mango apple." > "/tmp/qux/f3"
[tester::#QJ0] [setup] echo -n "pineapple banana." > "/tmp/qux/f4"
[your-program] $ 'exe with space' /tmp/qux/f1
[your-program] orange strawberry.
[tester::#QJ0] β Received expected response
[your-program] $ 'exe with "quotes"' /tmp/qux/f2
[your-program] grape apple.
[tester::#QJ0] β Received expected response
[your-program] $ "exe with \'single quotes\'" /tmp/qux/f3
[your-program] mango apple.
[tester::#QJ0] β Received expected response
[your-program] $ 'exe with \n newline' /tmp/qux/f4
[your-program] pineapple banana.
[tester::#QJ0] β Received expected response
[your-program] $
[tester::#QJ0] Test passed.
[tester::#GU3] Running tests for Stage #GU3 (Quoting - Backslash within double quotes)
[tester::#GU3] [setup] export PATH=/tmp/pineapple/blueberry/pineapple:$PATH
[tester::#GU3] [setup] echo -n "pineapple grape." > "/tmp/baz/\"f 57\""
[tester::#GU3] [setup] echo -n "blueberry orange." > "/tmp/baz/\"f\\32\""
[tester::#GU3] [setup] echo -n "pear pineapple." > "/tmp/baz/f91"
[tester::#GU3] Running ./your_program.sh
[your-program] $ echo "hello'world'\\'test"
[your-program] hello'world'\'test
[tester::#GU3] β Received expected response
[your-program] $ echo "hello\"insidequotes"world\"
[your-program] hello"insidequotesworld"
[tester::#GU3] β Received expected response
[your-program] $ echo "mixed\"quote'script'\\"
[your-program] mixed"quote'script'\
[tester::#GU3] β Received expected response
[your-program] $ cat '/tmp/baz/"f 57"' '/tmp/baz/"f\32"' '/tmp/baz/f91'
[your-program] pineapple grape.blueberry orange.pear pineapple.
[tester::#GU3] β Received expected response
[your-program] $
[tester::#GU3] Test passed.
[tester::#LE5] Running tests for Stage #LE5 (Quoting - Backslash within single quotes)
[tester::#LE5] [setup] export PATH=/tmp/pineapple/orange/pear:$PATH
[tester::#LE5] Running ./your_program.sh
[tester::#LE5] [setup] echo -n "blueberry orange." > "/tmp/quz/'f 81'"
[tester::#LE5] [setup] echo -n "strawberry apple." > "/tmp/quz/'f \\64'"
[tester::#LE5] [setup] echo -n "orange grape." > "/tmp/quz/'f \\93\\'"
[your-program] $ echo 'script\\nhello'
[your-program] script\\nhello
[tester::#LE5] β Received expected response
[your-program] $ echo 'example\"shelltest\"script'
[your-program] example\"shelltest\"script
[tester::#LE5] β Received expected response
[your-program] $ echo 'test\\nhello'
[your-program] test\\nhello
[tester::#LE5] β Received expected response
[your-program] $ cat "/tmp/quz/'f 81'" "/tmp/quz/'f \64'" "/tmp/quz/'f \93\'"
[your-program] blueberry orange.strawberry apple.orange grape.
[tester::#LE5] β Received expected response
[your-program] $
[tester::#LE5] Test passed.
[tester::#YT5] Running tests for Stage #YT5 (Quoting - Backslash outside quotes)
[tester::#YT5] [setup] export PATH=/tmp/apple/banana/banana:$PATH
[tester::#YT5] [setup] echo -n "pineapple pear." > "/tmp/foo/f\\n9"
[tester::#YT5] [setup] echo -n "grape pear." > "/tmp/foo/f\\30"
[tester::#YT5] [setup] echo -n "raspberry pineapple." > "/tmp/foo/f'\\'74"
[tester::#YT5] Running ./your_program.sh
[your-program] $ echo world\ \ \ \ \ \ shell
[your-program] world shell
[tester::#YT5] β Received expected response
[your-program] $ echo \'\"shell test\"\'
[your-program] '"shell test"'
[tester::#YT5] β Received expected response
[your-program] $ echo test\nhello
[your-program] testnhello
[tester::#YT5] β Received expected response
[your-program] $ cat "/tmp/foo/f\n9" "/tmp/foo/f\30" "/tmp/foo/f'\'74"
[your-program] pineapple pear.grape pear.raspberry pineapple.
[tester::#YT5] β Received expected response
[your-program] $
[tester::#YT5] Test passed.
[tester::#TG6] Running tests for Stage #TG6 (Quoting - Double quotes)
[tester::#TG6] [setup] export PATH=/tmp/banana/strawberry/orange:$PATH
[tester::#TG6] Running ./your_program.sh
[tester::#TG6] [setup] echo -n "pineapple strawberry." > "/tmp/baz/f 54"
[tester::#TG6] [setup] echo -n "mango apple." > "/tmp/baz/f 8"
[tester::#TG6] [setup] echo -n "raspberry orange." > "/tmp/baz/f's73"
[your-program] $ echo "hello example"
[your-program] hello example
[tester::#TG6] β Received expected response
[your-program] $ echo "example world" "script""hello"
[your-program] example world scripthello
[tester::#TG6] β Received expected response
[your-program] $ echo "script" "shell's" "example"
[your-program] script shell's example
[tester::#TG6] β Received expected response
[your-program] $ cat "/tmp/baz/f 54" "/tmp/baz/f 8" "/tmp/baz/f's73"
[your-program] pineapple strawberry.mango apple.raspberry orange.
[tester::#TG6] β Received expected response
[your-program] $
[tester::#TG6] Test passed.
[tester::#NI6] Running tests for Stage #NI6 (Quoting - Single quotes)
[tester::#NI6] [setup] export PATH=/tmp/apple/pear/blueberry:$PATH
[tester::#NI6] Running ./your_program.sh
[tester::#NI6] [setup] echo -n "blueberry grape." > "/tmp/baz/f 82"
[tester::#NI6] [setup] echo -n "banana mango." > "/tmp/baz/f 93"
[tester::#NI6] [setup] echo -n "pear blueberry." > "/tmp/baz/f 89"
[your-program] $ echo 'script test'
[your-program] script test
[tester::#NI6] β Received expected response
[your-program] $ echo test world
[your-program] test world
[tester::#NI6] β Received expected response
[your-program] $ echo 'shell example' 'world''script'
[your-program] shell example worldscript
[tester::#NI6] β Received expected response
[your-program] $ cat '/tmp/baz/f 82' '/tmp/baz/f 93' '/tmp/baz/f 89'
[your-program] blueberry grape.banana mango.pear blueberry.
[tester::#NI6] β Received expected response
[your-program] $
[tester::#NI6] Test passed.
[tester::#GP4] Running tests for Stage #GP4 (Navigation - The cd builtin: Home directory)
[tester::#GP4] Running ./your_program.sh
[your-program] $ cd /tmp/orange/banana/raspberry
[your-program] $ pwd
[your-program] /tmp/orange/banana/raspberry
[tester::#GP4] Received current working directory response
[your-program] $ cd ~
[your-program] $ pwd
[your-program] /tmp/banana/grape/apple
[tester::#GP4] Received current working directory response
[your-program] $
[tester::#GP4] Test passed.
[tester::#GQ9] Running tests for Stage #GQ9 (Navigation - The cd builtin: Relative paths)
[tester::#GQ9] Running ./your_program.sh
[your-program] $ cd /tmp/grape
[your-program] $ pwd
[your-program] /tmp/grape
[tester::#GQ9] Received current working directory response
[your-program] $ cd ./banana/banana
[your-program] $ pwd
[your-program] /tmp/grape/banana/banana
[tester::#GQ9] Received current working directory response
[your-program] $ cd ../../../
[your-program] $ pwd
[your-program] /tmp
[tester::#GQ9] Received current working directory response
[your-program] $
[tester::#GQ9] Test passed.
[tester::#RA6] Running tests for Stage #RA6 (Navigation - The cd builtin: Absolute paths)
[tester::#RA6] Running ./your_program.sh
[your-program] $ cd /tmp/blueberry/strawberry/mango
[your-program] $ pwd
[your-program] /tmp/blueberry/strawberry/mango
[tester::#RA6] Received current working directory response
[your-program] $ cd /non-existing-directory
[your-program] cd: /non-existing-directory: No such file or directory
[tester::#RA6] β Received error message
[your-program] $
[tester::#RA6] Test passed.
[tester::#EI0] Running tests for Stage #EI0 (Navigation - The pwd builtin)
[tester::#EI0] Running ./your_program.sh
[your-program] $ type pwd
[your-program] pwd is a shell builtin
[tester::#EI0] β Received expected response
[your-program] $ pwd
[your-program] /app
[tester::#EI0] β Received current working directory response
[your-program] $
[tester::#EI0] Test passed.
[tester::#IP1] Running tests for Stage #IP1 (Run a program)
[tester::#IP1] [setup] export PATH=/tmp/quz:$PATH
[tester::#IP1] [setup] Available executables:
[tester::#IP1] [setup] - custom_exe_1815
[tester::#IP1] Running ./your_program.sh
[your-program] $ custom_exe_1815 Emily
[your-program] Program was passed 2 args (including program name).
[your-program] Arg #0 (program name): custom_exe_1815
[your-program] Arg #1: Emily
[your-program] Program Signature: 2954454925
[tester::#IP1] β Received expected response
[your-program] $
[tester::#IP1] Test passed.
[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/baz:$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] Output does not match expected value.
[tester::#MG5] Expected: "cat is /usr/bin/cat"
[tester::#MG5] Received: "cat is /bin/cat"
[your-program] $
[tester::#MG5] Assertion failed.
[tester::#MG5] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
On my local machine both paths(/usr/bin and /bin) were found but the type command only takes the /bin path.