Created
January 22, 2017 15:08
-
-
Save macrat/2319931ab8ec8f6078800eb5acd12dd5 to your computer and use it in GitHub Desktop.
簡易的なセルフテストのマクロ
This file contains hidden or 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 <string.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#define TEST(name, assert) { \ | |
printf(name); \ | |
for(int i=strlen(name); i<40-6; i++){ \ | |
printf(" "); \ | |
} \ | |
printf("[....]"); \ | |
fflush(stdout); \ | |
if(assert){ \ | |
printf("\r\e[0;37m%s", name); \ | |
for(int i=strlen(name); i<40-6; i++){ \ | |
printf(" "); \ | |
} \ | |
printf("\e[0m[\e[0;32m OK \e[0m]\r\n"); \ | |
}else{ \ | |
printf("\r\e[1;37m%s", name); \ | |
for(int i=strlen(name); i<40-6; i++){ \ | |
printf(" "); \ | |
} \ | |
printf("\e[0m[\e[0;31mFAIL\e[0m]\r\n"); \ | |
} \ | |
} | |
bool later(int n){ | |
sleep(n); | |
return true; | |
} | |
bool never(){ | |
while(true); | |
} | |
int main() { | |
TEST("hoge", 1 == 10); | |
TEST("fuga", 1 == 1); | |
TEST("foo", later(1)); | |
TEST("bar", !later(1)); | |
TEST("later 1", later(1)); | |
TEST("later 2", later(2)); | |
TEST("never", never()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment