From ce624f79834221b90b9b8a73ad5748ae0d0c2295 Mon Sep 17 00:00:00 2001 From: Crestez Dan Leonard Date: Wed, 3 Feb 2010 13:30:05 +0200 Subject: Use find_unique_completion_pair in chown test --- test/lib/completions/chown.exp | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/test/lib/completions/chown.exp b/test/lib/completions/chown.exp index 480f6743..b1207eed 100644 --- a/test/lib/completions/chown.exp +++ b/test/lib/completions/chown.exp @@ -14,26 +14,21 @@ assert_complete_any "chown " sync_after_int -# All the tests use the root:root user and group. They're assumed to exist. -set fulluser "root" -set fullgroup "root" - -# Partial username is assumed to be unambiguous. -set partuser "roo" -set partgroup "roo" - -# Skip tests if root:root not available or if roo:roo matches multiple -# users/groups -# -# compgen -A is used because it's a bash builtin and available everywhere. -# The || true part prevents exec from throwing an exception if nothing is -# found. -if {[exec bash -c "compgen -A user $partuser || true" | wc -l] > 1 || - [exec bash -c "compgen -A user $fulluser || true" | wc -l] != 1 || - [exec bash -c "compgen -A group $partgroup || true" | wc -l] > 1 || - [exec bash -c "compgen -A group $fullgroup || true" | wc -l] != 1} { - untested "Not running complex chown tests." -} else { +# Find user/group suitable for testing. +set failed_find_unique_completion 0 +foreach ug {user group} { + # compgen -A is used because it's a bash builtin and available everywhere. + # The || true part prevents exec from throwing an exception if nothing is + # found (very very unlikely). + set list [split [exec bash -c "compgen -A $ug || true"] "\n"] + if {![find_unique_completion_pair $list part$ug full$ug]} { + untested "Not running complex chown tests; no suitable test $ug found." + set failed_find_unique_completion 1 + } +} + +# These tests require an unique completion. +if {!$failed_find_unique_completion} { assert_complete $fulluser "chown $partuser" sync_after_int -- cgit v1.2.1