Re: [PATCH 1/3] t0033: add tests for safe.directory
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Apr 13, 2022, 19:16 UTC
- Message-ID
- <220413.86k0bseqq8.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <5b18bd1852d673ab5c62a67f873987d74294cd70.1649863951.git.gitgitgadget@gmail.com>
On Wed, Apr 13 2022, Derrick Stolee via GitGitGadget wrote:
Show 6 quoted lines
> From: Derrick Stolee <derrickstolee@github.com> > > It is difficult to change the ownership on a directory in our test > suite, so insert a new GIT_TEST_ASSUME_DIFFERENT_OWNER environment > variable to trick Git into thinking we are in a differently-owned > directory. This allows us to test that the config is parsed correctly.
I think this is a good trade-off, but FWIW I'd think we could test also without the git_env_bool() by having the test depend on !NOT_ROOT, then check the owner of t/test-lib.sh, and chown to that user (i.e. the "real" user).
But that's all sorts of more fragile than just this test variable..
Show 6 quoted lines
> +test_description='verify safe.directory checks' > + > +. ./test-lib.sh > + > +GIT_TEST_ASSUME_DIFFERENT_OWNER=1 > +export GIT_TEST_ASSUME_DIFFERENT_OWNER
Instead of this "export" perhaps just add it in front of the "git status"?
These tests also pass with SANITIZE=leak, so please add TEST_PASSES_SANITIZE_LEAK=true at the top.
Show 16 quoted lines
> +expect_rejected_dir () {
> + test_must_fail git status 2>err &&
> + grep "safe.directory" err
> +}
> +
> +test_expect_success 'safe.directory is not set' '
> + expect_rejected_dir
> +'
> +
> +test_expect_success 'safe.directory does not match' '
> + git config --global safe.directory bogus &&
> + expect_rejected_dir
> +'
> +
> +test_expect_success 'safe.directory matches' '
> + git config --global --add safe.directory "$(pwd)" &&nit: $PWD instead of $(pwd)