[PATCH v2 0/2] make macOS `git maintenance` test work on Windows
This is a re-roll of [1] which makes the macOS-specific test of `git maintenance start` and `git maintenance stop` work correctly on Windows (since the tests have been otherwise carefully crafted to work on any platform even though the `start` and `stop` commands themselves are necessarily platform-specific).
v2 makes the macOS-specific test in t7900 UID-agnostic, as suggested by Ævar[2], thus the patch which added `test-tool getuid` has been dropped.
This series is built atop ds/maintenance-part-4.
[1]: https://lore.kernel.org/git/20201127075054.31174-1-sunshine@sunshineco.com/ [2]: https://lore.kernel.org/git/87o8jikfh7.fsf@evledraar.gmail.com/
Eric Sunshine (2): t7900: fix test failures when invoked individually via --run t7900: make macOS-specific test work on Windows
t/t7900-maintenance.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
Range-diff against v1:
1: 9f9b26de93 = 1: d535669fb9 t7900: fix test failures when invoked individually via --run
2: 07c9e9bd69 < -: ---------- test-tool: add `getuid` subcommand
3: 01c6a3229d ! 2: 8561d08bcd t7900: make macOS-specific test work on Windows
@@ Commit message
invoke platform-specific scheduling utilities, their related tests have
been carefully crafted -- with one minor exception -- to work correctly
on any platform, thus improving overall coverage. The exception is that
- the macOS-specific test fails on Windows due to unportable use of
- `$(id -u)` and comparison involving the value of $HOME which suffers
- from the typical shortcoming on that platform in which the same path may
- be represented two different ways depending upon its source (i.e. as a
- Windows path `C:/git-sdk-64/usr/src/git/foo` versus as a Unix path
- `/usr/src/git/foo`). Fix both problems and drop the !MINGW prerequisite
- from the macOS-specific test, thus allowing the test to run on Windows,
- as well.
+ the macOS-specific test fails on Windows due to non-portable use of
+ `$(id -u)` and comparison involving the value of $HOME.
+ In particular, on Windows, the value of getuid() called by the C code is
+ not guaranteed to be the same as `$(id -u)` invoked by the test. This is
+ because `git.exe` is a native Windows program, whereas the utility
+ programs run by the test script mostly utilize the MSYS2 runtime, which
+ emulates a POSIX-like environment. Since the purpose of the test is to
+ check that the input to the hook is well-formed, the actual user ID is
+ immaterial, thus we can work around the problem by making the the test
+ UID-agnostic.
+
+ As for comparison of $HOME, it suffers from the typical shortcoming on
+ Windows in which the same path may be represented two different ways
+ depending upon its source (i.e. as a Windows path
+ `C:/git-sdk-64/usr/src/git/foo` versus as a Unix path
+ `/usr/src/git/foo`).
+
+ Fix both problems and drop the !MINGW prerequisite from the
+ macOS-specific test, thus allowing the test to run on Windows, as well.
+
+ Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
## t/t7900-maintenance.sh ##
@@ t/t7900-maintenance.sh: test_expect_success 'start preserves existing schedule'
-test_expect_success !MINGW 'start and stop macOS maintenance' '
- uid=$(id -u) &&
+test_expect_success 'start and stop macOS maintenance' '
-+ uid=$(test-tool getuid) &&
+ # ensure $HOME can be compared against hook arguments on all platforms
+ pfx=$(cd "$HOME" && pwd) &&
write_script print-args <<-\EOF &&
- echo $* >>args
+- echo $* >>args
++ echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args
+ EOF
+
+ rm -f args &&
@@ t/t7900-maintenance.sh: test_expect_success !MINGW 'start and stop macOS maintenance' '
rm -f expect &&
for frequency in hourly daily weekly
@@ t/t7900-maintenance.sh: test_expect_success !MINGW 'start and stop macOS mainten
+ PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
test_xmllint "$PLIST" &&
grep schedule=$frequency "$PLIST" &&
- echo "bootout gui/$uid $PLIST" >>expect &&
+- echo "bootout gui/$uid $PLIST" >>expect &&
+- echo "bootstrap gui/$uid $PLIST" >>expect || return 1
++ echo "bootout gui/[UID] $PLIST" >>expect &&
++ echo "bootstrap gui/[UID] $PLIST" >>expect || return 1
+ done &&
+ test_cmp expect args &&
+
@@ t/t7900-maintenance.sh: test_expect_success !MINGW 'start and stop macOS maintenance' '
# stop does not unregister the repo
git config --get --global maintenance.repo "$(pwd)" &&
- printf "bootout gui/$uid $HOME/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
-+ printf "bootout gui/$uid $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
++ printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
hourly daily weekly >expect &&
test_cmp expect args &&
ls "$HOME/Library/LaunchAgents" >actual &&-- 2.29.2.576.ga3fc446d84