Skip to content

Commit

Permalink
chore: Fix various pending test formatting issues
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
halostatue committed Jul 20, 2024
1 parent 3f9cebf commit eb36015
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 48 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 20 additions & 14 deletions src/_adr_generate_graph
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 "}"
3 changes: 1 addition & 2 deletions tests/edit-adr.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/edit-adr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/list-records.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ adr new second
adr list
adr new third
adr list
adr list -r
adr list -r
5 changes: 1 addition & 4 deletions tests/migrate-date-format.expected
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions tests/migrate-date-format.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions tests/must-provide-a-nonexisting-adr-number.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions tests/must-provide-a-nonexisting-adr-number.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions tests/must-provide-a-single-number-when-creating-new-adr.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions tests/must-provide-a-title-when-creating-new-adr.expected
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions tests/must-provide-a-title-when-creating-new-adr.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
if adr new
then
echo ERROR: should have failed
if adr new; then
echo ERROR: should have failed
fi
1 change: 0 additions & 1 deletion tests/supersede-existing-adr.expected
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ Supersedes [1. First Record](0001-first-record.md)

## Context


1 change: 0 additions & 1 deletion tests/supersede-existing-adr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eb36015

Please sign in to comment.