|
6 | 6 | ========================================================================= */ |
7 | 7 |
|
8 | 8 | #include "unity.h" |
| 9 | +#ifdef UNITY_USE_COMMAND_LINE_ARGS |
| 10 | +#include "unity_internals.h" |
| 11 | +#include <stdlib.h> |
| 12 | +#endif |
9 | 13 | #define TEST_INSTANCES |
10 | 14 | #include "self_assessment_utils.h" |
11 | 15 |
|
@@ -194,6 +198,67 @@ void testFail(void) |
194 | 198 | VERIFY_FAILS_END |
195 | 199 | } |
196 | 200 |
|
| 201 | +#ifdef UNITY_USE_COMMAND_LINE_ARGS |
| 202 | +static void UnitySetTestbridgeFilter(const char* value) |
| 203 | +{ |
| 204 | +#if defined(_WIN32) || defined(_MSC_VER) |
| 205 | + if (value) |
| 206 | + { |
| 207 | + _putenv_s("TESTBRIDGE_TEST_ONLY", value); |
| 208 | + } |
| 209 | + else |
| 210 | + { |
| 211 | + _putenv_s("TESTBRIDGE_TEST_ONLY", ""); |
| 212 | + } |
| 213 | +#else |
| 214 | + if (value) |
| 215 | + { |
| 216 | + setenv("TESTBRIDGE_TEST_ONLY", value, 1); |
| 217 | + } |
| 218 | + else |
| 219 | + { |
| 220 | + unsetenv("TESTBRIDGE_TEST_ONLY"); |
| 221 | + } |
| 222 | +#endif |
| 223 | +} |
| 224 | + |
| 225 | +static void UnitySetTestContext(const char* testfile, const char* testname) |
| 226 | +{ |
| 227 | + Unity.TestFile = testfile; |
| 228 | + Unity.CurrentTestName = testname; |
| 229 | +} |
| 230 | + |
| 231 | +void testUnityParseOptionsUsesTestbridgeFilter(void) |
| 232 | +{ |
| 233 | + char* argv[] = { (char*)"prog", NULL }; |
| 234 | + |
| 235 | + UnitySetTestbridgeFilter("test_my_function"); |
| 236 | + UnityParseOptions(1, argv); |
| 237 | + |
| 238 | + UnitySetTestContext("file.c", "test_my_function"); |
| 239 | + TEST_ASSERT_TRUE(UnityTestMatches()); |
| 240 | + UnitySetTestContext("file.c", "other"); |
| 241 | + TEST_ASSERT_FALSE(UnityTestMatches()); |
| 242 | + |
| 243 | + UnitySetTestbridgeFilter(NULL); |
| 244 | +} |
| 245 | + |
| 246 | +void testUnityParseOptionsArgsOverrideTestbridgeFilter(void) |
| 247 | +{ |
| 248 | + char* argv[] = { (char*)"prog", (char*)"-n", (char*)"other", NULL }; |
| 249 | + |
| 250 | + UnitySetTestbridgeFilter("test_my_function"); |
| 251 | + UnityParseOptions(3, argv); |
| 252 | + |
| 253 | + UnitySetTestContext("file.c", "other"); |
| 254 | + TEST_ASSERT_TRUE(UnityTestMatches()); |
| 255 | + UnitySetTestContext("file.c", "test_my_function"); |
| 256 | + TEST_ASSERT_FALSE(UnityTestMatches()); |
| 257 | + |
| 258 | + UnitySetTestbridgeFilter(NULL); |
| 259 | +} |
| 260 | +#endif |
| 261 | + |
197 | 262 | void testIsNull(void) |
198 | 263 | { |
199 | 264 | char* ptr1 = NULL; |
|
0 commit comments