Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IGNORE_TEST and IGNORE_TEST_F macros #47

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

stefano-p
Copy link
Contributor

Add IGNORE_TEST and IGNORE_TEST_F macros 🚀

This feature allows developers to temporarily disable specific tests without removing them from the codebase. This is particularly useful when:

  • Working on experimental features
  • Dealing with temporarily broken tests
  • Handling environment-dependent tests
  • Managing long-running tests during development

New Macros ✨

Two new macros have been added:

  • IGNORE_TEST() - for regular test cases
  • IGNORE_TEST_F() - for fixture-based tests

Usage Example 💡

#include <tau/tau.h>

// Regular test case that will be executed
TEST(MathSuite, Addition) {
    int result = 2 + 2;
    CHECK_EQ(result, 4);
}

// This test will be ignored but remains in the codebase
IGNORE_TEST(MathSuite, ComplexCalculation) {
    int result = perform_complex_calculation();
    CHECK_EQ(result, 42);
}

// Setup for fixture
TEST_F_SETUP(DatabaseFixture) {
    tau->db = database_connect();
}

// Teardown for fixture
TEST_F_TEARDOWN(DatabaseFixture) {
    database_disconnect(tau->db);
}

// This fixture test will be ignored but setup/teardown are preserved
IGNORE_TEST_F(DatabaseFixture, SlowQuery) {
    bool query_result = database_execute_heavy_query(tau->db);
    CHECK_TRUE(query_result);
}

// This fixture test will run normally
TEST_F(DatabaseFixture, QuickQuery) {
    bool query_result = database_execute_simple_query(tau->db);
    CHECK_TRUE(query_result);
}

TAU_MAIN()

Output Example 🖥️

[==========] Running 4 test suites.
[ RUN      ] MathSuite.Addition
[       OK ] MathSuite.Addition (0.001s)
[ IGNORED  ] MathSuite.ComplexCalculation
[ RUN      ] DatabaseFixture.QuickQuery
[       OK ] DatabaseFixture.QuickQuery (0.003s)
[ IGNORED  ] DatabaseFixture.SlowQuery
[==========] 2 test suites ran
[  PASSED  ] 2 suites

Summary:
    Total test suites:          4
    Total suites run:           2
    Total warnings generated:   0
    Total suites skipped:       2
    Total suites failed:        0

Implementation Details 🔧

  • Added ignored flag to test suite structure
  • Extended test registration to support ignored state
  • Modified test runner to handle ignored tests
  • Maintained existing color coding (yellow for ignored tests)
  • Updated test statistics to properly count ignored tests

Backwards Compatibility ⚡

This change is fully backwards compatible:

  • Existing tests continue to work as before
  • No changes required to existing test code
  • No changes to command-line interface

Testing 🧪

The implementation has been tested with:

  • Regular test cases
  • Fixture-based tests
  • Mixed ignored and regular tests
  • Various output formats (colored, non-colored)

Add support for skipping test execution through two new macros:
- IGNORE_TEST: for ignoring regular test cases
- IGNORE_TEST_F: for ignoring fixture-based tests

Features:
- Tests marked with these macros are registered but not executed
- Ignored tests are reported with yellow "[IGNORED]" status
- Ignored tests count towards skipped tests in final summary
- Maintains existing test fixtures functionality (setup/teardown)

Implementation:
- Extended tauTestSuiteStruct with 'ignored' flag
- Added isCurrentTestIgnored tracking variable
- Modified tauRunTests to handle ignored tests
- Updated TAU_ONLY_GLOBALS to include new state variable
@stefano-p stefano-p requested a review from jasmcaus as a code owner November 11, 2024 13:52
@jasmcaus jasmcaus merged commit 909b422 into jasmcaus:dev Nov 12, 2024
5 of 87 checks passed
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.

2 participants