Skip to content

env: a way for a program to keep variables from the programs it starts (mtest protocol P2.2) #29

Open

Description

@ZheFeng7110

Need

The mtest protocol (mcpp docs/specs/test.md, SPEC-017, P2.2) forbids a program that speaks it to pass the protocol variables (MTEST_PROTOCOL, MTEST_MODE, MTEST_REPORT, MTEST_SELECT, ...) to the programs it starts, so that a test program a test starts is not taken for the runner's. mcpp-community/mtest#29 found that the doctest adapter breaks it: a case sees MTEST_REPORT, and a doctest program the case starts appends its events to the parent's report. The GoogleTest adapter and the library (mcpplibs.mtest) read the variables the same way and do not remove them; the library strips them only from the commands e2e::run starts.

A test framework does not control how a case starts a program: os::process::spawn, std::system, posix_spawn, a library's own process class. The variables have to be gone from what each of these inherits once the framework has read them, before any case runs.

What mcpplibs.os states now

  • src/env.cppm: "a started program's environment is stated when it is started (process::spawn_options), and this program's own is not modified --- part 2 §6.4."
  • openkal include/openkal/env.h: "THE SET DOES NOT CHANGE while the program runs."
  • process::spawn_options::env: "a value sets the variable and nothing removes it", so one spawn can leave a name out ({"MTEST_REPORT", std::nullopt}), which is what e2e::run does.

So a caller can strip the names from each program it starts itself, but the library has no way for a program to say "the programs I start, by any means, do not get these names", and an env::unset on the program's own environment would contradict both statements above (and, in an ok image, leave env::get and process::spawn still seeing the variables).

Possible shapes (for the maintainers to decide)

  1. env::withhold(names): names process::spawn leaves out of every program it starts unless spawn_options::env sets them; openkal's set is unchanged. This covers programs started through mcpplibs.os only.
  2. A host-side removal from the C library's environment (what std::system, posix_spawn and std::getenv see), chosen at run time in src/posix / src/windows (unsetenv, _putenv_s(name, "")), stated as not changing openkal's set; with or without 1.
  3. None of these: such removal is out of the library's scope.

Meanwhile

mtest's adapters remove the variables from the C library's environment themselves (they are header-based and outside the rule that mtest's engine and library reach the system only through mcpplibs.os). The library mcpplibs.mtest keeps its current behaviour until this is decided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions