xaizek / stic (License: MIT) (since 2018-12-07)
Simple Tests In C with optional automatic test registration in C.
Commit b26fea59ef8f4f6dc85fb67ebe0ec8b857eb2197

Don't run {setup,teardown}_once when no tests did

This might be the case when there is a test filter.

Author: xaizek
Author date (UTC): 2018-07-15 18:49
Committer: xaizek
Commit date (UTC): 2018-07-15 21:24
Tree: 83560137d34e642844ae302e38bee3eb09f137bb
Parents: d8af85e89f42db50f80d204e092bb7888fd9bf8c
Signing key: 99DC5E4DB05F6BE2
File Lines added Lines deleted
src/stic.h 17 9

File src/stic.h changed (mode: 100644) (index 61f18f1..6f6a1f8)
... ... static void stic_fixture(void)
306 306 extern stic_void_void stic_current_test; extern stic_void_void stic_current_test;
307 307
308 308 size_t i; size_t i;
309 int has_any_tests = 0;
309 310
310 311 const char *fixture_name = stic_get_fixture_name(); const char *fixture_name = stic_get_fixture_name();
311 312 if(fixture_name == NULL || !stic_should_run(fixture_name, NULL)) if(fixture_name == NULL || !stic_should_run(fixture_name, NULL))
 
... ... static void stic_fixture(void)
318 319 fixture_setup(stic_setup_func); fixture_setup(stic_setup_func);
319 320 fixture_teardown(stic_teardown_func); fixture_teardown(stic_teardown_func);
320 321
321 if(stic_setup_once_func != NULL)
322 {
323 stic_current_test_name = "<setup once>";
324 stic_current_test = stic_setup_once_func;
325 stic_setup_once_func();
326 }
327
328 322 for(i = 0; i < STIC_ARRAY_LEN(stic_test_data); ++i) for(i = 0; i < STIC_ARRAY_LEN(stic_test_data); ++i)
329 323 { {
330 324 struct stic_test_data *td = *stic_test_data[i]; struct stic_test_data *td = *stic_test_data[i];
331 325 if(td == NULL) continue; if(td == NULL) continue;
326 if(!stic_should_run(fixture_name, td->n)) continue;
327
328 /* Since predicates can rely on setup once, check predicates after
329 * invoking setup once. */
330 if(!has_any_tests)
331 {
332 has_any_tests = 1;
333 if(stic_setup_once_func != NULL)
334 {
335 stic_current_test_name = "<setup once>";
336 stic_current_test = stic_setup_once_func;
337 stic_setup_once_func();
338 }
339 }
340
332 341 if(td->p != NULL && !td->p()) if(td->p != NULL && !td->p())
333 342 { {
334 343 stic_skip_test(fixture_name, td->n); stic_skip_test(fixture_name, td->n);
335 344 continue; continue;
336 345 } }
337 if(!stic_should_run(fixture_name, td->n)) continue;
338 346
339 347 stic_current_test_name = td->n; stic_current_test_name = td->n;
340 348 stic_current_test = td->t; stic_current_test = td->t;
 
... ... static void stic_fixture(void)
346 354 stic_run_test(fixture_name, td->n); stic_run_test(fixture_name, td->n);
347 355 } }
348 356
349 if(stic_teardown_once_func != NULL)
357 if(has_any_tests && stic_teardown_once_func != NULL)
350 358 { {
351 359 stic_current_test_name = "<teardown once>"; stic_current_test_name = "<teardown once>";
352 360 stic_current_test = stic_teardown_once_func; stic_current_test = stic_teardown_once_func;
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/stic

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/stic

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master