1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
import os
from e3.testsuite.driver.classic import TestAbortWithError
from e3.testsuite.driver.diff import DiffTestDriver, OutputRefiner, Substitute
from drivers import gprbuild
class ToLower(OutputRefiner):
"""Output refiner to switch to lower case."""
def refine(self, output):
return output.lower()
class BuildRunDiffDriver(DiffTestDriver):
"""Build and run a project using GNATCOLL.
Put project and source files in the test directory, in particular
"test.gpr" in the root directory, whose compilation is supposed to create a
"test" executable in the same directory.
This test driver builds the "test.gpr" project file and then executes the
"test" shell script (test.sh). This script should run the executable that
was built. It can either pass through all output to stdout, or stdout can
be piped to files to allow for post processesing first. The test succeeds
if all of the following items are true:
* the compilation is successful;
* the "test" program completes with status code 0.
* the contents of test.out/regex_test.out match the stdout of the test.sh
"""
@property
def baseline(self):
# Allow a missing test.out or regex_test.out -- treat as empty
test_out = self.test_dir("test.out")
regex_test_out = self.test_dir("regex_test.out")
regex = False
if os.path.exists(test_out):
with open(test_out, encoding=self.default_encoding) as f:
baseline = f.read()
elif os.path.exists(regex_test_out):
with open(regex_test_out, encoding=self.default_encoding) as f:
baseline = f.read()
regex = True
else:
baseline = ""
test_out = None
return (test_out, baseline, regex)
@property
def output_refiners(self):
result = super().output_refiners
if self.test_env.get("fold_casing", False):
result.append(ToLower())
if self.test_env.get("canonicalize_backslashes", False):
result.append(Substitute("\\", "/"))
return result
def run(self):
# Build the test project
if self.test_env.get('no-coverage'):
gpr_project_path = self.env.gnatcoll_debug_gpr_dir
else:
gpr_project_path = self.env.gnatcoll_gpr_dir
gprbuild(
self,
project_file="test.gpr",
gcov=self.env.gcov,
gpr_project_path=gpr_project_path
)
# Run the test program
p = self.shell(["bash", "test.sh"], catch_error=False)
if p.status:
self.output += ">>>program returned status code {}\n".format(
p.status
)
|