Skip to content

Commit

Permalink
refactorising colorisation
Browse files Browse the repository at this point in the history
  • Loading branch information
flammie committed Jul 6, 2024
1 parent 5127f69 commit bc6f3c5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
14 changes: 12 additions & 2 deletions scripts/accept-all-lemmas.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ speller_file=$1
exclusion=$2
source_files=$3

. "$GIELLA_CORE/scripts/termcolors.bash"

if ! test -f "$speller_file" ; then
echo missing "$speller_file".zhfst
exit 1
Expand All @@ -31,19 +33,27 @@ checked_lemmas=$outdir/checked_lemmas.txt
$source_files > "$lemmas"
rv=$?
if test $rv -ge 1 ; then
echo failed to extract lemmas
printf "%sfail%sed to extract lemmas" "$red" "$reset"
exit 1
fi

####### Start testing: #######

"$ospell" "$speller_file" < "$lemmas" > "$checked_lemmas"

rv=$?
if test $rv -ge 1 ; then
printf "%sfail%sed to ospell" "$red" "$reset"
exit 1
fi
grep -F 'is NOT in the lexicon' "$checked_lemmas" > "$rejected_lemmas"

if [ -s "$rejected_lemmas" ] ; then
printf "%sFAIL%s: " "$red" "$reset"
wc -l < "$rejected_lemmas" | sed 's/$/ words missing, here’s first ones:'
head "$rejected_lemmas"
echo see "$rejected_lemmas" for more
exit 1
else
printf "%sPASS%s\n" "$green" "$reset"
fi

11 changes: 7 additions & 4 deletions scripts/run-lexc-testcases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ alt_concat_file="lexicon.tmp.lexc"

relpath=$GIELLA_CORE/scripts/
testrunner=run-morph-tester.sh
. "$relpath/termcolors.bash"

if ! test -x "$relpath/$testrunner" ; then
echo "$0: No test runner found in $relpath/$testrunner!"
printf "%s%s%s: No test runner found in %s/%s!\n" "$red" "$0" "$reset" \
"$relpath" "$testrunner"
exit 77
fi

Expand All @@ -59,14 +61,15 @@ for file in ${source_files}; do
if test "$Tests_found" == "no" ; then
Skipped=yes
fi
echo "SKIPPED: no tests in $fileshort"
printf "%sSKIPPED%s: no tests in %s\n" "$light_blue" "$reset" "$fileshort"

# If there are tests, but no specified fst, skip (future: run default fst)
elif test "$fsts" == "" -a ! "$tests" == ""; then
# (( i += 1 ))
# echo "$file has tests, but no fst specified - defaulting to $transducer"
# source ./run-yaml-testcases.sh $transducer $file
echo "* WARNING: $fileshort has tests, but no fst specified - SKIPPED"
printf "* %sWARNING%s: %s has tests, but no fst specified - %sSKIPPED%s\n"\
"$red" "$reset" "$fileshort" "$light_blue" "$reset"
Skipped=yes
# For each specified fst in the lexc file, run those tests:
else
Expand Down Expand Up @@ -96,7 +99,7 @@ for file in ${source_files}; do
"$fst" "$file" "$relpath" "$testtype" all "$srcdir" "$tk" "$leadtext"
rv=$?
if test $rv = 77 ; then
echo skipped
printf "%sskipped%s" "$light_blue" "$reset"
Skipped=yes
elif test $rv -ge 1 ; then
(( Fail += 1 ))
Expand Down
10 changes: 6 additions & 4 deletions scripts/run-morph-tester.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ fi
leadtext="$*"

testfileshort="$(basename \ "$(dirname "$testfile")")/$(basename "$testfile")"
. "$relpath/termcolors.bash"


# getting the absolute path of the $srcdir of the test script:
abs_srcdir=$(cd "$srcdir" && pwd)
Expand Down Expand Up @@ -140,7 +142,7 @@ outputformat="--output final"
# If the test failed, print instructions to rerun and get more details:
if [[ $exitv -gt 0 ]]; then
(( Fail += 1 ))
printf "\033[1;31mFAIL\033[m\n"
printf "%sFAIL%s\n" "$red" "$reset"
echo
printf "To rerun with more details, please triple-click, copy and paste"
echo " the following:"
Expand All @@ -151,7 +153,7 @@ outputformat="--output final"
else
if [ "$outputformat" == "--silent" \
-o "$outputformat" == "--output final" ]; then
printf "\033[0;32mPASS\033[m\n"
printf "%sPASS%s\n" "$green" "$reset"
fi
fi
if test "$Fail" -gt 0 ; then
Expand Down Expand Up @@ -327,12 +329,12 @@ for f in $fsttype; do
done

if test $transducer_found = 0 ; then
echo "no transducers found for at $fstdir:"
printf "%sSKIP%s: no transducers found for at %s:" "$light_blue" "$reset" "$fstdir"
echo "$analyserfile $generatorfile $bare_fst_file?"
exit 77
fi

if test "$Fail" -gt 0 ; then
echo "some tests failed"
printf "some tests %sfail%sed" "$red" "$reset"
exit 1
fi
26 changes: 9 additions & 17 deletions scripts/run-yaml-testcases.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ halftest=$6
Fail=0
testtotalsfile=$(mktemp -t giella-yaml_test.XXXXXXXXXXX)

. "$relpath/termcolors.bash"

# Remove summary file before we start:

if test -z "$yaml_file_subdir" ; then
Expand Down Expand Up @@ -197,23 +199,13 @@ totalfails=$( cat "$testtotalsfile" | tr ' ' '\n' | cut -d'/' -f2 \
totaltotals=$( cat "$testtotalsfile" | tr ' ' '\n' | cut -d'/' -f3 \
| tr '\n' ' ' | sed 's/ / + /g' | sed 's/ + $/\n/' | bc )

red="\033[1;31m"
green="\033[0;32m"
orange="\033[0;33m"
yellow="\033[1;33m"
blue="\033[0;34m"
light_blue="\033[0;36m"
reset="\033[m"
bold=$(tput smso)
offbold=$(tput sgr0)
#bold=$(tput bold)
#normal=$(tput sgr0)

printf "${bold}SUMMARY${offbold} for the "
printf "${orange}$summaryhalftext$transducer${reset} fst(s): "
printf "${green}PASSES: ${totalpasses}${reset} / "
printf "${red}FAILS: ${totalfails}${reset} / "
printf "${blue}TOTAL: ${totaltotals}${reset}\n"

printf "%sSUMMARY%s for the " "${bold}" "${offbold}"
printf "%s%s%s%s fst(s): " "${orange}" "$summaryhalftext" \
"$transducer" "${reset}"
printf "%sPASSES: %s%s / " "${green}" "${totalpasses}" "${reset}"
printf "%sFAILS: %s%s / " "${red}" "${totalfails}" "${reset}"
printf "%sTOTAL: %s%s\n" "${blue}" "${totaltotals}" "${reset}"

if test $Fail -gt 0 ; then
exit 1
Expand Down
14 changes: 14 additions & 0 deletions scripts/termcolors.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# terminal colours for bash scripts

red=$(tput setaf 1)
green=$(tput setaf 2)
orange=$(tput setaf 3)
yellow=$(tput setaf 4)
blue=$(tput setaf 4)
light_blue=$(tput setaf 6)
reset=$(tput sgr0)
bold=$(tput smso)
offbold=$(tput sgr0)
#bold=$(tput bold)
#normal=$(tput sgr0)

0 comments on commit bc6f3c5

Please sign in to comment.