Runner generation using generate_test_runner.rb does not work with fixtures. · Issue #789 · ThrowTheSwitch/Unity · GitHub
Skip to content

Runner generation using generate_test_runner.rb does not work with fixtures. #789

Open

Description

@twbje

We are using fixtures, but unfortunately the runner generation using generate_test_runner.rb is not working anymore. It simply does not find any test. This seems to be due to the regular expressions, that are used to find tests in the code. So e.g.

TEST(PassiveTimer, can_detect_expired_timers) {

is not detected as a test, unless you manually add a line

void TEST_PassiveTimer_can_detect_expired_timers_(void);

as well. This is actually the preprocessor macro expansion, the TEST macro does perform. So far I could fix it locally by adding an additional replacement in the find_tests method UnityTestRunnerGenerator class:

  # resolve fixtures if found
  line = line.gsub(/TEST\s*\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\s*,\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)/, 'void ' + @options[:test_prefix] + '\1_\2_(void)')

The line above simply perfoms the same expansion, the preprocessor would do anyway. Is this the right approach? Or am I using it totally wrong?

Activity

  1. Letme commented on Jun 25, 2025

    @Letme
    Contributor

    TEST(PassiveTimer, can_detect_expired_timers) is not a valid function name. Where did you get this TEST macro as requirement? Just simply take the example test as your template and write functions as normal C functions, except that it should have test_ to be picked up as test case by scripting.

    https://github.com/ThrowTheSwitch/Unity/blob/master/examples/example_4/test/TestProductionCode.c

    So in your case

    void test_PassiveTimer_can_detect_expired_timers_(void)
    {
        Write your test code here with TEST_ASSERT...
    }
    
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