add add/directory tests
This commit is contained in:
parent
53b103af9e
commit
fc8e976c9c
45
tests/add/directory.sh
Executable file
45
tests/add/directory.sh
Executable 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
|
@ -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
|
||||
|
@ -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)"
|
||||
|
38
tests/utils.sh
Executable file
38
tests/utils.sh
Executable file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user