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"