Skip to content

RegTest: can you include another file from a test file? #25

Open

Description

@stormi

I would like to create a shared macros file for all my tests to include. Mostly macros that bring the game to the wanted state before the actual test starts.

For example, I want to add a test which specifically performs various checks on a given object. The object is in a room that you only reach after a few tens of commands, that I want to avoid repeating, for maintainability's sake. I could just include the macro from another file where it's defined once and for all, this would be very convenient.

I haven't found such a feature in the documentation, but maybe there's already a way? If not, please consider this a feature suggestion 🙏 .

Activity

  1. erkyrath commented on Sep 7, 2025

    @erkyrath
    Owner

    Nope, there is no such feature at present. It's a reasonable suggestion. Possibly as

    >{include} TESTNAME::FILENAME
    

    However, it's not entirely trivial to implement, so I can't promise I'll pick it up soon.

    Thanks for the idea, though.

  2. stormi commented on Sep 8, 2025

    @stormi
    Author

    Just a way to include another file on top would already be very useful, and possibly easier to implement.

    ** include: FILENAME
    

    I would just include "lib" files that define reusable "macros" (tests that start with _) on top of my test files.

  3. erkyrath commented on Sep 9, 2025

    @erkyrath
    Owner

    Good point, thanks.

  4. stormi commented on Jul 26, 2026

    @stormi
    Author

    I've worked on an implementation and am currently testing it. Here's what the addition to the doc would say:


    A line beginning with "** include:" specifies a file to include at that point in the test file. The included file is parsed recursively; its tests, directives, and nested includes take effect as if the content were pasted inline. File paths are resolved relative to the directory of the file containing the ** include: directive. You can use multiple ** include: lines to include several files.

    Because included content is parsed inline, directives in included files follow the same rules as in the main file: ** game: overrides any prior value, ** precommand: appends to the precommand list, and so on. Test names must be unique across all files. A duplicate test name will cause an error. Circular includes (A includes B which includes A) are also an error.

    An included file can contain anything the main file can: top-level directives, test definitions, comments, and even more ** include: lines.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions