|
64 | 64 | _DIR = tempfile.mkdtemp()
|
65 | 65 | print(f"{_INFO_PREFIX}Using temporary directory: {_DIR}\033[0m")
|
66 | 66 |
|
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 | +) |
76 | 81 |
|
77 | 82 | _RUN_GAP = f"{_ARGS.gap_root}/gap -A -m 1g -T --cover {_DIR}/profile.gz"
|
78 | 83 |
|
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: |
80 | 90 | try:
|
81 | 91 | with subprocess.Popen(_RUN_GAP, stdin=pro1.stdout, shell=True) as pro2:
|
82 | 92 | pro2.wait()
|
|
0 commit comments