Created
August 28, 2012 13:57
-
-
Save sw17ch/3498219 to your computer and use it in GitHub Desktop.
A change similar to what we might think about doing to Unity down the road.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* This stuff would be updated/added to unity. */ | |
typedef struct { | |
char * desc; | |
char * file; | |
int line; | |
} test_information_t; | |
#define TEST_INFO_NAME(x, y) test_info_ ## x ## _ ## y | |
#define TEST_INFO_NAME2(x, y) TEST_INFO_NAME(x, y) | |
#define TEST_FN_NAME(x, y) test_fn_ ## x ## _ ## y | |
#define TEST_FN_NAME2(x, y) TEST_FN_NAME(x, y) | |
#define TEST(fn, desc) \ | |
test_information_t TEST_INFO_NAME2(fn, __LINE__) = { \ | |
(desc), \ | |
(__FILE__), \ | |
(__LINE__), \ | |
}; \ | |
void TEST_FN_NAME2(fn, __LINE__)(void) | |
/* This is what a test declaration would look like. */ | |
TEST(SomeFun, "this is a description " | |
"it has multiple lines " | |
"omg, that's cool. also " | |
"it has spaces.") // This is the line on which the test is defined | |
{ | |
printf("i am a test\n"); | |
} | |
int main(int argc, char * argv[]) | |
{ | |
/* This is what a test runner would have to deal with. */ | |
printf("%s %d\n%s\n", test_info_SomeFun_29.file | |
, test_info_SomeFun_29.line | |
, test_info_SomeFun_29.desc); | |
printf("OUTPUT<<<\n"); | |
/* Here's how a test runner would have to call the test. */ | |
test_fn_SomeFun_29(); | |
printf(">>>END OUTPUT\n"); | |
/* This is the output when running this file: | |
* | |
* gcc t.c -o t && ./t | |
* t.c 29 | |
* this is a description it has multiple lines omg, that's cool. also it has spaces. | |
* OUTPUT<<< | |
* i am a test | |
* >>>END OUTPUT | |
*/ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment