test: what a test leaves in its TMPDIR, kept when it fails, else gone
TestTemporaryDirectory runs a probe through RunTests that records the TMPDIR it was given and the directory fs::temp_directory_path() names, leaves a file there and exits as it is told. Two configurations each declare a passing test named probe, built differently so that the run does not refuse them, and the second also a failing one and one for another target, the host's own triple without its vendor and with x32 after it, which is never the host's and makes a second pass after the host's, and is skipped before it is built. The run takes one test at a time, so the failing one comes last in the host's pass, and it dates the run's directory, and a directory beside it that looks like one a run let go of, two minutes back before it fails, as a test that ran that long leaves them. Each test's fs::temp_directory_path() is the TMPDIR it was given: <run>/<name>, in a directory made for the run in the temp directory, and probe-2 for the second probe. What the passing tests left is removed; what the failing one left is kept, named in its output and its log, and so is the run's directory. A second run gets a directory of its own, removes it since every test passed, and leaves the first run's alone; a third, once that one is dated past the minute, removes it. The other target's pass makes no directory of its own: the one dated back beside the run's is still there when the run ends. A fourth run, whose pass for the other target throws, as one does where CRAFTER_BUILD_RUNNER_ names that target's runner wrong, keeps what its first pass kept. The runs make their directories in a temp directory the test makes for them and names with TMPDIR. The test removes only its own scratch directory, which holds that one, and the fixture's bin/ and build/, and dates a directory a probe reports only when it is a run's directory in that temp directory. HeadlessCompositor checks that a test that sets wayland and is given a TMPDIR runs with both: the TMPDIR it is given and its compositor's display alone, and that one under `host` and given a TMPDIR has it beside the session's display. Two failing tests of one name each have a log of their own, twin.log and twin-2.log, that says where what each left is kept. RunSingleTestExit runs a script whose path has an '=' in it, given a TMPDIR, which has to run and whose exit decides the outcome. Without TMPDIR on the test's command, 13 of TestTemporaryDirectory's checks fail; with a test's log named after the test alone, the two on the logs of the tests of one name do; without the date a kept directory gets as it is let go of, the one on the second run leaving the first run's alone does; with a directory of its own for a later pass, beside the run's, the one on the other target's pass does; and with the directory kept only once RunTests returns, the one on the fourth run does. With the test's own words as env's command, the two of RunSingleTestExit on the script whose path has an '=' fail.
This commit is contained in:
parent
93f1c8d9b9
commit
ab8935826d
5 changed files with 326 additions and 3 deletions
|
|
@ -29,7 +29,8 @@ using namespace std::chrono_literals;
|
|||
// leaves goes the next time one is made. A test that does not set it, or a
|
||||
// run that names `host`, keeps the session's display. A test with no time
|
||||
// limit gives its compositor none, and one whose binary's path holds an '='
|
||||
// runs as any other.
|
||||
// runs as any other. One that is given a TMPDIR as well, as RunTests gives
|
||||
// every test one, runs with both.
|
||||
//
|
||||
// This binary plays every part. Without arguments it is the driver; the
|
||||
// harness starts it again as the compositor, which listens on a wayland-7
|
||||
|
|
@ -63,8 +64,8 @@ namespace {
|
|||
return value != nullptr ? std::string(value) : std::string(Unset);
|
||||
}
|
||||
|
||||
// The variables of a Wayland session.
|
||||
constexpr std::array<std::string_view, 4> SessionVariables = { "WAYLAND_DISPLAY", "WAYLAND_SOCKET", "DISPLAY", "XDG_RUNTIME_DIR" };
|
||||
// The variables of a Wayland session, and the TMPDIR a test is given.
|
||||
constexpr std::array<std::string_view, 5> SessionVariables = { "WAYLAND_DISPLAY", "WAYLAND_SOCKET", "DISPLAY", "XDG_RUNTIME_DIR", "TMPDIR" };
|
||||
|
||||
void WriteFile(const fs::path& file, std::string_view content) {
|
||||
std::ofstream(file, std::ios::binary) << content;
|
||||
|
|
@ -360,6 +361,31 @@ int main(int argc, char* argv[]) {
|
|||
Check(!directory.empty() && !fs::exists(directory), "which is removed afterwards");
|
||||
}
|
||||
|
||||
// A test that sets wayland and is given a TMPDIR: the env prefix takes
|
||||
// the TMPDIR beside what it unsets and sets for the display.
|
||||
{
|
||||
const fs::path state = stateDir("tmpdir");
|
||||
const fs::path given = stateDir("tmpdir-given");
|
||||
const TestResult r = RunSingleTest(MakeTest(true, "--client", state), self, 10s, FakeCompositorCommand(self, state), given);
|
||||
Check(r.outcome == TestOutcome::Pass, std::format("a test that sets wayland and is given a TMPDIR passes: {}", r.output));
|
||||
std::map<std::string, std::string> client = ReadEnvironment(state / "client.env");
|
||||
Check(client["TMPDIR"] == given.string(), std::format("and runs with that TMPDIR: {}", client["TMPDIR"]));
|
||||
Check(client["WAYLAND_DISPLAY"] == ReadFile(state / "compositor.listening") && client["DISPLAY"] == Unset && client["WAYLAND_SOCKET"] == Unset,
|
||||
std::format("and with its compositor's display alone: {}", client["WAYLAND_DISPLAY"]));
|
||||
}
|
||||
|
||||
// Under `host`, a test given a TMPDIR runs with it, beside the
|
||||
// session's display.
|
||||
{
|
||||
const fs::path state = stateDir("host-tmpdir");
|
||||
const fs::path given = stateDir("host-tmpdir-given");
|
||||
const TestResult r = RunSingleTest(MakeTest(true, "--env", state), self, 10s, "host", given);
|
||||
std::map<std::string, std::string> client = ReadEnvironment(state / "client.env");
|
||||
Check(r.outcome == TestOutcome::Pass && client["TMPDIR"] == given.string(), std::format("under `host` a test given a TMPDIR runs with it: {}", client["TMPDIR"]));
|
||||
Check(client["WAYLAND_DISPLAY"] == "crafter-build-session-display" && client["DISPLAY"] == ":4242" && client["WAYLAND_SOCKET"] == "4243",
|
||||
"and with the session's display");
|
||||
}
|
||||
|
||||
{
|
||||
const fs::path state = stateDir("without");
|
||||
const TestResult r = RunSingleTest(MakeTest(false, "--env", state), self, 10s, FakeCompositorCommand(self, state));
|
||||
|
|
|
|||
Loading…
Reference in a new issue