From 85a0c1c59f06b4102109bbb6622ae69b0157df9a Mon Sep 17 00:00:00 2001 From: Daniel Buckmaster Date: Sat, 2 Aug 2014 10:14:08 +1000 Subject: [PATCH] Allow test flags to be specified, so we don't need TEST_STRESS. --- Engine/source/testing/unitTesting.cpp | 36 ++++++++++++++++----------- Engine/source/testing/unitTesting.h | 10 -------- Templates/Empty/game/runTests.cs | 2 +- Templates/Full/game/runTests.cs | 2 +- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Engine/source/testing/unitTesting.cpp b/Engine/source/testing/unitTesting.cpp index d9304e5b3..bf4a2bc0a 100644 --- a/Engine/source/testing/unitTesting.cpp +++ b/Engine/source/testing/unitTesting.cpp @@ -69,23 +69,30 @@ class TorqueUnitTestListener : public ::testing::EmptyTestEventListener } }; -DefineConsoleFunction( runAllUnitTests, int, (bool includeStressTests), (false), - "Runs all engine unit tests. Some tests are marked as 'stress' tests which do " - "not necessarily check correctness, just performance or possible nondeterministic " - "glitches. These tests can take some time, so they are not included unless " - "specified.\n\n" - "@param includeStressTests Run stress tests as well as unit tests. Default is false." ) +DefineConsoleFunction( runAllUnitTests, int, (const char* testSpecs), (""), + "Runs engine unit tests. Some tests are marked as 'stress' tests which do not " + "necessarily check correctness, just performance or possible nondeterministic " + "glitches. There may also be interactive or networking tests which may be " + "excluded by using the testSpecs argument.\n" + "This function should only be called once per executable run, because of " + "googletest's design.\n\n" + + "@param testSpecs A space-sepatated list of filters for test cases. " + "See https://code.google.com/p/googletest/wiki/AdvancedGuide#Running_a_Subset_of_the_Tests " + "for a description of the flag format.") { S32 testArgc = 0; char** testArgv = NULL; - if ( includeStressTests ) + if ( dStrlen( testSpecs ) > 0 ) { - // Yes, I never free this memory, because it seems to be mangled by gtest. - // Also it's a negligible space leak that will only occur once. + String specs(testSpecs); + specs.replace(' ', ':'); + specs.insert(0, "--gtest_filter="); + testArgc = 2; testArgv = new char*[2]; - testArgv[0] = new char( '\0' ); - testArgv[1] = new char[26]; - dStrcpy( testArgv[1], "--gtest_filter=-*Stress.*" ); + testArgv[0] = NULL; // Program name is unused by googletest. + testArgv[1] = new char[specs.length()+1]; + dStrcpy(testArgv[1], specs); } // Initialize Google Test. @@ -108,11 +115,10 @@ DefineConsoleFunction( runAllUnitTests, int, (bool includeStressTests), (false), // Add the Torque unit test listener. listeners.Append( new TorqueUnitTestListener ); + // Perform googletest run. Con::printf( "\nUnit Tests Starting...\n" ); - const S32 result = RUN_ALL_TESTS(); - - Con::printf( "\n... Unit Tests Ended.\n" ); + Con::printf( "... Unit Tests Ended.\n" ); return result; } diff --git a/Engine/source/testing/unitTesting.h b/Engine/source/testing/unitTesting.h index 5db45d775..158c3e034 100644 --- a/Engine/source/testing/unitTesting.h +++ b/Engine/source/testing/unitTesting.h @@ -38,16 +38,6 @@ GTEST_TEST_(test_fixture, test_name, test_fixture##Fixture, \ ::testing::internal::GetTypeId()) -/// Define a stress test. The test name is suffixed with Stress, so it will be -/// excluded from normal unit test runs. -#define TEST_STRESS(test_case_name, test_name)\ - TEST(test_case_name##Stress, test_name) - -/// Define a stress test with a fixture. -#define TEST_STRESS_FIX(test_fixture, test_name)\ - GTEST_TEST_(test_fixture##Stress, test_name, test_fixture##Fixture, \ - ::testing::internal::GetTypeId()) - #endif // TORQUE_TESTS_ENABLED #endif // _UNIT_TESTING_H_ diff --git a/Templates/Empty/game/runTests.cs b/Templates/Empty/game/runTests.cs index e44d2fbd4..b6d903ff0 100644 --- a/Templates/Empty/game/runTests.cs +++ b/Templates/Empty/game/runTests.cs @@ -1,5 +1,5 @@ setLogMode(2); $Con::LogBufferEnabled = false; $Testing::CheckMemoryLeaks = false; -runAllUnitTests(); +runAllUnitTests("-*.Stress*"); quit(); diff --git a/Templates/Full/game/runTests.cs b/Templates/Full/game/runTests.cs index e44d2fbd4..b6d903ff0 100644 --- a/Templates/Full/game/runTests.cs +++ b/Templates/Full/game/runTests.cs @@ -1,5 +1,5 @@ setLogMode(2); $Con::LogBufferEnabled = false; $Testing::CheckMemoryLeaks = false; -runAllUnitTests(); +runAllUnitTests("-*.Stress*"); quit();