diff --git a/tests/add/directory.sh b/tests/add/directory.sh new file mode 100755 index 0000000..3c0cf6b --- /dev/null +++ b/tests/add/directory.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +source ./utils.sh + +nb_tests=0 +TEST_SUITE_NAME="add/directory/" + +add_test_no_env() { + touch $2 + $exe add $3 + status_cmp "$1" "$4" +} + +add_test() { + nb_tests=$((nb_tests + 1)) + setup_env + $exe init + add_test_no_env "$1" "$2" "$3" "$4" +} + +add_dir() { + nb_tests=$((nb_tests + 1)) + setup_env + $exe init + mkdir dir + $exe add "dir" + res=$($exe status --nostyle) + status_cmp "dir" "new: dir" +} + +add_subdir() { + nb_tests=$((nb_tests + 1)) + setup_env + $exe init + mkdir foo foo/bar + $exe add "foo" + res=$($exe status --nostyle) + status_cmp "dir" "new: foo/bar\nnew: foo" +} + +add_dir +add_subdir + +echo $nb_tests +exit 0 diff --git a/tests/add/file.sh b/tests/add/file.sh index 9f75b96..582f157 100755 --- a/tests/add/file.sh +++ b/tests/add/file.sh @@ -5,36 +5,10 @@ source ./utils.sh nb_tests=0 TEST_SUITE_NAME="add/file/" -get_exe() { - exe=$(pwd) - exe+="/../target/debug/nextsync" - if [ ! -f $exe ]; then - echo "No executable found, try to compile first" >&2 - exit 4 - fi -} -setup_env() { - [ ! -v exe ] && get_exe - path=$(mktd) - cd $path -} - -add_cmp() { - res=$($exe status --nostyle) - diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null - if [ $? -ne 0 ]; then - echo -e "$TEST_SUITE_NAME$1: Output differ:" >&2 - diff -u <(echo -e "$2" ) <(echo -e "$res") | grep "^[-\+\ ][^-\+]" >&2 - echo -e "\nMore in $path" >&2 - echo $nb_tests - exit 1 - fi -} - add_test_no_env() { touch $2 $exe add $3 - add_cmp "$1" "$4" + status_cmp "$1" "$4" } add_test() { @@ -55,7 +29,7 @@ add_space() { touch 'to to' $exe add 'to to' res=$($exe status --nostyle) - add_cmp "space" "new: to to" + status_cmp "space" "new: to to" } add_multiple() { @@ -74,7 +48,7 @@ add_file_subdir() { touch dir/toto $exe add "./dir/toto" res=$($exe status --nostyle) - add_cmp "file_subdir" "new: dir/toto" + status_cmp "file_subdir" "new: dir/toto" } add_whole_subdir() { @@ -86,7 +60,7 @@ add_whole_subdir() { touch dir/roro $exe add "dir" res=$($exe status --nostyle) - add_cmp "whole_subdir" "new: dir/roro\nnew: dir/toto\nnew: dir" + status_cmp "whole_subdir" "new: dir/roro\nnew: dir/toto\nnew: dir" } add_subdir_regex() { @@ -97,7 +71,7 @@ add_subdir_regex() { touch dir/toto dir/roro $exe add "./dir/*" res=$($exe status --nostyle) - add_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto" + status_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto" } add_duplication() { @@ -120,12 +94,9 @@ add_all() { touch dir/toto dir/roro lolo $exe add -A res=$($exe status --nostyle) - add_cmp "all" "new: .nextsyncignore\nnew: dir/roro\nnew: dir/toto\nnew: dir\nnew: lolo" + status_cmp "all" "new: .nextsyncignore\nnew: dir/roro\nnew: dir/toto\nnew: dir\nnew: lolo" } -#test nextsyncignore -#test inside folder -#test -A duplication #test add file without changes add_basics diff --git a/tests/main.sh b/tests/main.sh index 5fb1a09..b2c6f26 100755 --- a/tests/main.sh +++ b/tests/main.sh @@ -27,8 +27,10 @@ for test in $TESTS; do [ $nb_tests_tmp -gt 0 ] && nb_tests=$((nb_tests + nb_tests_tmp)) + # deal with the result of the test if [ $exit_code -eq 0 ]; then nb_success=$((nb_success + nb_tests_tmp)) + echo "$test ran successfully" elif [ $exit_code -eq 4 ]; then # not executable (nextsync) found, not need to try other tests exit 1 @@ -38,6 +40,6 @@ for test in $TESTS; do fi done; -#rm -rf /tmp/*_nextsync +rm -rf /tmp/*_nextsync echo -e "\nRan $nb_tests tests ($((nb_tests - nb_success)) Failed)" diff --git a/tests/utils.sh b/tests/utils.sh new file mode 100755 index 0000000..26f968d --- /dev/null +++ b/tests/utils.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +mktd() +{ + echo $(mktemp -d --suffix=_nextsync) +} + +mktf() +{ + echo $(mktemp --suffix=_nextsync) +} + +get_exe() { + exe=$(pwd) + exe+="/../target/debug/nextsync" + if [ ! -f $exe ]; then + echo "No executable found, try to compile first" >&2 + exit 4 + fi +} +setup_env() { + [ ! -v exe ] && get_exe + path=$(mktd) + cd $path +} + +# test_name expected_output +status_cmp() { + res=$($exe status --nostyle) + diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null + if [ $? -ne 0 ]; then + echo -e "$TEST_SUITE_NAME$1: Output differ:" >&2 + diff -u <(echo -e "$2" ) <(echo -e "$res") | grep "^[-\+\ ][^-\+]" >&2 + echo -e "\nMore in $path" >&2 + echo $nb_tests + exit 1 + fi +}