|
| 1 | +""" |
| 2 | +Check that gnatcov does not crash during elaboration when it fails to find |
| 3 | +itself in PATH. |
| 4 | +
|
| 5 | +This requires a fairly specific setup for both path lookup to work in the |
| 6 | +terminal, but not from gnatcov. So far we have managed to do it by |
| 7 | +- Being on a Windows system |
| 8 | +- Having the gnatcov executable being in a case-sensitive directory |
| 9 | +- Modifying the gnatcov.exe filename to change the case of the executable |
| 10 | + suffix |
| 11 | +- Invoking gnatcov without the executable suffix. |
| 12 | +
|
| 13 | +This test aims to re-create these conditions, and thus removes some stuff from |
| 14 | +the environment to make sure we have a the right conditions. |
| 15 | +""" |
| 16 | + |
| 17 | +import os |
| 18 | + |
| 19 | +from e3.os.fs import which |
| 20 | +from e3.fs import mkdir, cp |
| 21 | + |
| 22 | +from SUITE.context import thistest |
| 23 | +from SUITE.cutils import Wdir, contents_of |
| 24 | +from SUITE.tutils import run_and_log |
| 25 | + |
| 26 | + |
| 27 | +tmp = Wdir("tmp_") |
| 28 | + |
| 29 | +# Create an empty directory in which we'll change the case sensitivity and |
| 30 | +# butcher the gnatcov exec. |
| 31 | +gnatcov_install = os.path.abspath("fake_gnatcov_bin") |
| 32 | +mkdir(gnatcov_install) |
| 33 | + |
| 34 | +# Enable file sensitivity for the install dir. This needs to be done while the |
| 35 | +# directory is empty. |
| 36 | +run_and_log( |
| 37 | + ["fsutil.exe", "file", "setCaseSensitiveInfo", gnatcov_install, "enable"] |
| 38 | +) |
| 39 | + |
| 40 | +# Copy the gnatcov.exe program and change its executable suffix casing |
| 41 | +cp(which("gnatcov.exe"), os.path.join(gnatcov_install, "gnatcov.EXE")) |
| 42 | + |
| 43 | +# Run gnatcov without anything on the environment to make sure we don't pick up |
| 44 | +# the correctly installed gnatcov, not the GNATCOV_PREFIX env var which would |
| 45 | +# bypass the path lookup check. We also go through a cmd indirection to avoid |
| 46 | +# the path lookup that takes place in e3.os.process.Run. |
| 47 | +# |
| 48 | +# We also need gnatcov to be invoked without the exe prefix here as the os |
| 49 | +# search should work, but the command name for gnatcov will still not have |
| 50 | +# the exe suffix. |
| 51 | +crash_log = "xcov.log" |
| 52 | +p = run_and_log( |
| 53 | + ["cmd", "/c", "gnatcov"], |
| 54 | + env={"PATH": gnatcov_install}, |
| 55 | + output=crash_log, |
| 56 | + ignore_environ=True, |
| 57 | +) |
| 58 | + |
| 59 | +thistest.fail_if( |
| 60 | + p.status == 0, |
| 61 | + comment="gnatcov did not exit with a failure status", |
| 62 | +) |
| 63 | + |
| 64 | +thistest.fail_if_not_equal( |
| 65 | + what="Unexpected error message from gnatcov", |
| 66 | + expected="Could not locate the invoked gnatcov command: <empty string>." |
| 67 | + " If gnatcov is installed on a case sensitive filesystem or directory," |
| 68 | + " ensure the casing as the executable filename is used when invoking the" |
| 69 | + " program.", |
| 70 | + actual=contents_of(crash_log).strip(), |
| 71 | +) |
| 72 | + |
| 73 | +thistest.result() |
0 commit comments