Skip to content

Commit 9703797

Browse files
szedergitster
authored andcommitted
t9902-completion: ignore COMPREPLY element order in some tests
The order or possible completion words in the COMPREPLY array doesn't actually matter, as long as all the right words are in there, because Bash will sort them anyway. Yet, our tests looking at the elements of COMPREPLY always expect them to be in a specific order. Now, this hasn't been an issue before, but the next patch is about to optimize a bit more our git-aware path completion, and as a harmless side effect the order of elements in COMPREPLY will change. Worse, the order will be downright undefined, because after the next patch path components will come directly from iterating through an associative array in 'awk', and the order of iteration over the elements in those arrays is undefined, and indeed different 'awk' implementations produce different order. Consequently, we can't get away with simply adjusting the expected results in the affected tests. Modify the 'test_completion' helper function to sort both the expected and the actual results, i.e. the elements in COMPREPLY, before comparing them, so the tests using this helper function will work regardless of the order of elements. Note that this change still leaves a bunch of tests depending on the order of elements in COMPREPLY, tests that focus on a specific helper function and therefore don't use the 'test_completion' helper. I would rather deal with those later, when (if ever) the need actually arises, than create unnecessary code churn now. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 105c0ef commit 9703797

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

t/t9902-completion.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ test_completion ()
8484
then
8585
printf '%s\n' "$2" >expected
8686
else
87-
sed -e 's/Z$//' >expected
87+
sed -e 's/Z$//' |sort >expected
8888
fi &&
8989
run_completion "$1" &&
90-
test_cmp expected out
90+
sort out >out_sorted &&
91+
test_cmp expected out_sorted
9192
}
9293

9394
# Test __gitcomp.
@@ -1405,6 +1406,7 @@ test_expect_success 'complete files' '
14051406
14061407
echo "expected" > .gitignore &&
14071408
echo "out" >> .gitignore &&
1409+
echo "out_sorted" >> .gitignore &&
14081410
14091411
git add .gitignore &&
14101412
test_completion "git commit " ".gitignore" &&

0 commit comments

Comments
 (0)