src/file.bash: Align code of `assert_not_file_owner` to `assert_file_owner` Change the code of `assert_not_file_owner` to the version of `assert_file_owner` introduced in PR #38. The removal of the stray sudo calls fixes issue #49.
diff --git a/src/file.bash b/src/file.bash index e96c3c2..2fce974 100644 --- a/src/file.bash +++ b/src/file.bash
@@ -818,27 +818,20 @@ assert_not_file_owner() { local -r owner="$1" local -r file="$2" - if [[ `uname` == "Darwin" ]]; then - sudo chown root ${TEST_FIXTURE_ROOT}/dir/owner - sudo chown daemon ${TEST_FIXTURE_ROOT}/dir/notowner - if [ `stat -f '%Su' "$file"` = "$owner" ]; then + if [[ "$(uname)" == "Darwin" ]]; then + __cmd_param="-f %Su" + elif [[ "$(uname)" == "Linux" ]]; then + __cmd_param="-c %U" + fi + __o=$(stat $__cmd_param "$file") + + if [[ "$__o" == "$owner" ]]; then local -r rem="${BATSLIB_FILE_PATH_REM-}" local -r add="${BATSLIB_FILE_PATH_ADD-}" batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ - | batslib_decorate "given user is the $owner, but it was expected not to be" \ + | batslib_decorate "user $owner is the owner of the file, but it was expected not to be" \ | fail fi - elif [[ `uname` == "Linux" ]]; then - sudo chown root ${TEST_FIXTURE_ROOT}/dir/owner - sudo chown daemon ${TEST_FIXTURE_ROOT}/dir/notowner - if [ `stat -c "%U" "$file"` = "$owner" ]; then - local -r rem="${BATSLIB_FILE_PATH_REM-}" - local -r add="${BATSLIB_FILE_PATH_ADD-}" - batslib_print_kv_single 4 'path' "${file/$rem/$add}" \ - | batslib_decorate "given user is the $owner, but it was expected not to be" \ - | fail - fi -fi } # Fail if the file has given permissions. This