Skip to content

Commit

Permalink
switch stat format flag depending on available
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeichlersmith committed May 10, 2024
1 parent a7b9c73 commit 0762e2c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/ownership.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ teardown() {

@test "file created inside denv has id match" {
run denv touch file-from-denv
assert_equal "$(stat -c %u file-from-denv)" "$(id -u ${USER})"
assert_equal "$(stat -c %g file-from-denv)" "$(id -g ${USER})"
# `-c` is the short for --format for GNU coreutils
# `-f` is the equivalent for BSD
# we can detect which stat we are using by testing
# for the GNU flag
format_flag="-c"
if ! stat ${format_flag} > /dev/null 2>&1; then
format_flag="-f"
fi
assert_equal "$(stat ${format_flag} %u file-from-denv)" "$(id -u ${USER})"
assert_equal "$(stat ${format_flag} %g file-from-denv)" "$(id -g ${USER})"
}

0 comments on commit 0762e2c

Please sign in to comment.