From c52f372a8c5210ee9f8109d5d897f448cfe27ce1 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 8 Aug 2021 21:01:10 -0500 Subject: [PATCH] Fix test function `mktemp` to avoid false errors If called within a temporary directory that had an X in the path, it would fail. This caused sporadic CI test failures. --- tests/test_functions/mktemp.fish | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/test_functions/mktemp.fish b/tests/test_functions/mktemp.fish index d99d48b8f..c0b073aa5 100644 --- a/tests/test_functions/mktemp.fish +++ b/tests/test_functions/mktemp.fish @@ -52,19 +52,16 @@ function mktemp # So let's outlaw them anywhere besides the end. # Similarly GNU mktemp requires at least 3 X's, BSD mktemp requires none. Let's require 3. begin - set -l chars (string split '' -- $template) - set -l found_x - for c in $chars - if test $c = X - set found_x $found_x X - else if set -q found_x[1] - echo 'mktemp: X\'s may only occur at the end of the template' >&2 - _mktemp_help >&2 - exit 1 - end + # Look for at least three Xs that are not the end of the template + if string match -rq -- 'XXX[^X].*$' "$template" + echo "mktemp: X's may only occur at the end of the template '$template'" >&2 + _mktemp_help >&2 + exit 1 end - if test (count $found_x) -lt 3 - echo "mktemp: too few X's in template '$template'" >&2 + + # Look for too few X incidences at the end of the template + if ! string match -rq -- 'XXX$' "$template" + echo "mktemp: too few trailing X's in template '$template'" >&2 _mktemp_usage >&2 exit 1 end