From 22a7b4f0c8e018077984d58476a0c419b5e11942 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 2 Apr 2023 10:33:40 -0300 Subject: aux/checks/repo.sh: WIP Fix tests --- Makefile | 2 +- aux/checks/repo.env | 5 ++ aux/checks/repo.sh | 150 +++++++++++++++++++++++------------------------ aux/checks/shellcheck.sh | 6 +- aux/dev.mk | 10 ++-- aux/lib.sh | 5 +- repo.sh | 33 +++++++++++ src/remembering.in | 2 +- 8 files changed, 126 insertions(+), 87 deletions(-) create mode 100644 aux/checks/repo.env create mode 100755 repo.sh diff --git a/Makefile b/Makefile index 8d155d6..9b60452 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ test-files = \ tests/signals.sh \ $(test-files): src/remembering ALWAYS - sh $@ + @echo sh $@ check: $(test-files) diff --git a/aux/checks/repo.env b/aux/checks/repo.env new file mode 100644 index 0000000..79b46d9 --- /dev/null +++ b/aux/checks/repo.env @@ -0,0 +1,5 @@ +#!/bin/sh + +export EXECUTABLES=1 +export SYMLINKS=2 +export FILES=9 diff --git a/aux/checks/repo.sh b/aux/checks/repo.sh index 0c00e92..323f68e 100755 --- a/aux/checks/repo.sh +++ b/aux/checks/repo.sh @@ -1,9 +1,6 @@ #!/bin/sh set -eu -if true; then - exit -fi if [ -n "${RECURSIVE_CHECK:-}" ]; then exit @@ -11,30 +8,14 @@ fi export RECURSIVE_CHECK=true . aux/lib.sh +. aux/checks/repo.env +set -eu -REPODIR="$PWD" - -INSTALLCHECK=false -while getopts 'x:l:f:' flag; do - case "$flag" in - x) - EXECUTABLES="$OPTARG" - INSTALLCHECK=true - ;; - l) - SYMLINKS="$OPTARG" - INSTALLCHECK=true - ;; - f) - FILES="$OPTARG" - INSTALLCHECK=true - ;; - *) - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) +usage() { + cat <<-'EOF' + FIXME + EOF +} assert_no_diffs() { if [ -n "$(git status -s)" ]; then @@ -45,37 +26,31 @@ assert_no_diffs() { } assert_installed_files() { - if [ -n "${EXECUTABLES:-}" ]; then - ACTUAL="$(find "$1" -type f -perm -u=x | wc -l)" - if [ "$EXECUTABLES" != "$ACTUAL" ]; then - printf 'Expected %s executables, found %s:\n' \ - "$EXECUTABLES" "$ACTUAL" >&2 - echo "find $1 -type f -perm -u=x:" >&2 - find "$1" -type f -perm -u=x >&2 - exit 1 - fi + ACTUAL="$(find "$1" -type f -perm -u=x | wc -l)" + if [ "$EXECUTABLES" != "$ACTUAL" ]; then + printf 'Expected %s executables, found %s:\n' \ + "$EXECUTABLES" "$ACTUAL" >&2 + echo "find $1 -type f -perm -u=x:" >&2 + find "$1" -type f -perm -u=x >&2 + exit 1 fi - if [ -n "${SYMLINKS:-}" ]; then - ACTUAL="$(find "$1" -type l | wc -l)" - if [ "$SYMLINKS" != "$ACTUAL" ]; then - printf 'Expected %s symlinks, found %s:\n' \ - "$SYMLINKS" "$ACTUAL" >&2 - echo "find $1 -type l:" >&2 - find "$1" -type l >&2 - exit 1 - fi + ACTUAL="$(find "$1" -type l | wc -l)" + if [ "$SYMLINKS" != "$ACTUAL" ]; then + printf 'Expected %s symlinks, found %s:\n' \ + "$SYMLINKS" "$ACTUAL" >&2 + echo "find $1 -type l:" >&2 + find "$1" -type l >&2 + exit 1 fi - if [ -n "${FILES:-}" ]; then - ACTUAL="$(find "$1" -type f | wc -l)" - if [ "$FILES" != "$ACTUAL" ]; then - printf 'Expected %s files, found %s:\n' \ - "$FILES" "$ACTUAL" >&2 - echo "find $1 -type f:" >&2 - find "$1" -type f >&2 - exit 1 - fi + ACTUAL="$(find "$1" -type f | wc -l)" + if [ "$FILES" != "$ACTUAL" ]; then + printf 'Expected %s files, found %s:\n' \ + "$FILES" "$ACTUAL" >&2 + echo "find $1 -type f:" >&2 + find "$1" -type f >&2 + exit 1 fi } @@ -89,14 +64,10 @@ assert_uninstalled_files() { } assert_install() { - if [ "$INSTALLCHECK" != 'true' ]; then - return - fi - make clean echo 'Asserting "canonical" install path' >&2 - INSTALL1="$(mkdtemp)" + INSTALL1="$(tmpname)" make PREFIX="$INSTALL1" make check PREFIX="$INSTALL1" make install PREFIX="$INSTALL1" @@ -107,7 +78,7 @@ assert_install() { make clean echo 'Asserting "straigh-forward" install path' >&2 - INSTALL2="$(mkdtemp)" + INSTALL2="$(tmpname)" make install PREFIX="$INSTALL2" assert_installed_files "$INSTALL2" make uninstall PREFIX="$INSTALL2" @@ -116,7 +87,7 @@ assert_install() { make clean echo 'Asserting "idempotent" install path' >&2 - INSTALL3="$(mkdtemp)" + INSTALL3="$(tmpname)" make install PREFIX="$INSTALL3" make install PREFIX="$INSTALL3" assert_installed_files "$INSTALL3" @@ -127,21 +98,26 @@ assert_install() { make clean echo 'Asserting "destdir" install path' >&2 - DESTDIR="$(mkdtemp)" - INSTALL4="$(mkdtemp)" + DESTDIR="$(tmpname)" + INSTALL4="$(tmpname)" make install DESTDIR="$DESTDIR" PREFIX="$INSTALL4" assert_installed_files "$DESTDIR/$INSTALL4" make uninstall DESTDIR="$DESTDIR" PREFIX="$INSTALL4" assert_uninstalled_files "$DESTDIR/$INSTALL4" } -assert_clean_clone() { - CLONEDIR="$(mkdtemp)" +check_clean_clone() { + um + unreachable + return 12 + oijwsx + CLONEDIR="$(tmpname)/$NAME" + mkdir -p -- "$CLONEDIR" cd "$CLONEDIR" - git clone "$REPODIR" . + git clone "$OLDPWD" . - make clean public dev-check + make dev assert_no_diffs make clean assert_no_diffs @@ -154,35 +130,59 @@ assert_clean_clone() { fi rm -rf aux/ - make clean check || { + make check || { echo 'Cannot run "make check" without "aux/".' >&2 echo "Clone directory: $CLONEDIR" >&2 - exit 1 + exit 1 #FIXME } assert_install + oijwsx cd - > /dev/null } -assert_clean_checkout() { - CHECKOUTDIR="$(mkdtemp)" +check_clean_checkout() { + set -x + echo dois + dois + CHECKOUTDIR="$(tmpname)/$NAME" + mkdir -p -- "$CHECKOUTDIR" git --work-tree="$CHECKOUTDIR" checkout HEAD -- . cd "$CHECKOUTDIR" FILECOUNT="$(find . -type f | wc -l)" - make clean public dev-check - make clean + : make clean public dev-check + : make clean if [ "$FILECOUNT" != "$(find . -type f | wc -l)" ]; then echo 'File count mismatch after "make clean".' >&2 echo "Checkout directory: $CHECKOUTDIR" >&2 exit 1 fi - assert_install + assert_insta cd - > /dev/null } -assert_clean_clone -assert_clean_checkout +set -eu +# set -eE +D="$(mkdtemp)" + +check_clean_clone && echo aaa +exit +if ! check_clean_clone; then + touch "$D"/clean-clone.err +fi +check_clean_clone +# || touch "$D"/clean-clone.err +# check_clean_checkout || touch "$D"/clean-checkout.err +# check_no_aux +wait +tree "$D" +if [ "$(find "$D" -name '*.err' | wc -l)" != 0 ]; then + find "$D" -name '*.err' | while read -r f; do + cat -- "${f%.err}" + done + exit 1 +fi diff --git a/aux/checks/shellcheck.sh b/aux/checks/shellcheck.sh index 40fd364..585a75f 100755 --- a/aux/checks/shellcheck.sh +++ b/aux/checks/shellcheck.sh @@ -1,6 +1,6 @@ #!/bin/sh set -eu -find . -name '*.sh' -print0 | - xargs -0 awk 'FNR==1 && /^#!\/bin\/sh$/ { print FILENAME }' | - xargs shellcheck +git ls-files | + xargs awk '/^#!\/bin\/sh$/ { print FILENAME } { nextfile }' | + xargs shellcheck -x diff --git a/aux/dev.mk b/aux/dev.mk index e644edb..9b91786 100644 --- a/aux/dev.mk +++ b/aux/dev.mk @@ -6,7 +6,7 @@ .in: sed \ -e "s:@TLD@:`cat aux/tld.txt`:g" \ - -e "s:@NAME@:`basename $$PWD`:g" \ + -e "s:@NAME@:`basename "$$PWD"`:g" \ -e 's:@MAILING_LIST@:$(MAILING_LIST):g' \ < $< > $@ @@ -14,13 +14,13 @@ pandoc -s -r man -w html \ -H aux/headers.html \ --metadata lang="`echo $< | awk -F. '{ print $$(NF-2) }'`" \ - < $( $@ + < $( $@ .md.html: pandoc -s -r commonmark -w html \ -H aux/headers.html \ --metadata lang="`echo $( $@ @@ -38,14 +38,14 @@ public/index.html: ln -rs public/en/index.html $@ public/ci: - sh aux/ci/report.sh -n `basename "$$PWD"` -o $@ + sh aux/ci/report.sh -n "`basename "$$PWD"`" -o $@ public/TODOs.html: TODOs.md aux/preamble-md mkdir -p $(@D) td -H | cat aux/preamble-md - | pandoc -s -r commonmark -w html \ -H aux/headers.html \ --metadata lang=en \ - --metadata title="`basename $$PWD` - TODOs" \ + --metadata title="`basename "$$PWD"` - TODOs" \ --toc --toc-depth=2 \ --highlight-style pygments \ > $@ diff --git a/aux/lib.sh b/aux/lib.sh index f168294..1d7dabe 100644 --- a/aux/lib.sh +++ b/aux/lib.sh @@ -21,7 +21,8 @@ uuid() { } tmpname() { - printf '%s/uuid-tmpname with spaces.%s' "${TMPDIR:-/tmp}" "$(uuid)" + # printf '%s/uuid-tmpname with spaces.%s' "${TMPDIR:-/tmp}" "$(uuid)" + printf '%s/uuid-tmpname-without-spaces.%s' "${TMPDIR:-/tmp}" "$(uuid)" } mkstemp() { @@ -32,6 +33,6 @@ mkstemp() { mkdtemp() { name="$(tmpname)" - mkdir -- "$name" + mkdir -p -- "$name" printf '%s' "$name" } diff --git a/repo.sh b/repo.sh new file mode 100755 index 0000000..7d81867 --- /dev/null +++ b/repo.sh @@ -0,0 +1,33 @@ +#!/bin/sh +set -eu + +f() { + set -e + bad-command + unreachable + return 0 +} + +f && echo 'Executed, but shoult not' + +if f; then + echo 'Also executed, but should not' +fi + +f || echo 'Not executed, but should be' + +if ! f; then + echo 'Also not executed, but should be' +fi + +set -x +set +e +f +STATUS=$? +set -e +if [ "$STATUS" != 0 ]; then + echo 'Only one that is executed when it should be' +fi + +f +echo 'This is *actually* unreachable' diff --git a/src/remembering.in b/src/remembering.in index 907ffe1..89e9453 100755 --- a/src/remembering.in +++ b/src/remembering.in @@ -138,7 +138,7 @@ if [ -z "$CHOICE" ]; then exit fi -cat "$MERGED" | +< "$MERGED" \ cut -d' ' -f1,3- | uniq -f1 | awk -vCHOICE="$CHOICE" ' -- cgit v1.2.3