diff --git a/42sh/42shelltest-tmp/log b/42sh/42shelltest-tmp/log index 8da543ab..b53a5886 100644 --- a/42sh/42shelltest-tmp/log +++ b/42sh/42shelltest-tmp/log @@ -1 +1 @@ -. +xxxx.x \ No newline at end of file diff --git a/42sh/42shelltest-tmp/log1 b/42sh/42shelltest-tmp/log1 new file mode 100644 index 00000000..1021b813 --- /dev/null +++ b/42sh/42shelltest-tmp/log1 @@ -0,0 +1,933 @@ +...xxxxxxxxxxxxxxxxxxx~xxxxxxxxx..xxxxx..xxx....x....x + +---------------------------------------------------------------- + +minishell/binary/004-binary-test-empty-path (FAILED) + + Description: + The purpose of this test is to check that the Shell finds binaries that are located in the current directory when the environment variable PATH is empty. + + Before test: + 01: export PATH="" + + STDIN: + 01: write_on_stdout "TOKEN201703202355" + + STDOUT: + FAILURE expected_to match_regex `TOKEN201703202355` + (no output) + + STDERR: + FAILURE expected_to be_empty + 01: minishell: command not found: write_on_stdout + + MISC: + SUCCESS expected_to exit_with_status `0` + +---------------------------------------------------------------- + +minishell/binary/005-binary-test-wrong-path (FAILED) + + Description: + This test purpose is to check if your shell is not able to use binary with a wrong PATH + We are changing the actual PATH by PATH=NULL + And executing the commande ls + + Before test: + 01: export PATH="/" + + STDIN: + 01: ls + + STDOUT: + SUCCESS might be_empty + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + SUCCESS might match_regex `[Cc]ommand not found` + 01: minishell: command not found: ls + + MISC: + FAILURE expected_to_not exit_with_status `0` + +---------------------------------------------------------------- + +minishell/binary/006-binary-undefined-path (FAILED) + + Description: + The purpose of this test is to check that the Shell retrieves the default value of the environment variable PATH if not set. This test depends on the presence of the UNIX binary `ls`, located in a path within the default environment variable PATH. + + Before test: + 01: rm -rf "TOKEN201703202355_006-BINARY-UNDEFINED-PATH" + 02: touch "TOKEN201703202355_006-BINARY-UNDEFINED-PATH" + 03: unset PATH + + STDIN: + 01: ls + + STDOUT: + FAILURE expected_to match_regex `TOKEN201703202355_006-BINARY-UNDEFINED-PATH` + (no output) + + STDERR: + FAILURE expected_to be_empty + 01: minishell: command not found: ls + + MISC: + SUCCESS expected_to exit_with_status `0` + +---------------------------------------------------------------- + +minishell/binary/007-binary-permission-denied (FAILED) + + Description: + The purpose of this test is to check that trying to execute a non-permitted binary results in an error on standard error and a failure exit status. + + Before test: + 01: rm -rf ./permission_denied + 02: touch ./permission_denied + 03: chmod 0 ./permission_denied + + STDIN: + 01: ./permission_denied + + STDOUT: + SUCCESS might be_empty + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + SUCCESS might match_regex `[Pp]ermission denied` + 01: minishell: permission denied: ./permission_denied + + MISC: + FAILURE expected_to_not exit_with_status 0 + + After test: + 01: if [ -d "./permission_denied" ]; then chmod 777 "./permission_denied"; fi + 02: rm -rf "./permission_denied" + +---------------------------------------------------------------- + +minishell/binary/008-binary-too-many-symbolic-links-encountered (FAILED) + + Description: + The purpose of this test is to check that trying to execute a path that encounters an infinite loop of symbolic link results in an error on standard error and a failure exit status. + + Before test: + 01: rm -rf ./symbolic_link1 ./symbolic_link2 ./symbolic_link3 + 02: ln -s ./symbolic_link1 ./symbolic_link2 + 03: ln -s ./symbolic_link2 ./symbolic_link3 + 04: ln -s ./symbolic_link3 ./symbolic_link1 + + STDIN: + 01: ./symbolic_link1 + + STDOUT: + SUCCESS might be_empty + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + WARNING might match_regex `[Tt]oo many.*symbolic links` + 01: minishell: ./symbolic_link1: no such file or directory + + MISC: + FAILURE expected_to_not exit_with_status 0 + +---------------------------------------------------------------- + +minishell/builtins/cd/001-no-arg (FAILED) + + Description: + The purpose of this test is to check that using the builtin `cd` without any argument results in moving to the HOME directory. + + STDIN: + 01: cd + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + + STDOUT: + SUCCESS expected_to_not match_regex `/Users/ariard/Projects/42sh/42shelltest-tmp/tmp$` + FAILURE expected_to match_regex `PWD:/Users/ariard:PWD` + 01: /Users/ariard + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/002-current-directory (FAILED) + + Description: + The purpose of this test is to check that using `.` as first argument with the builtin `cd` results in not changing current directory. + + STDIN: + 01: cd . + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp$` + 01: PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/003-current-directory-2 (FAILED) + + Description: + The purpose of this test is to check that using a relative path to the current directory as argument with the builtin `cd` results in not changing the current directory. The environment variable must not be changed. + + STDIN: + 01: cd ../tmp + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp$` + 01: PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/004-parent-directory (FAILED) + + Description: + The purpose of this test is to check that using `..` as first argument with the builtin `cd` results in moving to the parent directory. + + STDIN: + 01: cd .. + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp:PWD$` + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp$` + 01: PWD:/Users/ariard/Projects/42sh/42shelltest-tmp:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/005-root-path (FAILED) + + Description: + The purpose of this test is to check that using the root path as first argument with the builtin `cd` results in moving to the correct directory. + + STDIN: + 01: cd / + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/:PWD` + FAILURE expected_to match_regex `^PWD=/$` + 01: PWD:/:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/006-root-path-2 (FAILED) + + Description: + The purpose of this test is to check that using the root path as first argument with the builtin `cd` results in moving to the correct directory. + + STDIN: + 01: cd /. + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/:PWD` + FAILURE expected_to match_regex `^PWD=/$` + 01: PWD:/:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/007-symbolic-link (FAILED) + + Description: + The purpose of this test is to check that using a symbolic link as first argument with the builtin `cd` results in moving the linked directory. + + Before test: + 01: rm -f "./symbolic_link" + 02: mkdir -p "./sub_directory" + 03: ln -s "./sub_directory" "./symbolic_link" + + STDIN: + 01: cd symbolic_link + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/sub_directory:PWD$` + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/symbolic_link$` + 01: PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/sub_directory:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/008-symbolic-link-2 (FAILED) + + Description: + The purpose of this test is to check that using a symbolic link as first argument with the builtin `cd` results in moving to the linked directory. In this test, the directory is linked with to chained symbolic links. + + Before test: + 01: rm -f "./symbolic_link1" "./symbolic_link2" + 02: mkdir -p "./sub_directory" + 03: ln -s "./sub_directory" "./symbolic_link1" + 04: ln -s "./symbolic_link1" "./symbolic_link2" + + STDIN: + 01: cd symbolic_link2 + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/sub_directory:PWD$` + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/symbolic_link2$` + 01: PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/sub_directory:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/010-update-OLDPWD (FAILED) + + Description: + The purpose of this test is to check that using the builtin `cd` results in a modified environment variable `PWD`. + + Before test: + 01: rm -rf "TOKEN201703202355" + 02: mkdir -p "./TOKEN201703202355/TOKEN201703202355" + + STDIN: + 01: cd TOKEN201703202355 + 02: cd TOKEN201703202355 + 03: ../../display_env + + STDOUT: + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/TOKEN201703202355/TOKEN201703202355$` + FAILURE expected_to match_regex `^OLDPWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/TOKEN201703202355$` + (no output) + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/011-dotdot (FAILED) + + Description: + The purpose of this test is to check that playing with relative paths with the builtin `cd` results in correctly changing the current directory. + + Before test: + 01: rm -rf "playing_with_dotdot" + 02: mkdir -p "playing_with_dotdot/1/2/3/4/5/6/7/8/9/10" + + STDIN: + 01: cd playing_with_dotdot + 02: cd ../playing_with_dotdot + 03: cd 1/2/3/4/../4/../4/../../3/4/5/6/7/8/9/10 + 04: cd ../../../../../../../../../../1/2/3/4/5 + 05: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 06: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + FAILURE expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/playing_with_dotdot/1/2/3/4/5:PWD` + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/playing_with_dotdot/1/2/3/4/5$` + (no output) + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/012-dot (FAILED) + + Description: + The purpose of this test is to check that playing with relative paths to the current directory with the builtin `cd` results in not changing the current directory. + + STDIN: + 01: cd . + 02: cd ./ + 03: cd ./. + 04: cd ././ + 05: cd ./././././././././. + 06: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 07: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp$` + 01: PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/013-absolute-path (FAILED) + + Description: + The purpose of this test is to check that using an absolute path as first argument with the builtin `cd` results in moving to the correct directory. + + Before test: + 01: rm -rf "./my_sub_directory" + 02: mkdir -p "./my_sub_directory/and_another_one/" + + STDIN: + 01: cd /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/my_sub_directory/and_another_one + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + SUCCESS expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/my_sub_directory/and_another_one:PWD` + FAILURE expected_to match_regex `^PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/my_sub_directory/and_another_one$` + 01: PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/my_sub_directory/and_another_one:PWD + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/001-not-a-directory (FAILED) + + Description: + The purpose of this test is to check that using a file name as first argument with the builtin `cd` results in error and not changing current directory. + + Before test: + 01: touch "./not_a_directory" + + STDIN: + 01: cd not_a_directory + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + + STDOUT: + FAILURE expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + WARNING might match_regex `[Nn]ot a directory` + 01: cd: no such file or directory: not_a_directory + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/002-not-a-directory-2 (FAILED) + + Description: + The purpose of this test is to check that using a file name as first argument with the builtin `cd` results in a Shell termination with a failure exit status. + + Before test: + 01: touch "./not_a_directory" + + STDIN: + 01: cd not_a_directory + + STDOUT: + (no output) + + STDERR: + 01: cd: no such file or directory: not_a_directory + + MISC: + FAILURE expected_to_not exit_with_status `0` + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/003-permission-denied (WARNING) + + Description: + The purpose of this test is to check that using a directory without any permission as first argument with the builtin `cd` results in error and not changing current directory. + + Before test: + 01: if [ -d "./permission_denied" ]; then chmod 777 "./permission_denied"; fi + 02: rm -rf "./permission_denied" + 03: mkdir -m 0 "./permission_denied" + + STDIN: + 01: cd permission_denied + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + + STDOUT: + SUCCESS expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + 01: PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD + + STDERR: + SUCCESS expected_to_not be_empty + WARNING might match_regex `[Pp]ermission denied` + 01: cd: no such file or directory: permission_denied + + After test: + 01: if [ -d "./permission_denied" ]; then chmod 777 "./permission_denied"; fi + 02: rm -rf "./permission_denied" + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/004-permission-denied-2 (FAILED) + + Description: + The purpose of this test is to check that using a directory without any permission as first argument with the builtin `cd` results in error and not changing current directory. + + Before test: + 01: if [ -d "./permission_denied" ]; then chmod 777 "./permission_denied"; fi + 02: rm -rf "./permission_denied" + 03: mkdir -m 0 "./permission_denied" + + STDIN: + 01: cd permission_denied + + STDOUT: + (no output) + + STDERR: + 01: cd: no such file or directory: permission_denied + + MISC: + FAILURE expected_to_not exit_with_status `0` + + After test: + 01: if [ -d "./permission_denied" ]; then chmod 777 "./permission_denied"; fi + 02: rm -rf "./permission_denied" + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/005-too-many-symbolic-links-encountered (FAILED) + + Description: + The purpose of this test is to check that using a symbolic link resulting in ELOOP error as first argument with the builtin `cd` results in error and not changing current directory. + + Before test: + 01: rm -f "./symbolic_link1" "./symbolic_link2" "./symbolic_link3" + 02: ln -s "./symbolic_link1" "./symbolic_link2" + 03: ln -s "./symbolic_link2" "./symbolic_link3" + 04: ln -s "./symbolic_link3" "./symbolic_link1" + + STDIN: + 01: cd symbolic_link1 + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + + STDOUT: + FAILURE expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + WARNING might match_regex `[Tt]oo many.*symbolic links` + 01: cd: no such file or directory: symbolic_link1 + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/006-too-many-symbolic-links-encountered-2 (FAILED) + + Description: + The purpose of this test is to check that using a symbolic link resulting in ELOOP error as first argument with the builtin `cd` results in a Shell termination with a failure exit status. + + Before test: + 01: rm -f "./symbolic_link1" "./symbolic_link2" "./symbolic_link3" + 02: ln -s "./symbolic_link1" "./symbolic_link2" + 03: ln -s "./symbolic_link2" "./symbolic_link3" + 04: ln -s "./symbolic_link3" "./symbolic_link1" + + STDIN: + 01: cd symbolic_link1 + + STDOUT: + (no output) + + STDERR: + 01: cd: no such file or directory: symbolic_link1 + + MISC: + FAILURE expected_to_not exit_with_status `0` + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/007-no-such-file-or-directory (FAILED) + + Description: + The purpose of this test is to check that using a non-existing path as first argument with the builtin `cd` results in error and not changing current directory. + + Before test: + 01: rm -f "./no_such_file_or_directory" + + STDIN: + 01: cd no_such_file_or_directory + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + + STDOUT: + FAILURE expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + SUCCESS might match_regex `[Nn]o such file or directory` + 01: cd: no such file or directory: no_such_file_or_directory + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/008-no-such-file-or-directory-2 (FAILED) + + Description: + The purpose of this test is to check that using a non-existing path as first argument with the builtin `cd` results in a Shell termination with an error status code. + + Before test: + 01: rm -f "./no_such_file_or_directory" + + STDIN: + 01: cd no_such_file_or_directory + + STDOUT: + (no output) + + STDERR: + 01: cd: no such file or directory: no_such_file_or_directory + + MISC: + FAILURE expected_to_not exit_with_status `0` + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/009-no-such-file-or-directory-symlink (FAILED) + + Description: + The purpose of this test is to check that using a symbolic link that targets to a non-existing directory with the builtin `cd` results in error and not changing current directory. + + Before test: + 01: rm -rf "./enoent_symlink" "./enoent_directory" + 02: ln -s "./enoent_directory" "./enoent_symlink" + + STDIN: + 01: cd ./enoent_symlink + 02: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + + STDOUT: + FAILURE expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + SUCCESS might match_regex `[Nn]o such file or directory` + 01: cd: no such file or directory: ./enoent_symlink + +---------------------------------------------------------------- + +minishell/builtins/cd/errors/010-no-such-file-or-directory-symlink-2 (FAILED) + + Description: + The purpose of this test is to check that using a symbolic link that targets to a non-existing directory with the builtin `cd` results in error and not changing current directory. + + Before test: + 01: rm -rf "./enoent_symlink" "./enoent_directory" + 02: ln -s "./enoent_directory" "./enoent_symlink" + + STDIN: + 01: cd ./enoent_symlink + + STDOUT: + (no output) + + STDERR: + 01: cd: no such file or directory: ./enoent_symlink + + MISC: + FAILURE expected_to_not exit_with_status `0` + +---------------------------------------------------------------- + +minishell/builtins/cd/options/001-not-following-links (FAILED) + + Description: + The purpose of this test is to check that using symbolic links twice with the builtin `cd` and the option `-P` results in a correct environment variable PWD. The option `-P` makes the Shell to resolve symbolic links. + + Before test: + 01: rm -fr "./sub_directory_link" "./sub_directory" + 02: mkdir -p "./sub_directory/sub_sub_directory" + 03: ln -s "./sub_directory" "./sub_directory_link" + 04: ln -s "./sub_sub_directory" "./sub_directory/sub_sub_directory_link" + + STDIN: + 01: cd -P sub_directory_link + 02: cd -P sub_sub_directory_link + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_env + + STDOUT: + FAILURE expected_to match_regex `PWD=/Users/ariard/Projects/42sh/42shelltest-tmp/tmp/sub_directory/sub_sub_directory` + (no output) + + STDERR: + SUCCESS might be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/cd/options/002-oldpwd (FAILED) + + Description: + The purpose of this test is to check that using `-` as first argument with the builtin `cd` results in moving the previous current directory. + + STDIN: + 01: cd / + 02: cd - + 03: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp/display_pwd + + STDOUT: + FAILURE expected_to match_regex `PWD:/Users/ariard/Projects/42sh/42shelltest-tmp/tmp:PWD` + 01: /Users/ariard/Projects/42sh/42shelltest-tmp/tmp + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/env/003-ignore-environment (FAILED) + + Description: + The purpose of this test is to check that using the option `-i` with the builtin `env` results in an empty environment sent to the given command. + + STDIN: + 01: env -i ./display_env + + STDOUT: + FAILURE expected_to match_regex `TOTAL ENVIRONMENT VARIABLES: 0` + (no output) + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/env/005-set-variables (FAILED) + + Description: + The purpose of this test is to check that the builtin `env` can modify or set multiple environment variables before executing the given command. + + Before test: + 01: export VARTEST1="OLD_VALUE" + + STDIN: + 01: env VARTEST1=TOKEN201703202355_1 VARTEST2=TOKEN201703202355_2 VARTEST3=TOKEN201703202355_3 ./display_env + + STDOUT: + FAILURE expected_to match_regex `VARTEST1=TOKEN201703202355_1` + FAILURE expected_to match_regex `VARTEST2=TOKEN201703202355_2` + FAILURE expected_to match_regex `VARTEST3=TOKEN201703202355_3` + (no output) + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/env/errors/001-command-not-found (FAILED) + + Description: + The purpose of this test is to check that using the builtin `env` with an invalid binary as argument results in an error and failure exit status. + + Before test: + 01: rm -f "./invalid_binary" + + STDIN: + 01: env ./invalid_binary + + STDOUT: + (no output) + + STDERR: + FAILURE expected_to_not be_empty + WARNING might match_regex `[Cc]ommand not found` + (no output) + + MISC: + SUCCESS expected_to_not exit_with_status `0` + +---------------------------------------------------------------- + +minishell/builtins/env/errors/002-illegal-option (FAILED) + + Description: + The purpose of this test is to check that using the builtin `env` with an invalid option results in an error and failure exit status. + + Before test: + 01: rm -f -- "-w" + + STDIN: + 01: env -w + + STDOUT: + (no output) + + STDERR: + SUCCESS expected_to_not be_empty + SUCCESS might match_regex `([Ii]nvalid|[Ii]llegal) (option|argument)` + 01: env: illegal option -- w + 02: usage: env [-i] [-u name] [name=value]... [utility [argument...]] + + MISC: + FAILURE expected_to_not exit_with_status `0` + +---------------------------------------------------------------- + +minishell/builtins/env/multiple-options/001-ignore-environment-and-set-variable (FAILED) + + Description: + The purpose of this test is to check that `env -i` works if we use a second argument to set an environment variable, we are also checking if this command unset environments variables for a given binary. + + STDIN: + 01: env -i TESTVARIABLE=TOKEN201703202355 ./display_env + + STDOUT: + FAILURE expected_to match_regex `TESTVARIABLE=TOKEN201703202355` + FAILURE expected_to match_regex `TOTAL ENVIRONMENT VARIABLES: 1` + (no output) + + STDERR: + SUCCESS expected_to be_empty + (no output) + +---------------------------------------------------------------- + +minishell/builtins/exit/003-status-of-last-command (FAILED) + + Description: + The purpose of this test is to check that using the builtin `exit` without any argument results in a Shell termination and the exit status of the previous command. + + STDIN: + 01: ./exit_with_status 42 + 02: exit + + STDOUT: + SUCCESS might be_empty + (no output) + + STDERR: + (no output) + + MISC: + FAILURE expected_to exit_with_status `42` + +---------------------------------------------------------------- + +minishell/builtins/exit/errors/001-too-many-args (FAILED) + + Description: + The purpose of this test is to check that using a wrong number of arguments with the builtin `exit` does not result in the Shell termination but an error on standard error. + + STDIN: + 01: exit 21 42 + 02: ./write_on_stdout TOKEN201703202355 + + STDOUT: + FAILURE expected_to match_regex `TOKEN201703202355` + (no output) + + STDERR: + FAILURE expected_to_not be_empty + WARNING might match_regex `([Tt]oo many arguments|[Aa]rgument list too long)` + (no output) + + MISC: + FAILURE expected_to exit_with_status `0` + +---------------------------------------------------------------- + +minishell/builtins/exit/errors/002-non-numeric-argument (FAILED) + + Description: + The purpose of this test is to check that using a non-numeric argument with the builtin `exit` results in the Shell termination and an error on standard error. + + STDIN: + 01: exit abc + 02: ./write_on_stdout TOKEN201703202355 + + STDOUT: + SUCCESS expected_to_not match_regex `TOKEN201703202355` + (no output) + + STDERR: + WARNING might_not be_empty + WARNING might match_regex `[Nn]umeric argument required` + (no output) + + MISC: + FAILURE expected_to_not exit_with_status `0` + +---------------------------------------------------------------- + +minishell/builtins/setenv/004-invalid-identifier (FAILED) + + Description: + The purpose of this test is to check that using a wrong variable name with the builtin `setenv` (or `export`) results in error. + + STDIN: + 01: setenv 42 + 02: export 42 + + STDOUT: + SUCCESS might be_empty + (no output) + + STDERR: + FAILURE expected_to_not be_empty + WARNING might match_regex `(not.*identifier|must begin.*letter)` + (no output) + +---------------------------------------------------------------- + +minishell/misc/001-copy-of-environment (FAILED) + + Description: + A Shell must send a copy of the environment to its child processes. + + Before test: + 01: export COPYENV_VAR1="TOKEN201703202355_VAR1" + 02: export COPYENV_VAR2="TOKEN201703202355_VAR2" + 03: export COPYENV_VAR3="TOKEN201703202355_VAR3" + + STDIN: + 01: ./display_env + + STDOUT: + FAILURE expected_to match_regex `COPYENV_VAR1=TOKEN201703202355_VAR1` + FAILURE expected_to match_regex `COPYENV_VAR2=TOKEN201703202355_VAR2` + FAILURE expected_to match_regex `COPYENV_VAR3=TOKEN201703202355_VAR3` + (no output) + + STDERR: + (no output) + +Total tests: 54 +Total failed tests: 38 +Total pending tests: 0 diff --git a/42sh/Makefile b/42sh/Makefile index 00876ba3..f6fd3377 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/20 21:07:34 by jhalford ### ########.fr # +# Updated: 2017/03/21 00:39:34 by ariard ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address +FLAGS = -Wall -Wextra -Werror -fvisibility=hidden #-fsanitize=address D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) @@ -44,6 +44,7 @@ builtin/builtin_return_status.c\ builtin/builtin_setenv.c\ builtin/builtin_unset.c\ builtin/builtin_unsetenv.c\ +builtin/error_msg.c\ builtin/is_builtin.c\ completion/c_arrow.c\ completion/c_clear.c\ diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index c95f8067..17a22131 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:51:23 by wescande ### ########.fr */ +/* Updated: 2017/03/20 23:22:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,4 +38,6 @@ int builtin_history(const char *path, char *const av[], char *const envp[]); int builtin_hash(const char *path, char *const av[], char *const envp[]); int builtin_math(const char *path, char *const av[], char *const envp[]); +int error_msg(char *msg); + #endif diff --git a/42sh/shellscript/README.md b/42sh/shellscript/README.md new file mode 100644 index 00000000..e6104108 --- /dev/null +++ b/42sh/shellscript/README.md @@ -0,0 +1,7 @@ +# shellscript + +*[spec > 42sh](..) > shellscript* + +* [if](./if) +* [until](./until) +* [while](./while) diff --git a/42sh/shellscript/if/001-simple-if-1/README.md b/42sh/shellscript/if/001-simple-if-1/README.md new file mode 100644 index 00000000..da1d0d91 --- /dev/null +++ b/42sh/shellscript/if/001-simple-if-1/README.md @@ -0,0 +1,64 @@ +# 001-simple-if-1 + +*[spec > 42sh > shellscript > if](..) > 001-simple-if-1* + +The purpose of this test is to check that a if control flow does result in the execution of the compound list inside the correct branch +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +if [ -f ${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +elif [ 1 ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error +else + ./write_on_stdout ${GLOBAL_TOKEN}_error +fi + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" +expected_to_not match_regex ${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/if/001-simple-if-1/before_exec b/42sh/shellscript/if/001-simple-if-1/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/if/001-simple-if-1/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/if/001-simple-if-1/description b/42sh/shellscript/if/001-simple-if-1/description new file mode 100644 index 00000000..49870676 --- /dev/null +++ b/42sh/shellscript/if/001-simple-if-1/description @@ -0,0 +1 @@ +The purpose of this test is to check that a if control flow does result in the execution of the compound list inside the correct branch diff --git a/42sh/shellscript/if/001-simple-if-1/stdin b/42sh/shellscript/if/001-simple-if-1/stdin new file mode 100644 index 00000000..9b6c94f0 --- /dev/null +++ b/42sh/shellscript/if/001-simple-if-1/stdin @@ -0,0 +1,10 @@ +if [ -f ${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +elif [ -f ${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error +else + ./write_on_stdout ${GLOBAL_TOKEN}_error +fi diff --git a/42sh/shellscript/if/001-simple-if-1/stdout b/42sh/shellscript/if/001-simple-if-1/stdout new file mode 100644 index 00000000..b87145c9 --- /dev/null +++ b/42sh/shellscript/if/001-simple-if-1/stdout @@ -0,0 +1,2 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout" +expected_to_not match_regex "${GLOBAL_TOKEN}_error" diff --git a/42sh/shellscript/if/002-simple-if-2/README.md b/42sh/shellscript/if/002-simple-if-2/README.md new file mode 100644 index 00000000..d534e99c --- /dev/null +++ b/42sh/shellscript/if/002-simple-if-2/README.md @@ -0,0 +1,67 @@ +# 002-simple-if-2 + +*[spec > 42sh > shellscript > if](..) > 002-simple-if-2* + +The purpose of this test is to check that a if control flow does result in one execution of the compound list with a pipe inside +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +if [ -f no_${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error +elif [ -f no_${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout | ./read_stdin +elif [ -f ${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error + ./delete-file ${GLOBAL_TOKEN}_FILE +else + ./write_on_stdout ${GLOBAL_TOKEN}_error +fi + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout@$" +expected_to_not match_regex "${GLOBAL_TOKEN}_stdout@$" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/if/002-simple-if-2/before_exec b/42sh/shellscript/if/002-simple-if-2/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/if/002-simple-if-2/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/if/002-simple-if-2/description b/42sh/shellscript/if/002-simple-if-2/description new file mode 100644 index 00000000..d03edcdc --- /dev/null +++ b/42sh/shellscript/if/002-simple-if-2/description @@ -0,0 +1 @@ +The purpose of this test is to check that a if control flow does result in one execution of the compound list with a pipe inside diff --git a/42sh/shellscript/if/002-simple-if-2/stdin b/42sh/shellscript/if/002-simple-if-2/stdin new file mode 100644 index 00000000..556b0691 --- /dev/null +++ b/42sh/shellscript/if/002-simple-if-2/stdin @@ -0,0 +1,13 @@ +if [ -f no_${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error +elif [ -f no_${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error +elif [ -f ${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout ${GLOBAL_TOKEN}_stderr | ./read_on_stdin + ./delete-file ${GLOBAL_TOKEN}_FILE +else + ./write_on_stdout ${GLOBAL_TOKEN}_error +fi diff --git a/42sh/shellscript/if/002-simple-if-2/stdout b/42sh/shellscript/if/002-simple-if-2/stdout new file mode 100644 index 00000000..1b2556ce --- /dev/null +++ b/42sh/shellscript/if/002-simple-if-2/stdout @@ -0,0 +1,2 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout@$" +expected_to_not match_regex "${GLOBAL_TOKEN}_error" diff --git a/42sh/shellscript/if/003-simple-if-3/README.md b/42sh/shellscript/if/003-simple-if-3/README.md new file mode 100644 index 00000000..3cf53f42 --- /dev/null +++ b/42sh/shellscript/if/003-simple-if-3/README.md @@ -0,0 +1,69 @@ +# 003-simple-if-3 + +*[spec > 42sh > shellscript > if](..) > 003-simple-if-3* + +The purpose of this test is to check that a if control flow does result in one execution of the compound list with a redirection inside +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +if [ -f no_${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error > ${GLOBAL_TOKEN}_file +elif [ -f no_${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error > ${GLOBAL_TOKEN}_file +else + ./write_on_stdout ${GLOBAL_TOKEN}_stdout > ${GLOBAL_TOKEN}_file +fi + +``` + +### What is expected on standard output + +```bash +expected_to_not match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### What miscellaneous behaviors are expected + +```bash +expected_to create_file "${GLOBAL_TOKEN}_file" matching_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/if/003-simple-if-3/before_exec b/42sh/shellscript/if/003-simple-if-3/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/if/003-simple-if-3/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/if/003-simple-if-3/description b/42sh/shellscript/if/003-simple-if-3/description new file mode 100644 index 00000000..37a554c0 --- /dev/null +++ b/42sh/shellscript/if/003-simple-if-3/description @@ -0,0 +1 @@ +The purpose of this test is to check that a if control flow does result in one execution of the compound list with a redirection inside diff --git a/42sh/shellscript/if/003-simple-if-3/misc b/42sh/shellscript/if/003-simple-if-3/misc new file mode 100644 index 00000000..cd59b9ee --- /dev/null +++ b/42sh/shellscript/if/003-simple-if-3/misc @@ -0,0 +1 @@ +expected_to create_file "${GLOBAL_TOKEN}_file" matching_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/if/003-simple-if-3/stdin b/42sh/shellscript/if/003-simple-if-3/stdin new file mode 100644 index 00000000..eaae75e4 --- /dev/null +++ b/42sh/shellscript/if/003-simple-if-3/stdin @@ -0,0 +1,9 @@ +if [ -f no_${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error > ${GLOBAL_TOKEN}_file +elif [ -f no_${GLOBAL_TOKEN}_FILE ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error > ${GLOBAL_TOKEN}_file +else + ./write_on_stdout ${GLOBAL_TOKEN}_stdout > ${GLOBAL_TOKEN}_file +fi diff --git a/42sh/shellscript/if/003-simple-if-3/stdout b/42sh/shellscript/if/003-simple-if-3/stdout new file mode 100644 index 00000000..edd840fd --- /dev/null +++ b/42sh/shellscript/if/003-simple-if-3/stdout @@ -0,0 +1 @@ +expected_to_not match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/if/004-nested-if/README.md b/42sh/shellscript/if/004-nested-if/README.md new file mode 100644 index 00000000..75b3281e --- /dev/null +++ b/42sh/shellscript/if/004-nested-if/README.md @@ -0,0 +1,68 @@ +# 004-nested-if + +*[spec > 42sh > shellscript > if](..) > 004-nested-if* + +The purpose of this test is to check that a if control flow nested in a if control flow does result in one execution of the compound list +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +if [ -f ${GLOBAL_TOKEN}_FILE ] +then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE + elif [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_error + fi +elif [ 1 ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error +fi + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" +expected_to_not match_regex "${GLOBAL_TOKEN}_error" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/if/004-nested-if/before_exec b/42sh/shellscript/if/004-nested-if/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/if/004-nested-if/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/if/004-nested-if/description b/42sh/shellscript/if/004-nested-if/description new file mode 100644 index 00000000..7fa79164 --- /dev/null +++ b/42sh/shellscript/if/004-nested-if/description @@ -0,0 +1 @@ +The purpose of this test is to check that a if control flow nested in a if control flow does result in one execution of the compound list diff --git a/42sh/shellscript/if/004-nested-if/stdin b/42sh/shellscript/if/004-nested-if/stdin new file mode 100644 index 00000000..f16940ab --- /dev/null +++ b/42sh/shellscript/if/004-nested-if/stdin @@ -0,0 +1,14 @@ +if [ -f ${GLOBAL_TOKEN}_FILE ] +then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE + elif [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_error + fi +elif [ 1 ] +then + ./write_on_stdout ${GLOBAL_TOKEN}_error +fi diff --git a/42sh/shellscript/if/004-nested-if/stdout b/42sh/shellscript/if/004-nested-if/stdout new file mode 100644 index 00000000..b87145c9 --- /dev/null +++ b/42sh/shellscript/if/004-nested-if/stdout @@ -0,0 +1,2 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout" +expected_to_not match_regex "${GLOBAL_TOKEN}_error" diff --git a/42sh/shellscript/if/005-hard-nested-if/README.md b/42sh/shellscript/if/005-hard-nested-if/README.md new file mode 100644 index 00000000..2908a8f1 --- /dev/null +++ b/42sh/shellscript/if/005-hard-nested-if/README.md @@ -0,0 +1,91 @@ +# 005-hard-nested-if + +*[spec > 42sh > shellscript > if](..) > 005-hard-nested-if* + +The purpose of this test is to check that multiple if control flow nested in a if does result in one execution of the compound list for each deeper if +### Shell commands that are sent to the standard entry + +```bash +if [ -f ${GLOBAL_TOKEN}_FILE ] +then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout1 + fi + fi + fi + fi + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout2 + fi + fi + fi + fi + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout3 + ./delete-file ${GLOBAL_TOKEN}_FILE + fi + fi + fi + fi +fi + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout1" +expected_to match_regex "${GLOBAL_TOKEN}_stdout2" +expected_to match_regex "${GLOBAL_TOKEN}_stdout3" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/if/005-hard-nested-if/before_exec b/42sh/shellscript/if/005-hard-nested-if/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/if/005-hard-nested-if/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/if/005-hard-nested-if/description b/42sh/shellscript/if/005-hard-nested-if/description new file mode 100644 index 00000000..38eeaa8c --- /dev/null +++ b/42sh/shellscript/if/005-hard-nested-if/description @@ -0,0 +1 @@ +The purpose of this test is to check that multiple if control flow nested in a if does result in one execution of the compound list for each deeper if diff --git a/42sh/shellscript/if/005-hard-nested-if/stdin b/42sh/shellscript/if/005-hard-nested-if/stdin new file mode 100644 index 00000000..b12fa193 --- /dev/null +++ b/42sh/shellscript/if/005-hard-nested-if/stdin @@ -0,0 +1,43 @@ +if [ -f ${GLOBAL_TOKEN}_FILE ] +then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout1 + fi + fi + fi + fi + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout2 + fi + fi + fi + fi + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + if [ -f ${GLOBAL_TOKEN}_FILE ] + then + ./write_on_stdout ${GLOBAL_TOKEN}_stdout3 + ./delete-file ${GLOBAL_TOKEN}_FILE + fi + fi + fi + fi +fi diff --git a/42sh/shellscript/if/005-hard-nested-if/stdout b/42sh/shellscript/if/005-hard-nested-if/stdout new file mode 100644 index 00000000..3a17c16f --- /dev/null +++ b/42sh/shellscript/if/005-hard-nested-if/stdout @@ -0,0 +1,3 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout1" +expected_to match_regex "${GLOBAL_TOKEN}_stdout2" +expected_to match_regex "${GLOBAL_TOKEN}_stdout3" diff --git a/42sh/shellscript/if/README.md b/42sh/shellscript/if/README.md new file mode 100644 index 00000000..12f96d9c --- /dev/null +++ b/42sh/shellscript/if/README.md @@ -0,0 +1,9 @@ +# if + +*[spec > 42sh > shellscript](..) > if* + +* [001-simple-if-1](./001-simple-if-1) +* [002-simple-if-2](./002-simple-if-2) +* [003-simple-if-3](./003-simple-if-3) +* [004-nested-if](./004-nested-if) +* [005-hard-nested-if](./005-hard-nested-if) diff --git a/42sh/shellscript/test b/42sh/shellscript/test new file mode 100644 index 00000000..5dcac487 --- /dev/null +++ b/42sh/shellscript/test @@ -0,0 +1,20 @@ +10 lignes de cmd inside +cmd | control flow +control flow > redir +control flow in condition control flow +control flow && cmd +control flow || cmd +add for +add case +add func func dans func = 10 +add math = 20 +add var = 10 +add brace = 20 +add commentaires = 2-3 +add tk_bang = 5 + +mixed one for each condition and block + +add 3 script + +100 tests + 50 tests diff --git a/42sh/shellscript/until/001-simple-until-1/README.md b/42sh/shellscript/until/001-simple-until-1/README.md new file mode 100644 index 00000000..2fe104a8 --- /dev/null +++ b/42sh/shellscript/until/001-simple-until-1/README.md @@ -0,0 +1,51 @@ +# 001-simple-until-1 + +*[spec > 42sh > shellscript > until](..) > 001-simple-until-1* + +The purpose of this test is to check that a until control flow does result in one execution of the compound list. +### Shell commands that are sent to the standard entry + +```bash +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./create-file ${GLOBAL_TOKEN} +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/until/001-simple-until-1/before_exec b/42sh/shellscript/until/001-simple-until-1/before_exec new file mode 100644 index 00000000..d86c9fb5 --- /dev/null +++ b/42sh/shellscript/until/001-simple-until-1/before_exec @@ -0,0 +1 @@ +./delete-file ${GLOBAL_TOKEN}_FILE diff --git a/42sh/shellscript/until/001-simple-until-1/description b/42sh/shellscript/until/001-simple-until-1/description new file mode 100644 index 00000000..af129611 --- /dev/null +++ b/42sh/shellscript/until/001-simple-until-1/description @@ -0,0 +1 @@ +The purpose of this test is to check that a until control flow does result in one execution of the compound list. diff --git a/42sh/shellscript/until/001-simple-until-1/stdin b/42sh/shellscript/until/001-simple-until-1/stdin new file mode 100644 index 00000000..d6e21471 --- /dev/null +++ b/42sh/shellscript/until/001-simple-until-1/stdin @@ -0,0 +1,5 @@ +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./create-file ${GLOBAL_TOKEN} +done diff --git a/42sh/shellscript/until/001-simple-until-1/stdout b/42sh/shellscript/until/001-simple-until-1/stdout new file mode 100644 index 00000000..cf61bc5f --- /dev/null +++ b/42sh/shellscript/until/001-simple-until-1/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/until/002-simple-until-2/README.md b/42sh/shellscript/until/002-simple-until-2/README.md new file mode 100644 index 00000000..c2312de7 --- /dev/null +++ b/42sh/shellscript/until/002-simple-until-2/README.md @@ -0,0 +1,51 @@ +# 002-simple-until-2 + +*[spec > 42sh > shellscript > until](..) > 002-simple-until-2* + +The purpose of this test is to check that a until control flow does result in one execution of the compound list with a pipe inside +### Shell commands that are sent to the standard entry + +```bash +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout | ./read_on_stdin + ./create-file ${GLOBAL_TOKEN} +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/until/002-simple-until-2/before_exec b/42sh/shellscript/until/002-simple-until-2/before_exec new file mode 100644 index 00000000..d86c9fb5 --- /dev/null +++ b/42sh/shellscript/until/002-simple-until-2/before_exec @@ -0,0 +1 @@ +./delete-file ${GLOBAL_TOKEN}_FILE diff --git a/42sh/shellscript/until/002-simple-until-2/description b/42sh/shellscript/until/002-simple-until-2/description new file mode 100644 index 00000000..d11b3c23 --- /dev/null +++ b/42sh/shellscript/until/002-simple-until-2/description @@ -0,0 +1 @@ +The purpose of this test is to check that a until control flow does result in one execution of the compound list with a pipe inside diff --git a/42sh/shellscript/until/002-simple-until-2/stdin b/42sh/shellscript/until/002-simple-until-2/stdin new file mode 100644 index 00000000..68b9bb19 --- /dev/null +++ b/42sh/shellscript/until/002-simple-until-2/stdin @@ -0,0 +1,6 @@ +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + echo "HELLO" + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout ${GLOBAL_TOKEN}_stderr | ./read_on_stdin + ./create-file ${GLOBAL_TOKEN} +done diff --git a/42sh/shellscript/until/002-simple-until-2/stdout b/42sh/shellscript/until/002-simple-until-2/stdout new file mode 100644 index 00000000..cd9c01ce --- /dev/null +++ b/42sh/shellscript/until/002-simple-until-2/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout@$" diff --git a/42sh/shellscript/until/003-simple-until-3/README.md b/42sh/shellscript/until/003-simple-until-3/README.md new file mode 100644 index 00000000..185aae52 --- /dev/null +++ b/42sh/shellscript/until/003-simple-until-3/README.md @@ -0,0 +1,58 @@ +# 003-simple-until-3 + +*[spec > 42sh > shellscript > until](..) > 003-simple-until-3* + +The purpose of this test is to check that a until control flow does result in one execution of the compound list with a redirection inside +### Shell commands that are sent to the standard entry + +```bash +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout > ${GLOBAL_TOKEN}_file + ./create-file ${GLOBAL_TOKEN} +done + +``` + +### What is expected on standard output + +```bash +expected_to_not match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### What miscellaneous behaviors are expected + +```bash +expected_to create_file "${GLOBAL_TOKEN}_file" matching_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/until/003-simple-until-3/before_exec b/42sh/shellscript/until/003-simple-until-3/before_exec new file mode 100644 index 00000000..d86c9fb5 --- /dev/null +++ b/42sh/shellscript/until/003-simple-until-3/before_exec @@ -0,0 +1 @@ +./delete-file ${GLOBAL_TOKEN}_FILE diff --git a/42sh/shellscript/until/003-simple-until-3/description b/42sh/shellscript/until/003-simple-until-3/description new file mode 100644 index 00000000..b8f19ad8 --- /dev/null +++ b/42sh/shellscript/until/003-simple-until-3/description @@ -0,0 +1 @@ +The purpose of this test is to check that a until control flow does result in one execution of the compound list with a redirection inside diff --git a/42sh/shellscript/until/003-simple-until-3/misc b/42sh/shellscript/until/003-simple-until-3/misc new file mode 100644 index 00000000..2c398ba6 --- /dev/null +++ b/42sh/shellscript/until/003-simple-until-3/misc @@ -0,0 +1 @@ +expected_to create_file "${GLOBAL_TOKEN}_OUTPUT" matching_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/until/003-simple-until-3/stdin b/42sh/shellscript/until/003-simple-until-3/stdin new file mode 100644 index 00000000..5b8f6cbd --- /dev/null +++ b/42sh/shellscript/until/003-simple-until-3/stdin @@ -0,0 +1,5 @@ +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout > ${GLOBAL_TOKEN}_OUTPUT + ./create-file ${GLOBAL_TOKEN} +done diff --git a/42sh/shellscript/until/003-simple-until-3/stdout b/42sh/shellscript/until/003-simple-until-3/stdout new file mode 100644 index 00000000..edd840fd --- /dev/null +++ b/42sh/shellscript/until/003-simple-until-3/stdout @@ -0,0 +1 @@ +expected_to_not match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/until/004-nested-until/README.md b/42sh/shellscript/until/004-nested-until/README.md new file mode 100644 index 00000000..2552d959 --- /dev/null +++ b/42sh/shellscript/until/004-nested-until/README.md @@ -0,0 +1,54 @@ +# 004-nested-until + +*[spec > 42sh > shellscript > until](..) > 004-nested-until* + +The purpose of this test is to check that a until control flow nested in a until control flow does result in one execution of the compound list +### Shell commands that are sent to the standard entry + +```bash +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./create-file ${GLOBAL_TOKEN} + done +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/until/004-nested-until/before_exec b/42sh/shellscript/until/004-nested-until/before_exec new file mode 100644 index 00000000..d86c9fb5 --- /dev/null +++ b/42sh/shellscript/until/004-nested-until/before_exec @@ -0,0 +1 @@ +./delete-file ${GLOBAL_TOKEN}_FILE diff --git a/42sh/shellscript/until/004-nested-until/description b/42sh/shellscript/until/004-nested-until/description new file mode 100644 index 00000000..d5f23016 --- /dev/null +++ b/42sh/shellscript/until/004-nested-until/description @@ -0,0 +1 @@ +The purpose of this test is to check that a until control flow nested in a until control flow does result in one execution of the compound list diff --git a/42sh/shellscript/until/004-nested-until/stdin b/42sh/shellscript/until/004-nested-until/stdin new file mode 100644 index 00000000..376d6195 --- /dev/null +++ b/42sh/shellscript/until/004-nested-until/stdin @@ -0,0 +1,8 @@ +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./create-file ${GLOBAL_TOKEN} + done +done diff --git a/42sh/shellscript/until/004-nested-until/stdout b/42sh/shellscript/until/004-nested-until/stdout new file mode 100644 index 00000000..cf61bc5f --- /dev/null +++ b/42sh/shellscript/until/004-nested-until/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/until/005-hard-nested-until/README.md b/42sh/shellscript/until/005-hard-nested-until/README.md new file mode 100644 index 00000000..3930dc89 --- /dev/null +++ b/42sh/shellscript/until/005-hard-nested-until/README.md @@ -0,0 +1,95 @@ +# 005-hard-nested-until + +*[spec > 42sh > shellscript > until](..) > 005-hard-nested-until* + +The purpose of this test is to check that multiple until control flow nested in a until does result in one execution of the compound list for each deeper until +### Shell commands that are sent to the standard entry + +```bash +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout1 + ./create-file ${GLOBAL_TOKEN} + done + done + done + done + ./delete-file ${GLOBAL_TOKEN}_FILE + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout2 + ./create-file ${GLOBAL_TOKEN} + done + done + done + done + ./delete-file ${GLOBAL_TOKEN}_FILE + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout3 + ./create-file ${GLOBAL_TOKEN} + done + done + done + done +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout1" +expected_to match_regex "${GLOBAL_TOKEN}_stdout2" +expected_to match_regex "${GLOBAL_TOKEN}_stdout3" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/until/005-hard-nested-until/before_exec b/42sh/shellscript/until/005-hard-nested-until/before_exec new file mode 100644 index 00000000..d86c9fb5 --- /dev/null +++ b/42sh/shellscript/until/005-hard-nested-until/before_exec @@ -0,0 +1 @@ +./delete-file ${GLOBAL_TOKEN}_FILE diff --git a/42sh/shellscript/until/005-hard-nested-until/description b/42sh/shellscript/until/005-hard-nested-until/description new file mode 100644 index 00000000..9e053e4f --- /dev/null +++ b/42sh/shellscript/until/005-hard-nested-until/description @@ -0,0 +1 @@ +The purpose of this test is to check that multiple until control flow nested in a until does result in one execution of the compound list for each deeper until diff --git a/42sh/shellscript/until/005-hard-nested-until/stdin b/42sh/shellscript/until/005-hard-nested-until/stdin new file mode 100644 index 00000000..52e18c68 --- /dev/null +++ b/42sh/shellscript/until/005-hard-nested-until/stdin @@ -0,0 +1,47 @@ +until [ -f ${GLOBAL_TOKEN}_FILE ] +do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout1 + ./create-file ${GLOBAL_TOKEN} + done + done + done + done + ./delete-file ${GLOBAL_TOKEN}_FILE + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout2 + ./create-file ${GLOBAL_TOKEN} + done + done + done + done + ./delete-file ${GLOBAL_TOKEN}_FILE + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + until [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout3 + ./create-file ${GLOBAL_TOKEN} + done + done + done + done +done diff --git a/42sh/shellscript/until/005-hard-nested-until/stdout b/42sh/shellscript/until/005-hard-nested-until/stdout new file mode 100644 index 00000000..3a17c16f --- /dev/null +++ b/42sh/shellscript/until/005-hard-nested-until/stdout @@ -0,0 +1,3 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout1" +expected_to match_regex "${GLOBAL_TOKEN}_stdout2" +expected_to match_regex "${GLOBAL_TOKEN}_stdout3" diff --git a/42sh/shellscript/until/README.md b/42sh/shellscript/until/README.md new file mode 100644 index 00000000..6641783e --- /dev/null +++ b/42sh/shellscript/until/README.md @@ -0,0 +1,9 @@ +# until + +*[spec > 42sh > shellscript](..) > until* + +* [001-simple-until-1](./001-simple-until-1) +* [002-simple-until-2](./002-simple-until-2) +* [003-simple-until-3](./003-simple-until-3) +* [004-nested-until](./004-nested-until) +* [005-hard-nested-until](./005-hard-nested-until) diff --git a/42sh/shellscript/while/001-simple-while-1/README.md b/42sh/shellscript/while/001-simple-while-1/README.md new file mode 100644 index 00000000..27a605af --- /dev/null +++ b/42sh/shellscript/while/001-simple-while-1/README.md @@ -0,0 +1,58 @@ +# 001-simple-while-1 + +*[spec > 42sh > shellscript > while](..) > 001-simple-while-1* + +The purpose of this test is to check that a while control flow does result in one execution of the compound list. +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/001-simple-while-1/before_exec b/42sh/shellscript/while/001-simple-while-1/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/001-simple-while-1/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/001-simple-while-1/description b/42sh/shellscript/while/001-simple-while-1/description new file mode 100644 index 00000000..5ea885ea --- /dev/null +++ b/42sh/shellscript/while/001-simple-while-1/description @@ -0,0 +1 @@ +The purpose of this test is to check that a while control flow does result in one execution of the compound list. diff --git a/42sh/shellscript/while/001-simple-while-1/stdin b/42sh/shellscript/while/001-simple-while-1/stdin new file mode 100644 index 00000000..b5c18790 --- /dev/null +++ b/42sh/shellscript/while/001-simple-while-1/stdin @@ -0,0 +1,5 @@ +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +done diff --git a/42sh/shellscript/while/001-simple-while-1/stdout b/42sh/shellscript/while/001-simple-while-1/stdout new file mode 100644 index 00000000..cf61bc5f --- /dev/null +++ b/42sh/shellscript/while/001-simple-while-1/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/while/002-simple-while-2/README.md b/42sh/shellscript/while/002-simple-while-2/README.md new file mode 100644 index 00000000..e87cc6df --- /dev/null +++ b/42sh/shellscript/while/002-simple-while-2/README.md @@ -0,0 +1,58 @@ +# 002-simple-while-2 + +*[spec > 42sh > shellscript > while](..) > 002-simple-while-2* + +The purpose of this test is to check that a while control flow does result in one execution of the compound list with a pipe inside +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout | ./read_on_stdin + ./delete-file ${GLOBAL_TOKEN}_FILE +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/002-simple-while-2/before_exec b/42sh/shellscript/while/002-simple-while-2/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/002-simple-while-2/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/002-simple-while-2/description b/42sh/shellscript/while/002-simple-while-2/description new file mode 100644 index 00000000..7aae1a4a --- /dev/null +++ b/42sh/shellscript/while/002-simple-while-2/description @@ -0,0 +1 @@ +The purpose of this test is to check that a while control flow does result in one execution of the compound list with a pipe inside diff --git a/42sh/shellscript/while/002-simple-while-2/stdin b/42sh/shellscript/while/002-simple-while-2/stdin new file mode 100644 index 00000000..805e803f --- /dev/null +++ b/42sh/shellscript/while/002-simple-while-2/stdin @@ -0,0 +1,5 @@ +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout ${GLOBAL_TOKEN}_stderr | ./read_on_stdin + ./delete-file ${GLOBAL_TOKEN}_FILE +done diff --git a/42sh/shellscript/while/002-simple-while-2/stdout b/42sh/shellscript/while/002-simple-while-2/stdout new file mode 100644 index 00000000..cd9c01ce --- /dev/null +++ b/42sh/shellscript/while/002-simple-while-2/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout@$" diff --git a/42sh/shellscript/while/003-simple-while-3/README.md b/42sh/shellscript/while/003-simple-while-3/README.md new file mode 100644 index 00000000..edce13c0 --- /dev/null +++ b/42sh/shellscript/while/003-simple-while-3/README.md @@ -0,0 +1,65 @@ +# 003-simple-while-3 + +*[spec > 42sh > shellscript > while](..) > 003-simple-while-3* + +The purpose of this test is to check that a while control flow does result in one execution of the compound list with a redirection inside +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout > ${GLOBAL_TOKEN}_file + ./delete-file ${GLOBAL_TOKEN}_FILE +done + +``` + +### What is expected on standard output + +```bash +expected_to_not match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### What miscellaneous behaviors are expected + +```bash +expected_to create_file "${GLOBAL_TOKEN}_file" matching_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/003-simple-while-3/before_exec b/42sh/shellscript/while/003-simple-while-3/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/003-simple-while-3/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/003-simple-while-3/description b/42sh/shellscript/while/003-simple-while-3/description new file mode 100644 index 00000000..1f284647 --- /dev/null +++ b/42sh/shellscript/while/003-simple-while-3/description @@ -0,0 +1 @@ +The purpose of this test is to check that a while control flow does result in one execution of the compound list with a redirection inside diff --git a/42sh/shellscript/while/003-simple-while-3/misc b/42sh/shellscript/while/003-simple-while-3/misc new file mode 100644 index 00000000..2c398ba6 --- /dev/null +++ b/42sh/shellscript/while/003-simple-while-3/misc @@ -0,0 +1 @@ +expected_to create_file "${GLOBAL_TOKEN}_OUTPUT" matching_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/while/003-simple-while-3/stdin b/42sh/shellscript/while/003-simple-while-3/stdin new file mode 100644 index 00000000..20275496 --- /dev/null +++ b/42sh/shellscript/while/003-simple-while-3/stdin @@ -0,0 +1,5 @@ +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout > ${GLOBAL_TOKEN}_OUTPUT + ./delete-file ${GLOBAL_TOKEN}_FILE +done diff --git a/42sh/shellscript/while/003-simple-while-3/stdout b/42sh/shellscript/while/003-simple-while-3/stdout new file mode 100644 index 00000000..edd840fd --- /dev/null +++ b/42sh/shellscript/while/003-simple-while-3/stdout @@ -0,0 +1 @@ +expected_to_not match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/while/004-nested-while/README.md b/42sh/shellscript/while/004-nested-while/README.md new file mode 100644 index 00000000..bd885f07 --- /dev/null +++ b/42sh/shellscript/while/004-nested-while/README.md @@ -0,0 +1,61 @@ +# 004-nested-while + +*[spec > 42sh > shellscript > while](..) > 004-nested-while* + +The purpose of this test is to check that a while control flow nested in a while control flow does result in one execution of the compound list +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE + done +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/004-nested-while/before_exec b/42sh/shellscript/while/004-nested-while/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/004-nested-while/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/004-nested-while/description b/42sh/shellscript/while/004-nested-while/description new file mode 100644 index 00000000..77b8e1fb --- /dev/null +++ b/42sh/shellscript/while/004-nested-while/description @@ -0,0 +1 @@ +The purpose of this test is to check that a while control flow nested in a while control flow does result in one execution of the compound list diff --git a/42sh/shellscript/while/004-nested-while/stdin b/42sh/shellscript/while/004-nested-while/stdin new file mode 100644 index 00000000..be057971 --- /dev/null +++ b/42sh/shellscript/while/004-nested-while/stdin @@ -0,0 +1,8 @@ +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE + done +done diff --git a/42sh/shellscript/while/004-nested-while/stdout b/42sh/shellscript/while/004-nested-while/stdout new file mode 100644 index 00000000..cf61bc5f --- /dev/null +++ b/42sh/shellscript/while/004-nested-while/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/while/005-hard-nested-while/README.md b/42sh/shellscript/while/005-hard-nested-while/README.md new file mode 100644 index 00000000..ee2ce86d --- /dev/null +++ b/42sh/shellscript/while/005-hard-nested-while/README.md @@ -0,0 +1,102 @@ +# 005-hard-nested-while + +*[spec > 42sh > shellscript > while](..) > 005-hard-nested-while* + +The purpose of this test is to check that multiple while control flow nested in a while does result in one execution of the compound list for each deeper while +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout1 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done + ./create-file ${GLOBAL_TOKEN} + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout2 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done + ./create-file ${GLOBAL_TOKEN} + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout3 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout1" +expected_to match_regex "${GLOBAL_TOKEN}_stdout2" +expected_to match_regex "${GLOBAL_TOKEN}_stdout3" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/005-hard-nested-while/before_exec b/42sh/shellscript/while/005-hard-nested-while/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/005-hard-nested-while/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/005-hard-nested-while/description b/42sh/shellscript/while/005-hard-nested-while/description new file mode 100644 index 00000000..dc788b99 --- /dev/null +++ b/42sh/shellscript/while/005-hard-nested-while/description @@ -0,0 +1 @@ +The purpose of this test is to check that multiple while control flow nested in a while does result in one execution of the compound list for each deeper while diff --git a/42sh/shellscript/while/005-hard-nested-while/stdin b/42sh/shellscript/while/005-hard-nested-while/stdin new file mode 100644 index 00000000..648b1c10 --- /dev/null +++ b/42sh/shellscript/while/005-hard-nested-while/stdin @@ -0,0 +1,47 @@ +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout1 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done + ./create-file ${GLOBAL_TOKEN} + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout2 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done + ./create-file ${GLOBAL_TOKEN} + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout3 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done +done diff --git a/42sh/shellscript/while/005-hard-nested-while/stdout b/42sh/shellscript/while/005-hard-nested-while/stdout new file mode 100644 index 00000000..3a17c16f --- /dev/null +++ b/42sh/shellscript/while/005-hard-nested-while/stdout @@ -0,0 +1,3 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout1" +expected_to match_regex "${GLOBAL_TOKEN}_stdout2" +expected_to match_regex "${GLOBAL_TOKEN}_stdout3" diff --git a/42sh/shellscript/while/006-big-instruction-block/README.md b/42sh/shellscript/while/006-big-instruction-block/README.md new file mode 100644 index 00000000..ee2ce86d --- /dev/null +++ b/42sh/shellscript/while/006-big-instruction-block/README.md @@ -0,0 +1,102 @@ +# 005-hard-nested-while + +*[spec > 42sh > shellscript > while](..) > 005-hard-nested-while* + +The purpose of this test is to check that multiple while control flow nested in a while does result in one execution of the compound list for each deeper while +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout1 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done + ./create-file ${GLOBAL_TOKEN} + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout2 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done + ./create-file ${GLOBAL_TOKEN} + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + while [ -f ${GLOBAL_TOKEN}_FILE ] + do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout3 + ./delete-file ${GLOBAL_TOKEN}_FILE + done + done + done + done +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout1" +expected_to match_regex "${GLOBAL_TOKEN}_stdout2" +expected_to match_regex "${GLOBAL_TOKEN}_stdout3" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/006-big-instruction-block/before_exec b/42sh/shellscript/while/006-big-instruction-block/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/006-big-instruction-block/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/006-big-instruction-block/description b/42sh/shellscript/while/006-big-instruction-block/description new file mode 100644 index 00000000..d3e71ca3 --- /dev/null +++ b/42sh/shellscript/while/006-big-instruction-block/description @@ -0,0 +1 @@ +The purpose of this test is to check that a big execution block succeed diff --git a/42sh/shellscript/while/006-big-instruction-block/stdin b/42sh/shellscript/while/006-big-instruction-block/stdin new file mode 100644 index 00000000..7276286d --- /dev/null +++ b/42sh/shellscript/while/006-big-instruction-block/stdin @@ -0,0 +1,14 @@ +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout1 ${GLOBAL_TOKEN}_stderr1 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout2 ${GLOBAL_TOKEN}_stderr2 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout3 ${GLOBAL_TOKEN}_stderr3 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout4 ${GLOBAL_TOKEN}_stderr4 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout5 ${GLOBAL_TOKEN}_stderr5 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout6 ${GLOBAL_TOKEN}_stderr6 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout7 ${GLOBAL_TOKEN}_stderr7 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout8 ${GLOBAL_TOKEN}_stderr8 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout9 ${GLOBAL_TOKEN}_stderr9 | ./read_on_stdin + ./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout10 ${GLOBAL_TOKEN}_stderr10 | ./read_on_stdin + ./delete-file ${GLOBAL_TOKEN}_FILE +done diff --git a/42sh/shellscript/while/006-big-instruction-block/stdout b/42sh/shellscript/while/006-big-instruction-block/stdout new file mode 100644 index 00000000..c317dc13 --- /dev/null +++ b/42sh/shellscript/while/006-big-instruction-block/stdout @@ -0,0 +1,10 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout1@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout2@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout3@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout4@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout5@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout6@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout7@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout8@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout9@$" +expected_to match_regex "${GLOBAL_TOKEN}_stdout10@$" diff --git a/42sh/shellscript/while/007-pipe-and-while/README.md b/42sh/shellscript/while/007-pipe-and-while/README.md new file mode 100644 index 00000000..27a605af --- /dev/null +++ b/42sh/shellscript/while/007-pipe-and-while/README.md @@ -0,0 +1,58 @@ +# 001-simple-while-1 + +*[spec > 42sh > shellscript > while](..) > 001-simple-while-1* + +The purpose of this test is to check that a while control flow does result in one execution of the compound list. +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/007-pipe-and-while/before_exec b/42sh/shellscript/while/007-pipe-and-while/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/007-pipe-and-while/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/007-pipe-and-while/description b/42sh/shellscript/while/007-pipe-and-while/description new file mode 100644 index 00000000..a7f8bcd5 --- /dev/null +++ b/42sh/shellscript/while/007-pipe-and-while/description @@ -0,0 +1 @@ +The purpose of this test is to check that a command could be piped inside a while diff --git a/42sh/shellscript/while/007-pipe-and-while/stdin b/42sh/shellscript/while/007-pipe-and-while/stdin new file mode 100644 index 00000000..dd50a616 --- /dev/null +++ b/42sh/shellscript/while/007-pipe-and-while/stdin @@ -0,0 +1,5 @@ +./write_on_stdout_and_stderr ${GLOBAL_TOKEN}_stdout ${GLOBAL_TOKEN}_stderr | while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./read_on_stdin_once + ./delete-file ${GLOBAL_TOKEN}_FILE +done diff --git a/42sh/shellscript/while/007-pipe-and-while/stdout b/42sh/shellscript/while/007-pipe-and-while/stdout new file mode 100644 index 00000000..cd9c01ce --- /dev/null +++ b/42sh/shellscript/while/007-pipe-and-while/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout@$" diff --git a/42sh/shellscript/while/008-redir-and-while/README.md b/42sh/shellscript/while/008-redir-and-while/README.md new file mode 100644 index 00000000..27a605af --- /dev/null +++ b/42sh/shellscript/while/008-redir-and-while/README.md @@ -0,0 +1,58 @@ +# 001-simple-while-1 + +*[spec > 42sh > shellscript > while](..) > 001-simple-while-1* + +The purpose of this test is to check that a while control flow does result in one execution of the compound list. +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/008-redir-and-while/before_exec b/42sh/shellscript/while/008-redir-and-while/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/008-redir-and-while/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/008-redir-and-while/description b/42sh/shellscript/while/008-redir-and-while/description new file mode 100644 index 00000000..80d7f5be --- /dev/null +++ b/42sh/shellscript/while/008-redir-and-while/description @@ -0,0 +1 @@ +The purpose of this test is to check that a redirection after the while output the result in a file diff --git a/42sh/shellscript/while/008-redir-and-while/misc b/42sh/shellscript/while/008-redir-and-while/misc new file mode 100644 index 00000000..2c398ba6 --- /dev/null +++ b/42sh/shellscript/while/008-redir-and-while/misc @@ -0,0 +1 @@ +expected_to create_file "${GLOBAL_TOKEN}_OUTPUT" matching_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/while/008-redir-and-while/stdin b/42sh/shellscript/while/008-redir-and-while/stdin new file mode 100644 index 00000000..68f3fafb --- /dev/null +++ b/42sh/shellscript/while/008-redir-and-while/stdin @@ -0,0 +1,5 @@ +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +done > ${GLOBAL_TOKEN}_OUTPUT diff --git a/42sh/shellscript/while/008-redir-and-while/stdout b/42sh/shellscript/while/008-redir-and-while/stdout new file mode 100644 index 00000000..cf61bc5f --- /dev/null +++ b/42sh/shellscript/while/008-redir-and-while/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/while/009-nested-while-in-condition/README.md b/42sh/shellscript/while/009-nested-while-in-condition/README.md new file mode 100644 index 00000000..27a605af --- /dev/null +++ b/42sh/shellscript/while/009-nested-while-in-condition/README.md @@ -0,0 +1,58 @@ +# 001-simple-while-1 + +*[spec > 42sh > shellscript > while](..) > 001-simple-while-1* + +The purpose of this test is to check that a while control flow does result in one execution of the compound list. +### What is done before test + +```bash +./create-file ${GLOBAL_TOKEN} + +``` + +### Shell commands that are sent to the standard entry + +```bash +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +done + +``` + +### What is expected on standard output + +```bash +expected_to match_regex "${GLOBAL_TOKEN}_stdout" + +``` + +### Variables + +The following variables may appear in this test: + +* ${**GLOBAL_INSTALLDIR**} -> The installation directory of 42ShellTester +* ${**GLOBAL_TMP_DIRECTORY**} -> The temporary directory in which tests are executed +* ${**GLOBAL_TOKEN**} -> A token that changes value at launch time +* ${**PATH**} -> The standard environment variable PATH +* ${**HOME**} -> The standard environment variable HOME + +### Support binaries + +The following binaries may appear in this test: + + +* **[./create_file](http://github.com/we-sh/42ShellTester/tree/master/support/create-file)** -> A binary that creates file named argv[1] + "_FILE" If argv[1] is not set, the file is named "TOKEN_FILE" +* **[./delete_file](http://github.com/we-sh/42ShellTester/tree/master/support/delete-file)** -> A binary that delete all files called in argument. +* **[./display_env](http://github.com/we-sh/42ShellTester/tree/master/support/display-env)** -> A binary that iterates on `**envp` and write each element on standard output. +* **[./display_program_name](http://github.com/we-sh/42ShellTester/tree/master/support/display-program-name)** -> A binary that writes its name on standard ouput. +* **[./display_pwd](http://github.com/we-sh/42ShellTester/tree/master/support/display-pwd)** -> A binary that writes on standard output the absolute path of the current directory returned by `getcwd(3)`, encountered with the strings `PWD:` and `:PWD`. +* **[./exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/exit-with-status)** -> A binary that immediately exits with the status given as first argument. +* **[./read_on_stdin](http://github.com/we-sh/42ShellTester/tree/master/support/read-on-stdin)** -> A binary that reads on standard entry and write each line on standard output suffixed with the character `@` (e.g. same behavior as `cat -e` and the *newline* character). When `read(2)` returns `-1`, then the string `STDIN READ ERROR` is written on standard error. +* **[./sleep_and_exit_with_status](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-exit-with-status)** -> A binary that sleeps for a duration in seconds given as first argument and then exits with status given as second argument. +* **[./sleep_and_write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/sleep-and-write-on-stderr)** -> A binary that sleeps for a duration in seconds given as first argument and then writes on STDERR the string given as second argument without EOL. +* **[./write_all_arguments_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-all-arguments-on-stdout)** -> A binary that writes on standard output each argument separated by the symbol `@`. If no argument is given, it writes the string "nothing to be written on stdout". +* **[./write_on_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stderr)** -> A binary that writes on standard error the first given argument (the same behavior as `echo` but with only one argument) and exits with an error status code given as second argument. If no argument is given, it writes the string "write on stderr" and exit with status `1`. +* **[./write_on_stdout](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout)** -> A binary that writes on standard output the first given argument (the same behavior as `echo` but with only one argument). If no argument is given, it writes the string "write on stdout". +* **[./write_on_stdout_and_stderr](http://github.com/we-sh/42ShellTester/tree/master/support/write-on-stdout-and-stderr)** -> A binary that writes on standard output the first given argument, and writes on standard error the second given argument. If an argument is missing, it writes the strings "write on stdout" and "write on stderr". diff --git a/42sh/shellscript/while/009-nested-while-in-condition/before_exec b/42sh/shellscript/while/009-nested-while-in-condition/before_exec new file mode 100644 index 00000000..5e44f185 --- /dev/null +++ b/42sh/shellscript/while/009-nested-while-in-condition/before_exec @@ -0,0 +1 @@ +./create-file ${GLOBAL_TOKEN} diff --git a/42sh/shellscript/while/009-nested-while-in-condition/description b/42sh/shellscript/while/009-nested-while-in-condition/description new file mode 100644 index 00000000..5ea885ea --- /dev/null +++ b/42sh/shellscript/while/009-nested-while-in-condition/description @@ -0,0 +1 @@ +The purpose of this test is to check that a while control flow does result in one execution of the compound list. diff --git a/42sh/shellscript/while/009-nested-while-in-condition/stdin b/42sh/shellscript/while/009-nested-while-in-condition/stdin new file mode 100644 index 00000000..b5c18790 --- /dev/null +++ b/42sh/shellscript/while/009-nested-while-in-condition/stdin @@ -0,0 +1,5 @@ +while [ -f ${GLOBAL_TOKEN}_FILE ] +do + ./write_on_stdout ${GLOBAL_TOKEN}_stdout + ./delete-file ${GLOBAL_TOKEN}_FILE +done diff --git a/42sh/shellscript/while/009-nested-while-in-condition/stdout b/42sh/shellscript/while/009-nested-while-in-condition/stdout new file mode 100644 index 00000000..cf61bc5f --- /dev/null +++ b/42sh/shellscript/while/009-nested-while-in-condition/stdout @@ -0,0 +1 @@ +expected_to match_regex "${GLOBAL_TOKEN}_stdout" diff --git a/42sh/shellscript/while/README.md b/42sh/shellscript/while/README.md new file mode 100644 index 00000000..b724a861 --- /dev/null +++ b/42sh/shellscript/while/README.md @@ -0,0 +1,9 @@ +# while + +*[spec > 42sh > shellscript](..) > while* + +* [001-simple-while-1](./001-simple-while-1) +* [002-simple-while-2](./002-simple-while-2) +* [003-simple-while-3](./003-simple-while-3) +* [004-nested-while](./004-nested-while) +* [005-hard-nested-while](./005-hard-nested-while) diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index d9e01d6a..96e72ba4 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,12 +6,14 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2017/03/20 21:23:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 00:31:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +#define EXITERR_0 SHELL_NAME ": numeric argument required\n" + int builtin_exit(const char *path, char *const av[], char *const envp[]) { int status; @@ -30,6 +32,8 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) data_singleton()->argv[0]); return (0); } + if (av[1] && !ft_stris(av[1], ft_isdigit)) + error_msg(EXITERR_0); status = (av && av[1]) ? ft_atoi(av[1]) : ft_atoi(ft_getenv(data_singleton()->env, "?")); if (SH_IS_INTERACTIVE(data_singleton()->opts)) diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index c6658e9d..ebd0e6c3 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/17 18:54:00 by ariard #+# #+# */ -/* Updated: 2017/03/20 14:45:09 by wescande ### ########.fr */ +/* Updated: 2017/03/20 23:21:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,6 @@ #define MATHERR_3 "math : invalid operand\n" #define MATHERR_4 "math : division by 0\n" -static int error_msg(char *msg) -{ - ft_dprintf(2, "{red}%s{eoc}", msg); - return (1); -} - static int init_math(char **var, char **value, char **operator, char **operand) { diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index e8c5306a..0c22840b 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -6,12 +6,14 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:35:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 00:21:46 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +#define SETERR_0 "invalid variable name\n" + static int assign_var(char *const av[], char ***env) { char *str; @@ -38,20 +40,27 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[]) { char ***env; + char *esc; + int ret; (void)path; if (!av || !av[0]) return (builtin_return_status(0, 1)); - if (ft_strcmp(av[0], "local") == 0) - env = &data_singleton()->local_var; - else - env = &data_singleton()->env; + env = (ft_strcmp(av[0], "local") == 0) ? &data_singleton()->local_var : + &data_singleton()->env; if (!av[1]) { ft_sstrprint(*env, '\n'); ft_putchar('\n'); } else + { + esc = ft_strnew((ft_strlen(av[1]) >> 3) + 1); + ret = word_is_assignment((char *[]){av[1], (esc + 1)}); + ft_strdel(&esc); + if (!ret && av[1][0] != '?') + return (error_msg(SETERR_0)); assign_var(av, env); + } return (envp ? builtin_return_status(0, 0) : 0); } diff --git a/42sh/src/builtin/error_msg.c b/42sh/src/builtin/error_msg.c new file mode 100644 index 00000000..3b15b0ad --- /dev/null +++ b/42sh/src/builtin/error_msg.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* error_msg.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 23:21:37 by ariard #+# #+# */ +/* Updated: 2017/03/20 23:21:56 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int error_msg(char *msg) +{ + ft_dprintf(2, "{red}%s{eoc}", msg); + return (1); +} + + diff --git a/42sh/test/fifi b/42sh/test/fifi new file mode 100644 index 00000000..43084821 --- /dev/null +++ b/42sh/test/fifi @@ -0,0 +1 @@ + 5