mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2026-02-02 15:45:11 +01:00
feat: suggestion tests
This commit is contained in:
parent
58b6a65a75
commit
5a4ef05828
7 changed files with 95 additions and 0 deletions
6
tests/cases/file_path
Normal file
6
tests/cases/file_path
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
case="file path typo"
|
||||||
|
command="cd ./correc"
|
||||||
|
error="no such file or directory"
|
||||||
|
expect="cd ./correct"
|
||||||
|
|
||||||
|
mkdir -p correct
|
||||||
4
tests/cases/privilege
Normal file
4
tests/cases/privilege
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
case="privilege"
|
||||||
|
command="pacman -Syu"
|
||||||
|
error="you cannot perform this operation unless you are root"
|
||||||
|
expect="sudo pacman -Syu"
|
||||||
7
tests/cases/regex_cmd
Normal file
7
tests/cases/regex_cmd
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
case="regex: command"
|
||||||
|
command="touch dir/file"
|
||||||
|
error="no such file or directory"
|
||||||
|
expect="\
|
||||||
|
mkdir --parents dir/ &&
|
||||||
|
touch dir/file\
|
||||||
|
"
|
||||||
7
tests/cases/regex_err
Normal file
7
tests/cases/regex_err
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
case="regex: error"
|
||||||
|
command="cargo built"
|
||||||
|
error="
|
||||||
|
error: no such command: \`built\`
|
||||||
|
Did you mean \`build\`?
|
||||||
|
"
|
||||||
|
expect="cargo build"
|
||||||
6
tests/cases/regex_opt
Normal file
6
tests/cases/regex_opt
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
case="regex: options"
|
||||||
|
command="rm correc -r"
|
||||||
|
error="no such file or directory"
|
||||||
|
expect="rm -r ./correct"
|
||||||
|
|
||||||
|
mkdir -p correct
|
||||||
4
tests/cases/typo
Normal file
4
tests/cases/typo
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
case="command typo"
|
||||||
|
command="echp"
|
||||||
|
error="command not found"
|
||||||
|
expect="echo"
|
||||||
61
tests/main.sh
Normal file
61
tests/main.sh
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
export PR=$(realpath ../target/debug/pay-respects)
|
||||||
|
export _PR_SHELL="bash"
|
||||||
|
export _PR_LIB=""
|
||||||
|
export _PR_MODE="echo"
|
||||||
|
export TMP=$(mktemp -d)
|
||||||
|
|
||||||
|
PASSED=0
|
||||||
|
FAILED=0
|
||||||
|
export green='\033[0;32m'
|
||||||
|
export red='\033[0;31m'
|
||||||
|
export reset='\033[0m'
|
||||||
|
|
||||||
|
run_test() {
|
||||||
|
export _PR_LAST_COMMAND=$command
|
||||||
|
export _PR_ERROR_MSG=$error
|
||||||
|
result=$($PR 2>/dev/null)
|
||||||
|
if [[ $result == *"$expect"* ]]; then
|
||||||
|
echo -e "${green}[Passed]${reset}: $case"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo -e "${red}[Failed]${reset}: $case"
|
||||||
|
echo -e "\texpected: $expect"
|
||||||
|
echo -e "\tgot: $result"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_case() {
|
||||||
|
source $1
|
||||||
|
run_test "$case" "$command" "$error" "$expect"
|
||||||
|
|
||||||
|
if [[ $? == 0 ]]; then
|
||||||
|
PASSED=$((PASSED + 1))
|
||||||
|
else
|
||||||
|
FAILED=$((FAILED + 1))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
echo "Starting suggestion tests..."
|
||||||
|
echo "-----------------------------------------"
|
||||||
|
WORKDIR=$(pwd)
|
||||||
|
cd $TMP
|
||||||
|
for case in $WORKDIR/cases/*; do
|
||||||
|
run_case $case
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "-----------------------------------------"
|
||||||
|
echo -en "${green}Passed${reset}: $PASSED\t"
|
||||||
|
echo -en "${red}Failed${reset}: $FAILED\t"
|
||||||
|
echo -e "Total: $((PASSED + FAILED))"
|
||||||
|
|
||||||
|
rm -rf $TMP
|
||||||
|
if [[ $FAILED -ne 0 ]]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue