diff --git a/bin/pwd/tests/get_path.c b/bin/pwd/tests/get_path.c --- a/bin/pwd/tests/get_path.c +++ b/bin/pwd/tests/get_path.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -7,14 +8,18 @@ int main(void) { - char current_path[PATH_MAX]; - char resolved_path[PATH_MAX]; + char getcwd_path[PATH_MAX]; // PATH_MAX is the max length of the path + char realpath_path[PATH_MAX]; - if (getcwd(current_path, sizeof(current_path)) == NULL) - err(1, "%s", "getcwd error"); - else if (realpath(current_path, resolved_path) == NULL) - err(1, "%s", "realpath error"); + // getcwd and realpath function return physical path (absolute) of current directory + if (getcwd(getcwd_path, sizeof(getcwd_path)) == NULL) { + perror("getcwd function error"); + return errno; + } else if (realpath(".", realpath_path) == NULL) { + perror("realpath function error"); + return errno; + } - printf("%s %s", current_path, resolved_path); + printf("%s %s", getcwd_path, realpath_path); return EXIT_SUCCESS; } diff --git a/bin/pwd/tests/pwd_test.sh b/bin/pwd/tests/pwd_test.sh --- a/bin/pwd/tests/pwd_test.sh +++ b/bin/pwd/tests/pwd_test.sh @@ -1,19 +1,18 @@ -get_output() { - # PWD environment variable which is logical path - pwd_environment="$PWD" - get_path_output="$("${0%/*}"/get_path)" - echo "$pwd_environment $get_path_output" -} - atf_test_case basic basic_head() -{ +{ atf_set "descr" "Basic test case" } basic_body() { - output="$(get_output)" - echo "$output" | while IFS=" " read pwd_environment getcwd realpath; do + # PWD environment variable which is logical path + pwd_environment="$PWD" + # Check get_path C file work correct + atf_check -s exit:0 -o ignore -e empty "${0%/*}"/get_path + # Get physical path + get_path_output="$("${0%/*}"/get_path)" + + echo "$pwd_environment $get_path_output" | while IFS=" " read pwd_environment getcwd realpath; do atf_check -o inline:"${getcwd}\n" pwd atf_check -o inline:"${realpath}\n" pwd atf_check -o inline:"${pwd_environment}\n" pwd -L @@ -34,8 +33,14 @@ ln -s soft_link_src soft_link_dst cd soft_link_dst || exit - output="$(get_output)" - echo "$output" | while IFS=" " read pwd_environment getcwd realpath; do + # PWD environment variable which is logical path + pwd_environment="$PWD" + # Check get_path C file work correct + atf_check -s exit:0 -o ignore -e empty "${0%/*}"/get_path + # Get physical path + get_path_output="$("${0%/*}"/get_path)" + + echo "$pwd_environment $get_path_output" | while IFS=" " read pwd_environment getcwd realpath; do atf_check -o inline:"${getcwd}\n" pwd atf_check -o inline:"${realpath}\n" pwd atf_check -o inline:"${pwd_environment}\n" pwd -L @@ -51,6 +56,7 @@ } broken_soft_link_body() { + # Create a broken_soft_link and enter it mkdir broken_soft_link_src ln -s broken_soft_link_src broken_soft_link_dst cd broken_soft_link_dst || exit