tests, maxlen.bash: speed up TestMaxlen using QUICK=1

From >6 to <1 second.
This commit is contained in:
Jakob Unterwurzacher 2021-06-26 19:12:52 +02:00
parent 446c3d7e93
commit ad3eeaedc5
2 changed files with 25 additions and 17 deletions

View File

@ -32,25 +32,36 @@ while true ; do
echo "error: file $PWD/$NEXT already exists" echo "error: file $PWD/$NEXT already exists"
exit 1 exit 1
fi fi
touch $NEXT 2> /dev/null || break echo -n 2> /dev/null > $NEXT || break
rm $NEXT rm $NEXT
NAME="$NEXT" NAME="$NEXT"
done done
echo "${#NAME}" echo "${#NAME}"
echo -n " Maximum dirname length: " # Set to 0 if undefined
# Add one character at a time until we hit an error : ${QUICK:=0}
NAME=""
while true ; do if [[ $QUICK -ne 1 ]]; then
echo -n " Maximum dirname length: "
# Add one character at a time until we hit an error
NAME=""
while true ; do
NEXT="${NAME}x" NEXT="${NAME}x"
mkdir $NEXT 2> /dev/null || break mkdir $NEXT 2> /dev/null || break
rmdir $NEXT rmdir $NEXT
NAME="$NEXT" NAME="$NEXT"
done done
MAX_DIRNAME=${#NAME} MAX_DIRNAME=${#NAME}
echo "${#NAME}" echo "${#NAME}"
fi
for CHARS_PER_SUBDIR in 1 10 100 $MAX_DIRNAME ; do if [[ $QUICK -eq 1 ]]; then
CHARS_TODO=100
else
CHARS_TODO="1 10 100 $MAX_DIRNAME"
fi
for CHARS_PER_SUBDIR in $CHARS_TODO ; do
echo -n " Maximum path length with $(printf %3d $CHARS_PER_SUBDIR) chars per subdir: " echo -n " Maximum path length with $(printf %3d $CHARS_PER_SUBDIR) chars per subdir: "
if [[ $INTERACTIVE -eq 1 ]] ; then if [[ $INTERACTIVE -eq 1 ]] ; then
echo -n " " echo -n " "

View File

@ -380,6 +380,7 @@ func TestMaxlen(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
cmd := exec.Command("../../contrib/maxlen.bash", workDir) cmd := exec.Command("../../contrib/maxlen.bash", workDir)
cmd.Env = []string{"QUICK=1"}
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
t.Log(string(out)) t.Log(string(out))
@ -387,11 +388,7 @@ func TestMaxlen(t *testing.T) {
} }
want := ` want := `
Maximum filename length: 255 Maximum filename length: 255
Maximum dirname length: 255
Maximum path length with 1 chars per subdir: 4095
Maximum path length with 10 chars per subdir: 4095
Maximum path length with 100 chars per subdir: 4095 Maximum path length with 100 chars per subdir: 4095
Maximum path length with 255 chars per subdir: 4095
` `
if !strings.HasSuffix(string(out), want) { if !strings.HasSuffix(string(out), want) {
t.Errorf("wrong output: %s", string(out)) t.Errorf("wrong output: %s", string(out))