Skip to content

Conversation

@jjtolton
Copy link

@jjtolton jjtolton commented Oct 12, 2025

Summary

Adds test_setup/0 and test_teardown/0 functionality to the testing framework, allowing tests to initialize and clean up state before and after each test.

Changes

  • Add test_setup/0: Runs before each test
  • Add test_teardown/0: Runs after each test
  • Teardown guaranteed to run even if test fails or throws exception
  • Optional predicates - tests run normally if not defined
  • Module-aware: setup/teardown called with correct module context
  • Update documentation with setup/teardown usage examples

- Add test_setup/0: Runs before each test
- Add test_teardown/0: Runs after each test
- Teardown guaranteed to run even if test fails or throws exception
- Optional predicates - tests run normally if not defined
- Module-aware: setup/teardown called with correct module context
- Update documentation with setup/teardown usage examples
@constraintAutomaton
Copy link

constraintAutomaton commented Oct 12, 2025

It is related to #1, but I think it is different because here we are talking to setup and teardown before each test and not global ones.

Copy link
Owner

@bakaq bakaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there might be a more elegant way to do this, but this is general enough to be useful for a lot of situations.

Comment on lines +235 to +246
catch(
(
call_setup_(SetupGoal),
catch(
(call(Goal), call_teardown_(TeardownGoal)),
TestException,
(call_teardown_(TeardownGoal), throw(TestException))
)
),
SetupException,
throw(SetupException)
).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you use setup_call_cleanup/3 instead?

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.

3 participants