Skip to content

Instantly share code, notes, and snippets.

@picasso250
Last active March 17, 2016 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picasso250/e745c8419eba8bbdc5ee to your computer and use it in GitHub Desktop.
Save picasso250/e745c8419eba8bbdc5ee to your computer and use it in GitHub Desktop.
C++ Testing framework, simple as possible
#!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
#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