Skip to content

Add ** include: directive for external file inclusion - #27

Open
stormi wants to merge 1 commit into
erkyrath:masterfrom
stormi:include-test-files
Open

Add ** include: directive for external file inclusion#27
stormi wants to merge 1 commit into
erkyrath:masterfrom
stormi:include-test-files

Conversation

@stormi

@stormi stormi commented Jul 26, 2026

Copy link
Copy Markdown

This implements #25


Add ** include: directive for external file inclusion

Add support for including another test file at a point in the current
test file with ** include: file.t

The included file is parsed recursively — its tests, directives, and
nested includes take effect as if pasted inline at the ** include:
line. Paths are resolved relative to the including file's directory.

Multiple ** include: lines are needed to include several files; each
line includes exactly one file.

- Circular include chains are detected and raise an error with the
  full cycle path (e.g. A -> B -> C -> A)
- Duplicate test names across files raise an error showing both
  source files
- All directives follow the same rules: ** game: overrides,
  ** precommand: appends, etc.

I have tested this on my own tests, with snippets that advance the game from one state to another, and others that move you to a given state from the beginning of the game.

$ ls tests/includes/
gue_to_parvis  parvis_to_chambre  to_chambre  to_parvis

Here's one that moves you from "parvis" to "chambre" :

$ cat tests/includes/parvis_to_chambre 
* _parvis_to_chambre
> prendre corde et bois
> attacher corde et bois
> jeter grappin sur herse
> tirer corde
> pousser la charrette
> monter sur la charrette
> monter
Dans la chambre

And another that moves you from the beginning of the game to "chambre", by including other snippets:

$ cat tests/includes/to_chambre 
** include: to_parvis
** include: parvis_to_chambre

* _to_chambre
>{include} _to_parvis
>{include} _parvis_to_chambre

In the real test files themselves, I include the file snippets that I need and either {include} the "tests" they define via ** precommand or directly in the tests, depending on the case.

Example (WIP test file):

$ cat tests/walkthrough.test
** include: includes/gue_to_parvis
** include: includes/parvis_to_chambre

* walkthrough direct
>{include}_gue_to_parvis
>{include}_parvis_to_chambre

> o
> n
Dans le cabinet de l'abbé
[...]

@stormi

stormi commented Jul 26, 2026

Copy link
Copy Markdown
Author

test_include.py

Here's a test file that I haven't committed because the plotex project has no test framework at the moment, but that can be used to verify that the implementation does what it claims it does.

Add support for including another test file at a point in the current
test file with ** include: file.t

The included file is parsed recursively — its tests, directives, and
nested includes take effect as if pasted inline at the ** include:
line. Paths are resolved relative to the including file's directory.

Multiple ** include: lines are needed to include several files; each
line includes exactly one file.

- Circular include chains are detected and raise an error with the
  full cycle path (e.g. A -> B -> C -> A)
- Duplicate test names across files raise an error showing both
  source files
- All directives follow the same rules: ** game: overrides,
  ** precommand: appends, etc.
@stormi
stormi force-pushed the include-test-files branch from 6a1f06c to da08273 Compare July 26, 2026 10:39
@stormi

stormi commented Jul 26, 2026

Copy link
Copy Markdown
Author

Last force-push: fixed stale commit message.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant