Featured post
Automatic code testing in c upon execution -
each source file has function:
unsigned char test(){ //return true if tests succceed false otherwise }
everytime sourcefile gets recompiled want test function of file run on execution of executable , if tests return false halt. however, want code test code hasnt been run since build.
i thinking use makefile system problem since makefiles recompile changed code want. therefore, thinking of adding command line arguments. saw example in used echo , date add time last modified. code write time last modified save file on successful execution of test code compare next time.
is there better way? 1 doesnt rely on make? @ least there way without relying on spefic unix commands? lastly, if isnt possible, command line addition file like.
yes, make file.t target dependant on file.c.
file.t generated based on successful completion of test.
it'll easier if call test function "main" , wrap in #ifdef's this:
#ifdef test int main() { if (test_something() == 1) return 0; else return 1; } #endif
of course, can other trickier things if want.
an example makefile (using gnu make syntax)
all: foo.t %.t: %.c gcc -dtest $< -o $@.tmp if ./$@.tmp ; echo "1" > $@; rm $@.tmp ; fi
however! you'll better off adopting cutest (http://cutest.sourceforge.net/).
- Get link
- X
- Other Apps
Comments
Post a Comment