Procházet zdrojové kódy

Allow test flags to be specified, so we don't need TEST_STRESS.

Daniel Buckmaster před 11 roky
rodič
revize
85a0c1c59f

+ 21 - 15
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;
 }

+ 0 - 10
Engine/source/testing/unitTesting.h

@@ -38,16 +38,6 @@
    GTEST_TEST_(test_fixture, test_name, test_fixture##Fixture, \
    ::testing::internal::GetTypeId<test_fixture##Fixture>())
 
-/// 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<test_fixture##Fixture>())
-
 #endif // TORQUE_TESTS_ENABLED
 
 #endif // _UNIT_TESTING_H_

+ 1 - 1
Templates/Empty/game/runTests.cs

@@ -1,5 +1,5 @@
 setLogMode(2);
 $Con::LogBufferEnabled = false;
 $Testing::CheckMemoryLeaks = false;
-runAllUnitTests();
+runAllUnitTests("-*.Stress*");
 quit();

+ 1 - 1
Templates/Full/game/runTests.cs

@@ -1,5 +1,5 @@
 setLogMode(2);
 $Con::LogBufferEnabled = false;
 $Testing::CheckMemoryLeaks = false;
-runAllUnitTests();
+runAllUnitTests("-*.Stress*");
 quit();