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

Make stic work when tests are defined with suite
I.e. when `TEST()` appear in the same file as `DEFINE_SUITE()` does.

Thanks to Ma_Sys.ma.
Author: xaizek
Author date (UTC): 2018-04-14 09:59
Committer name: xaizek
Committer date (UTC): 2018-04-20 13:10
Parent(s): 67bbc0a1a978d4608e31128057afbe3b6f41e59d
Signing key: 99DC5E4DB05F6BE2
Tree: 53771155cfd79a78a5140e5f167ae7597d8b3a8c
File Lines added Lines deleted
src/stic.h 23 16
File src/stic.h changed (mode: 100644) (index 63c7141..e4bc80e)
... ... struct stic_test_data
258 258 int main(int argc, char *argv[]) \ int main(int argc, char *argv[]) \
259 259 { \ { \
260 260 int r; \ int r; \
261 if(stic_setup_once_func != NULL) \
261 const int file_has_tests = (stic_get_fixture_name() != NULL); \
262 if(!file_has_tests && stic_setup_once_func != NULL) \
262 263 { \ { \
263 264 stic_setup_once_func(); \ stic_setup_once_func(); \
264 265 } \ } \
265 266 r = stic_testrunner(argc, argv, stic_suite, stic_setup_func, stic_teardown_func) == 0; \ r = stic_testrunner(argc, argv, stic_suite, stic_setup_func, stic_teardown_func) == 0; \
266 if(stic_teardown_once_func != NULL) \
267 if(!file_has_tests && stic_teardown_once_func != NULL) \
267 268 { \ { \
268 269 stic_teardown_once_func(); \ stic_teardown_once_func(); \
269 270 } \ } \
 
... ... static void (*stic_setup_once_func)(void);
282 283 static void (*stic_teardown_func)(void); static void (*stic_teardown_func)(void);
283 284 static void (*stic_teardown_once_func)(void); static void (*stic_teardown_once_func)(void);
284 285
286 static struct stic_test_data *const *const stic_test_data[] = {
287 TEST_DATA_STRUCTS_REF
288 };
289
290 static const char * stic_get_fixture_name(void)
291 {
292 size_t i;
293 for(i = 0U; i < STIC_ARRAY_LEN(stic_test_data); ++i)
294 {
295 if(*stic_test_data[i])
296 {
297 return (*stic_test_data[i])->f;
298 }
299 }
300 return NULL;
301 }
302
285 303 static void stic_fixture(void) static void stic_fixture(void)
286 304 { {
287 305 extern const char *stic_current_test_name; extern const char *stic_current_test_name;
288 306 extern stic_void_void stic_current_test; extern stic_void_void stic_current_test;
289 307
290 const char *fixture_name = NULL;
291 308 size_t i; size_t i;
292 static struct stic_test_data *const *const test_data[] = {
293 TEST_DATA_STRUCTS_REF
294 };
295 309
296 for(i = 0; i < STIC_ARRAY_LEN(test_data); ++i)
297 {
298 if(*test_data[i])
299 {
300 fixture_name = (*test_data[i])->f;
301 break;
302 }
303 }
310 const char *fixture_name = stic_get_fixture_name();
304 311 if(fixture_name == NULL) if(fixture_name == NULL)
305 312 { {
306 313 return; return;
 
... ... static void stic_fixture(void)
318 325 stic_setup_once_func(); stic_setup_once_func();
319 326 } }
320 327
321 for(i = 0; i < STIC_ARRAY_LEN(test_data); ++i)
328 for(i = 0; i < STIC_ARRAY_LEN(stic_test_data); ++i)
322 329 { {
323 struct stic_test_data *td = *test_data[i];
330 struct stic_test_data *td = *stic_test_data[i];
324 331 if(td == NULL) continue; if(td == NULL) continue;
325 332 if(td->p != NULL && !td->p()) if(td->p != NULL && !td->p())
326 333 { {
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