From eb36015612094d02892b1bbee6f1d3779ed16df2 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Sat, 20 Jul 2024 16:13:52 -0400 Subject: [PATCH] chore: Fix various pending test formatting issues - Some test files did not properly end with a newline. All resolved. - Graph generation failed on macOS under CI. Resolved. - Reformatted most of the test scripts and their expected output to match the reformatting. --- Makefile | 5 ++- src/_adr_generate_graph | 34 +++++++++++-------- tests/edit-adr.expected | 3 +- tests/edit-adr.sh | 3 +- tests/list-records.sh | 2 +- tests/migrate-date-format.expected | 5 +-- tests/migrate-date-format.sh | 5 +-- ...-provide-a-nonexisting-adr-number.expected | 5 ++- .../must-provide-a-nonexisting-adr-number.sh | 5 ++- ...ngle-number-when-creating-new-adr.expected | 5 ++- ...e-a-single-number-when-creating-new-adr.sh | 5 ++- ...ide-a-title-when-creating-new-adr.expected | 5 ++- ...t-provide-a-title-when-creating-new-adr.sh | 5 ++- tests/supersede-existing-adr.expected | 1 - tests/supersede-existing-adr.sh | 1 - 15 files changed, 41 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 455edf5..a1e4f43 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,14 @@ BUILDDIR:=/tmp/adr-tools-build check: $(TESTS:tests/%.sh=$(BUILDDIR)/tests/%.diff) @echo SUCCESS +recheck: clean check + tests/adr-config.expected: tests/adr-config.expected.tmpl @sed -e "s!__PWD__!$(shell pwd -P)!g" < $< > $@ $(BUILDDIR)/tests/%.diff: $(BUILDDIR)/tests/%.output tests/%.expected - @diff --side-by-side --width 225 $^ > $@ || ! cat -n $@ + @diff --side-by-side $^ > $@ || ! cat -n $@ + @#diff --side-by-side --width 225 $^ > $@ || ! cat -n $@ @#diff -u $^ > $@ || ! cat $@ $(BUILDDIR)/tests/%.output: tests/%.sh tests/%.expected $(SRC) diff --git a/src/_adr_generate_graph b/src/_adr_generate_graph index 6c6f0d4..61a5126 100755 --- a/src/_adr_generate_graph +++ b/src/_adr_generate_graph @@ -34,16 +34,16 @@ link_extension=.html while getopts e:p: arg; do case "${arg}" in - e) - link_extension="$OPTARG" - ;; - p) - link_prefix="$OPTARG" - ;; - *) - echo "Not implemented: ${arg}" >&2 - exit 1 - ;; + e) + link_extension="$OPTARG" + ;; + p) + link_prefix="$OPTARG" + ;; + *) + echo "Not implemented: ${arg}" >&2 + exit 1 + ;; esac done shift $((OPTIND - 1)) @@ -60,16 +60,22 @@ for f in $("${adr_bin_dir:?}"/adr-list); do n=$(index "$f") title="$("${adr_bin_dir:?}"/_adr_title "$f")" - echo " _$n [label=\"${title}\"; URL=\"${link_prefix}$(basename "$f" .md)${link_extension}\"];" - if [ "$n" -gt 1 ]; then - echo " _$(("$n" - 1)) -> _$n [style=\"dotted\", weight=1];" + url="${link_prefix}$(basename "$f" .md)${link_extension}" + + printf " _%s [label=\"%s\"; URL=\"%s\"];\n" "$n" "${title}" "${url}" + + if ((n > 1)); then + printf " _%s -> _%s [style=\"dotted\", weight=1];\n" $((n - 1)) "$n" fi done + echo " }" for f in $("${adr_bin_dir:?}"/adr-list); do n=$(index "$f") - "${adr_bin_dir:?}"/_adr_links "$f" | grep -Ev " by$" | sed -E -e 's/^([0-9]+)=(.+)$/ _'"$n"' -> _\1 [label="\2", weight=0]/;' + "${adr_bin_dir:?}"/_adr_links "$f" | + grep -Ev " by$" | + sed -E -e 's/^([0-9]+)=(.+)$/ _'"$n"' -> _\1 [label="\2", weight=0]/;' done echo "}" diff --git a/tests/edit-adr.expected b/tests/edit-adr.expected index 683759b..d05e979 100644 --- a/tests/edit-adr.expected +++ b/tests/edit-adr.expected @@ -6,8 +6,7 @@ architecture-log/0002-first-record.md export VISUAL export EDITOR -if adr edit -then +if adr edit; then echo ERROR: should have failed fi ERROR: editor not configured diff --git a/tests/edit-adr.sh b/tests/edit-adr.sh index e9cdd40..3fac65d 100644 --- a/tests/edit-adr.sh +++ b/tests/edit-adr.sh @@ -4,8 +4,7 @@ adr new First Record export VISUAL export EDITOR -if adr edit -then +if adr edit; then echo ERROR: should have failed fi diff --git a/tests/list-records.sh b/tests/list-records.sh index 7be5440..97b588a 100644 --- a/tests/list-records.sh +++ b/tests/list-records.sh @@ -5,4 +5,4 @@ adr new second adr list adr new third adr list -adr list -r \ No newline at end of file +adr list -r diff --git a/tests/migrate-date-format.expected b/tests/migrate-date-format.expected index 453dc89..083c2be 100644 --- a/tests/migrate-date-format.expected +++ b/tests/migrate-date-format.expected @@ -1,9 +1,6 @@ adr init doc/adr/0001-record-architecture-decisions.md -( - ADR_DATE=12/01/1992 - adr new With Old Date Format -) +(ADR_DATE=12/01/1992 adr new With Old Date Format) doc/adr/0002-with-old-date-format.md adr new With Current Date Format doc/adr/0003-with-current-date-format.md diff --git a/tests/migrate-date-format.sh b/tests/migrate-date-format.sh index ee049d0..02eced9 100644 --- a/tests/migrate-date-format.sh +++ b/tests/migrate-date-format.sh @@ -1,8 +1,5 @@ adr init -( - ADR_DATE=12/01/1992 - adr new With Old Date Format -) +(ADR_DATE=12/01/1992 adr new With Old Date Format) adr new With Current Date Format grep Date: doc/adr/* adr upgrade-repository diff --git a/tests/must-provide-a-nonexisting-adr-number.expected b/tests/must-provide-a-nonexisting-adr-number.expected index 19169b3..dfdd6be 100644 --- a/tests/must-provide-a-nonexisting-adr-number.expected +++ b/tests/must-provide-a-nonexisting-adr-number.expected @@ -4,8 +4,7 @@ adr new The Second Decision doc/adr/0002-the-second-decision.md adr new The Third Decision doc/adr/0003-the-third-decision.md -if adr new -n 2 The Fourth Decision -then - echo ERROR: should have failed +if adr new -n 2 The Fourth Decision; then + echo ERROR: should have failed fi ERROR: ADR number 2 already exists diff --git a/tests/must-provide-a-nonexisting-adr-number.sh b/tests/must-provide-a-nonexisting-adr-number.sh index cf41bb6..aafc0d1 100644 --- a/tests/must-provide-a-nonexisting-adr-number.sh +++ b/tests/must-provide-a-nonexisting-adr-number.sh @@ -1,7 +1,6 @@ adr new The First Decision adr new The Second Decision adr new The Third Decision -if adr new -n 2 The Fourth Decision -then - echo ERROR: should have failed +if adr new -n 2 The Fourth Decision; then + echo ERROR: should have failed fi diff --git a/tests/must-provide-a-single-number-when-creating-new-adr.expected b/tests/must-provide-a-single-number-when-creating-new-adr.expected index a6e1e81..6eaf1e6 100644 --- a/tests/must-provide-a-single-number-when-creating-new-adr.expected +++ b/tests/must-provide-a-single-number-when-creating-new-adr.expected @@ -1,5 +1,4 @@ -if adr new -n 23 -n 24 Test ADR -then - echo ERROR: should have failed +if adr new -n 23 -n 24 Test ADR; then + echo ERROR: should have failed fi ERROR: multiple numbers given diff --git a/tests/must-provide-a-single-number-when-creating-new-adr.sh b/tests/must-provide-a-single-number-when-creating-new-adr.sh index 4ac7778..a6980ac 100644 --- a/tests/must-provide-a-single-number-when-creating-new-adr.sh +++ b/tests/must-provide-a-single-number-when-creating-new-adr.sh @@ -1,4 +1,3 @@ -if adr new -n 23 -n 24 Test ADR -then - echo ERROR: should have failed +if adr new -n 23 -n 24 Test ADR; then + echo ERROR: should have failed fi diff --git a/tests/must-provide-a-title-when-creating-new-adr.expected b/tests/must-provide-a-title-when-creating-new-adr.expected index 3d9ed99..b836053 100644 --- a/tests/must-provide-a-title-when-creating-new-adr.expected +++ b/tests/must-provide-a-title-when-creating-new-adr.expected @@ -1,5 +1,4 @@ -if adr new -then - echo ERROR: should have failed +if adr new; then + echo ERROR: should have failed fi ERROR: no title given diff --git a/tests/must-provide-a-title-when-creating-new-adr.sh b/tests/must-provide-a-title-when-creating-new-adr.sh index 29c5fd2..e238bbb 100644 --- a/tests/must-provide-a-title-when-creating-new-adr.sh +++ b/tests/must-provide-a-title-when-creating-new-adr.sh @@ -1,4 +1,3 @@ -if adr new -then - echo ERROR: should have failed +if adr new; then + echo ERROR: should have failed fi diff --git a/tests/supersede-existing-adr.expected b/tests/supersede-existing-adr.expected index 8a53a7a..67dccc2 100644 --- a/tests/supersede-existing-adr.expected +++ b/tests/supersede-existing-adr.expected @@ -26,4 +26,3 @@ Supersedes [1. First Record](0001-first-record.md) ## Context - diff --git a/tests/supersede-existing-adr.sh b/tests/supersede-existing-adr.sh index 679896a..5712ad9 100644 --- a/tests/supersede-existing-adr.sh +++ b/tests/supersede-existing-adr.sh @@ -2,4 +2,3 @@ adr new First Record adr new -s 1 Second Record head -10 doc/adr/0001-first-record.md head -12 doc/adr/0002-second-record.md -