add multiple test for the add command

This commit is contained in:
grimhilt 2023-10-28 15:45:35 +02:00
parent 0c925bc4f4
commit 22b9351862

View File

@ -1,10 +1,13 @@
#!/bin/sh #!/bin/sh
nb_tests=0
TEST_SUITE_NAME="add/file/"
get_exe() { get_exe() {
exe=$(pwd) exe=$(pwd)
exe+="/../target/debug/nextsync" exe+="/../target/debug/nextsync"
if [ ! -f $exe ]; then if [ ! -f $exe ]; then
echo "No executable found, try to compile first" echo "No executable found, try to compile first" >&2
exit 4 exit 4
fi fi
} }
@ -16,28 +19,35 @@ setup_env() {
add_cmp() { add_cmp() {
res=$($exe status --nostyle) res=$($exe status --nostyle)
diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "$1: Output differ:" echo -e "$TEST_SUITE_NAME$1: Output differ:" >&2
diff <(echo -e "$2" ) <(echo -e "$res") diff -u <(echo -e "$2" ) <(echo -e "$res") | grep "^[-\+\ ][^-\+]" >&2
echo $path echo -e "\nMore in $path" >&2
echo $nb_tests
exit 1 exit 1
fi fi
} }
add_test() { add_test_no_env() {
setup_env
$exe init
touch $2 touch $2
$exe add $3 $exe add $3
add_cmp "$1" "$4" add_cmp "$1" "$4"
} }
add_test() {
nb_tests=$((nb_tests + 1))
setup_env
$exe init
add_test_no_env "$1" "$2" "$3" "$4"
}
add_basics() { add_basics() {
add_test "basic" "toto" "toto" "new: toto" add_test "basic" "toto" "toto" "new: toto"
} }
add_space() { add_space() {
nb_tests=$((nb_tests + 1))
setup_env setup_env
$exe init $exe init
touch 'to to' touch 'to to'
@ -55,6 +65,7 @@ add_regex() {
} }
add_subdir() { add_subdir() {
nb_tests=$((nb_tests + 1))
setup_env setup_env
$exe init $exe init
mkdir dir mkdir dir
@ -65,6 +76,7 @@ add_subdir() {
} }
add_subdir_regex() { add_subdir_regex() {
nb_tests=$((nb_tests + 1))
setup_env setup_env
$exe init $exe init
mkdir dir mkdir dir
@ -74,11 +86,44 @@ add_subdir_regex() {
add_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto" add_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto"
} }
add_duplication() {
add_test "duplication" "toto" "toto toto" "new: toto"
}
add_duplication_subdir() {
nb_tests=$((nb_tests + 1))
setup_env
$exe init
mkdir dir
add_test_no_env "duplication_subdir" "dir/toto" "dir/toto dir/toto" "new: dir/toto"
}
add_all() {
nb_tests=$((nb_tests + 1))
setup_env
$exe init
mkdir dir
touch dir/toto dir/roro lolo
$exe add -A
res=$($exe status --nostyle)
add/file/all: Output differ:
add_cmp "all" "new: dir/roro\nnew: dir/toto\nnew: lolo\nnew: .nextsyncignore"
}
#test nextsyncignore
#test inside folder
#test -A duplication
#test add file without changes
add_basics add_basics
add_space add_space
add_multiple add_multiple
add_regex add_regex
add_subdir add_subdir
#add_subdir_regex add_subdir_regex
add_duplication
add_duplication_subdir
add_all
echo $nb_tests
exit 0 exit 0