Skip to content

Commit fa9462c

Browse files
reiniscirponsjames-d-mitchell
authored andcommitted
Fix code coverage script on certain platforms.
1 parent ec0efb0 commit fa9462c

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

etc/code-coverage-test-gap.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,29 @@
6464
_DIR = tempfile.mkdtemp()
6565
print(f"{_INFO_PREFIX}Using temporary directory: {_DIR}\033[0m")
6666

67-
_COMMANDS = 'echo "'
68-
_COMMANDS += "".join(rf"Test(\"{f}\");;\n" for f in _ARGS.tstfiles)
69-
_COMMANDS += rf"""UncoverageLineByLine();;
70-
LoadPackage(\"profiling\", false);;
71-
filesdir := \"{getcwd()}{_PROFILE_DIR}\";;\n"""
72-
73-
_COMMANDS += rf"outdir := \"{_DIR}\";;\n"
74-
_COMMANDS += rf"x := ReadLineByLineProfile(\"{_DIR}/profile.gz\");;\n"
75-
_COMMANDS += 'OutputAnnotatedCodeCoverageFiles(x, filesdir, outdir);"'
67+
# Raw strings are used to correctly escape quotes " for input in another
68+
# process, i.e. we explicitly need the string to contain \" instead of just "
69+
# for each quote.
70+
_GAP_COMMANDS = [rf"Test(\"{f}\");;" for f in _ARGS.tstfiles]
71+
_GAP_COMMANDS.extend(
72+
[
73+
"UncoverageLineByLine();;",
74+
rf"LoadPackage(\"profiling\", false);;",
75+
rf"filesdir := \"{getcwd()}{_PROFILE_DIR}\";;",
76+
rf"outdir := \"{_DIR}\";;",
77+
rf"x := ReadLineByLineProfile(\"{_DIR}/profile.gz\");;",
78+
"OutputAnnotatedCodeCoverageFiles(x, filesdir, outdir);",
79+
]
80+
)
7681

7782
_RUN_GAP = f"{_ARGS.gap_root}/gap -A -m 1g -T --cover {_DIR}/profile.gz"
7883

79-
with subprocess.Popen(_COMMANDS, stdout=subprocess.PIPE, shell=True) as pro1:
84+
# Commands are stored in a list and then joined with "\n" since including
85+
# newlines directly in raw strings cause issues when piping into GAP on some
86+
# platforms.
87+
with subprocess.Popen(
88+
'echo "' + "\n".join(_GAP_COMMANDS) + '"', stdout=subprocess.PIPE, shell=True
89+
) as pro1:
8090
try:
8191
with subprocess.Popen(_RUN_GAP, stdin=pro1.stdout, shell=True) as pro2:
8292
pro2.wait()

0 commit comments

Comments
 (0)