-
-
Save picasso250/e745c8419eba8bbdc5ee to your computer and use it in GitHub Desktop.
C++ Testing framework, simple as possible
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
#!bash | |
# Usage: test X | |
# It will include `X.h` and `test_X.cpp` | |
# and execute all `test_.+()` functions. | |
if [[ x$1 == "x" ]]; then | |
echo "Usage: $0 <file>" | |
exit | |
fi | |
dep=.test_tmp_dep.h | |
if [[ ! -f $1.h ]]; then | |
echo no $1.h | |
exit | |
fi | |
echo "#include \"$1.h\"" > $dep | |
tf=test_$1.cpp | |
if [[ ! -f $tf ]]; then | |
echo no $tf | |
exit | |
fi | |
echo "#include \"$tf\"" >> $dep | |
cf=.test_tmp_testing.cpp | |
pt="void test[_A-Z].*\)$" | |
grep -P "$pt" $tf | cut -d" " -f 2 | sed 'a ;' > $cf | |
tc=$(grep -P "$pt" $tf -c) | |
ac=$(grep -P "^\s*assert\(" $tf -c) | |
echo "cout<<\"$tc cases ($ac assertions) PASSED.\"<<endl;" >> $cf | |
g++ -std=c++11 -o test test_frame.cpp | |
if [[ $? -eq 0 ]]; then | |
./test.exe | |
fi |
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 <iostream> | |
#include <cassert> | |
#include ".test_tmp_dep.h" | |
using namespace std; | |
int main(int argc, char const *argv[]) | |
{ | |
#include ".test_tmp_testing.cpp" | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment