test suite: add a check that all test numbers are unique
PATCH 1/1 test suite: add a check that all test numbers are unique
From: Johannes Sixt <[email protected]>
The test runs only if 'make all' is used. Its purpose is to alert our valued integrator if different branches are merged that happen to introduce the same test number.
--- t/Makefile | 1 + t/check_unique_numbers.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 0 deletions(-) create mode 100755 t/check_unique_numbers.sh
t/Makefile +1 -0
@@ -17,6 +17,7 @@ T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) TSVN = $(wildcard t91[0-9][0-9]-*.sh) all: pre-clean + '$(SHELL_PATH_SQ)' ./check_unique_numbers.sh $(MAKE) aggregate-results-and-cleanup $(T):
t/check_unique_numbers.sh new file +27 -0
@@ -0,0 +1,27 @@ +#!/bin/sh + +# checks whether test case numbers are unique; +# returns non-zero if any duplicates were found + +check_numbers () { + last= dup= + while read name + do + case $name in + t[0-9][0-9][0-9][0-9]-*.sh) + number=${name%%-*} + if test "$number" = "$last"; then + dup="$dup $number" + fi + last=$number + ;; + esac + done + test -z "$dup" || { + echo >&2 "error: duplicate test numbers:" $dup + return 1 + } +} + +ls -1 | # no wildcard to avoid overflow of command line +check_numbers
Signature · 1 line
1.6.4.204.g6aad7
Quoted 3 lines · Johannes Sixt
The test runs only if 'make all' is used. Its purpose is to alert our valued integrator if different branches are merged that happen to introduce the same test number.
I think this is probably useful. In addition to the t7406 you posted a patch for, it looks like t4037 has a duplicate in next.
As for the implementation:
Quoted 19 lines
+++
b/t/check_unique_numbers.sht/check_unique_numbers.sh new file +17
-0@@ -0,0 +1,27 @@ +#!/bin/sh + +# checks whether test case numbers are unique; +# returns non-zero if any duplicates were found + +check_numbers () { + last= dup= + while read name + do + case $name in + t[0-9][0-9][0-9][0-9]-*.sh) + number=${name%%-*} + if test "$number" = "$last"; then + dup="$dup $number" + fi + last=$number + ;;
t/check_unique_numbers.sh line 27
Quoted 10 lines
t/check_unique_numbers.sh new file +10
-0+ esac + done + test -z "$dup" || { + echo >&2 "error: duplicate test numbers:" $dup + return 1 + } +} + +ls -1 | # no wildcard to avoid overflow of command line +check_numbers
Why not the much shorter:
tests() {
ls | sed -n 's/^\(t[0-9][0-9][0-9][0-9]\)-.*\.sh$/\1/p'
}
dups=tests | uniq -d
instead of the long shell loop?
-Peff
PATCH v2 1/1 test suite: add a check that all test numbers are unique
Quoted 8 lines · Jeff King
Why not the much shorter:
tests(){
ls | sed -n 's/^\(t[0-9][0-9][0-9][0-9]\)-.*\.sh$/\1/p'
}
dups=tests | uniq -dinstead of the long shell loop?
Because it's faster on Windows ;-) No, seriously, I didn't know about uniq -d.
Here is a replacement patch.
--- 8< ---
From: Johannes Sixt <[email protected]>
Subject: [PATCH] t/Makefile: add a check that all test numbers are unique
The test runs only if 'make all' is used. Its purpose is to alert our valued integrator if different branches are merged that happen to introduce the same test number.
--- t/Makefile | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
t/Makefile +4 -0
@@ -17,6 +17,10 @@ T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) TSVN = $(wildcard t91[0-9][0-9]-*.sh) all: pre-clean + @dups=`ls | sed -n 's/^\(t[0-9][0-9][0-9][0-9]\)-.*\.sh$$/\1/p' | \ + uniq -d` && \ + test -z "$$dups" || { \ + echo "duplicate test numbers:" $$dups; exit 1; } $(MAKE) aggregate-results-and-cleanup $(T):
Signature · 1 line
1.6.4.204.g6aad7
Quoted 2 lines · Johannes Sixt
Because it's faster on Windows ;-) No, seriously, I didn't know about uniq -d.
:)
Quoted 1 line
Here is a replacement patch.
Looks good to me. Thanks.
-Peff