summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-09-10 19:52:01 +0100
committerw0rp <devw0rp@gmail.com>2017-09-10 19:52:01 +0100
commit65e6e50bf8b973519b511c60076777db295d79ff (patch)
tree9476daf49a529014f00634f8222b874efe0bfbf8 /test
parent9d24cc40471441fef4c5dd2467f22eea072d2c2d (diff)
downloadale-65e6e50bf8b973519b511c60076777db295d79ff.zip
Explain the table of contents script better, and simplify it a bit
Diffstat (limited to 'test')
-rwxr-xr-xtest/script/check-toc16
1 files changed, 8 insertions, 8 deletions
diff --git a/test/script/check-toc b/test/script/check-toc
index 039707eb..c4512b08 100755
--- a/test/script/check-toc
+++ b/test/script/check-toc
@@ -19,7 +19,7 @@ toc_end_line="$(expr "$toc_start_line" + "$toc_section_size" - 2)"
toc_file="$(mktemp -t table-of-contents.XXXXXXXX)"
heading_file="$(mktemp -t headings.XXXXXXXX)"
-unsorted_toc_file="$(mktemp -t ale.txt.XXXXXXXX)"
+tagged_toc_file="$(mktemp -t ale.txt.XXXXXXXX)"
sorted_toc_file="$(mktemp -t sorted-ale.txt.XXXXXXXX)"
sed -n "$toc_start_line,$toc_end_line"p doc/ale.txt \
@@ -43,6 +43,8 @@ exit_code=0
in_section=0
section_index=0
+# Prefix numbers to table of contents entries so that sections aren't mixed up
+# with sub-sections when they are sorted.
while read -r; do
if [[ "$REPLY" =~ ^\ ]]; then
if ! ((in_section)); then
@@ -56,17 +58,15 @@ while read -r; do
fi
fi
- echo "$section_index $REPLY" >> "$unsorted_toc_file"
+ echo "$section_index $REPLY" >> "$tagged_toc_file"
done < "$toc_file"
-
-sort -h "$unsorted_toc_file" | sed 's/[0-9]\+//' > "$sorted_toc_file"
-sed -i.bak 's/[0-9]\+//' "$unsorted_toc_file"
-rm -f "$unsorted_toc_file".bak
+# Sort the sections and sub-sections and remove the tags.
+sort -h "$tagged_toc_file" | sed 's/[0-9]\+ //' > "$sorted_toc_file"
echo 'Check for bad ToC sorting:'
echo
-diff -U2 "$sorted_toc_file" "$unsorted_toc_file" || exit_code=$?
+diff -U2 "$sorted_toc_file" "$toc_file" || exit_code=$?
echo 'Check for mismatched ToC and headings:'
echo
@@ -74,7 +74,7 @@ diff -U3 "$toc_file" "$heading_file" || exit_code=$?
rm "$toc_file"
rm "$heading_file"
-rm "$unsorted_toc_file"
+rm "$tagged_toc_file"
rm "$sorted_toc_file"
exit "$exit_code"