add add/directory tests

This commit is contained in:
grimhilt
2023-10-28 22:23:48 +02:00
parent 53b103af9e
commit fc8e976c9c
4 changed files with 92 additions and 36 deletions

45
tests/add/directory.sh Executable file
View File

@@ -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

View File

@@ -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