Skip to content

Commit

Permalink
is-accessible, tests.bash: group tests
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Jan 7, 2025
1 parent 39b921d commit b13a707
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions commands/is-accessible
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function is_accessible_test() (
0 "$root/symlinks/non-writable-subdir-file"
0 "$root/symlinks/non-writable-subdir"
)
fs_tests__tuples "$command" --sudo -- "${tuples[@]}"
fs_tests__tuples --group='test escalation' "$command" --sudo -- "${tuples[@]}"

# test default escalation
tuples=(
Expand All @@ -104,7 +104,7 @@ function is_accessible_test() (
"$(fs_tests__root_status 0)" "$root/symlinks/non-executable-subdir-file"
"$(fs_tests__root_status 0)" "$root/symlinks/non-executable-subdir"
)
fs_tests__tuples "$command" -- "${tuples[@]}"
fs_tests__tuples --group='test default escalation' "$command" -- "${tuples[@]}"

# test no escalation
tuples=(
Expand All @@ -126,9 +126,9 @@ function is_accessible_test() (
"$(fs_tests__root_status 0)" "$root/symlinks/non-executable-subdir-file"
"$(fs_tests__root_status 0)" "$root/symlinks/non-executable-subdir"
)
fs_tests__tuples "$command" --no-sudo -- "${tuples[@]}"
fs_tests__tuples --group='test no escalation' "$command" --no-sudo -- "${tuples[@]}"

# break the symlinks, test broken symlinks
# break the symlinks
sudo-helper -- rm -rf "$root/targets"
tuples=(
0 "$root/symlinks/empty-dir"
Expand Down Expand Up @@ -164,7 +164,7 @@ function is_accessible_test() (
0 "$root/symlinks/non-writable-subdir-file"
0 "$root/symlinks/non-writable-subdir"
)
fs_tests__tuples "$command" -- "${tuples[@]}"
fs_tests__tuples --group='test broken symlinks' "$command" -- "${tuples[@]}"

echo-style --g1="TEST: $0"
return 0
Expand Down
12 changes: 11 additions & 1 deletion sources/tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ function fs_tests__root_status {
fi
}
function fs_tests__tuples {
local command args=() tuples=()
local group='' command args=() tuples=()

# process
local item
while [[ $# -ne 0 ]]; do
item="$1"
shift
case "$item" in
'--group='*) group="${item#*=}" ;;
'--command='*) command="${item#*=}" ;;
'--')
tuples+=("$@")
Expand All @@ -133,6 +134,9 @@ function fs_tests__tuples {
root="$(fs-temp --directory="$command")"

# tests
if [[ -n "$group" ]]; then
echo-style --g2="$group"
fi
local index status path total="${#tuples[@]}" result=0
for ((index = 0; index < total; index += 2)); do
status="${tuples[index]}"
Expand All @@ -144,7 +148,13 @@ function fs_tests__tuples {
fi
done
if [[ $result -ne 0 ]]; then
if [[ -n "$group" ]]; then
echo-style --e2="$group"
fi
return 1
fi
if [[ -n "$group" ]]; then
echo-style --g2="$group"
fi
return 0
}

0 comments on commit b13a707

Please sign in to comment.