changeset 51945:4ee2505f9f65

tests: stabilize `test-merge-partial-tool.t` on Windows The test was previously failing because it was opening the shell scripts being used as an executable in a text editor, and problems cascaded from there.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 02 Oct 2024 16:34:33 -0400
parents 2eeca9a8f4a7
children d7e61891ab5a
files tests/test-merge-partial-tool.t
diffstat 1 files changed, 42 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-merge-partial-tool.t	Wed Oct 02 11:43:22 2024 -0400
+++ b/tests/test-merge-partial-tool.t	Wed Oct 02 16:34:33 2024 -0400
@@ -5,8 +5,8 @@
   $ cat >> "$TESTTMP/head.sh" <<'EOF'
   > #!/bin/sh
   > for f in "$@"; do
-  >   head -5 $f > tmp
-  >   mv -f tmp $f
+  >   head -5 "$f" > tmp
+  >   mv -f tmp "$f"
   > done
   > EOF
   $ chmod +x "$TESTTMP/head.sh"
@@ -14,8 +14,8 @@
   $ cat >> "$TESTTMP/tail.sh" <<'EOF'
   > #!/bin/sh
   > for f in "$@"; do
-  >   tail -5 $f > tmp
-  >   mv -f tmp $f
+  >   tail -5 "$f" > tmp
+  >   mv -f tmp "$f"
   > done
   > EOF
   $ chmod +x "$TESTTMP/tail.sh"
@@ -30,6 +30,27 @@
   > tail.order=1
   > EOF
 
+On Windows, running $TESTTMP/script.sh will open script.sh in an editor, if
+that's what the configured file association is.  The code shell quotes the
+*.executable value, so we can't set it to `sh $TESTTMP/script.sh`, because it
+tries to run that as the executable.  As a workaround, generate a bat file that
+invokes `sh script.sh`, and passes the args along.
+
+#if windows
+  $ cat >> "$TESTTMP/head.bat" <<'EOF'
+  > @echo off
+  > sh "%TESTTMP%/head.sh" %*
+  > EOF
+
+  $ cat >> "$TESTTMP/tail.bat" <<'EOF'
+  > @echo off
+  > sh "%TESTTMP%/tail.sh" %*
+  > EOF
+
+  $ sed 's/head.sh/head.bat/g' "${HGRCPATH}" > "${HGRCPATH}.tmp"
+  $ sed 's/tail.sh/tail.bat/g' "${HGRCPATH}.tmp" > "${HGRCPATH}"
+#endif
+
   $ make_commit() {
   >   echo "$@" | xargs -n1 > file
   >   hg add file 2> /dev/null
@@ -294,6 +315,23 @@
   > [partial-merge-tools]
   > log-args.executable=$TESTTMP/log-args.sh
   > EOF
+
+On Windows, running $TESTTMP/script.sh will open script.sh in an editor, if
+that's what the configured file association is.  The code shell quotes the
+*.executable value, so we can't set it to `sh $TESTTMP/script.sh`, because it
+tries to run that as the executable.  As a workaround, generate a bat file that
+invokes `sh script.sh`, and passes the args along.
+
+#if windows
+  $ cat >> "$TESTTMP/log-args.bat" <<'EOF'
+  > @echo off
+  > sh "%TESTTMP%/log-args.sh" %*
+  > EOF
+
+  $ sed 's/log-args.sh/log-args.bat/g' "$HGRCPATH" > "${HGRCPATH}.tmp"
+  $ mv "${HGRCPATH}.tmp" "${HGRCPATH}"
+#endif
+
   $ hg up -C 2
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg merge 1