#!/bin/sh

UNITTEST_MAIN_CPP=unittest_main.cpp

# 登録関数
REGIST_CLASSES=`grep "class .*public.*TestCase" src/*.cpp | sed -s "s/^.*class \(.*\)\:.*public.*/\1/"`



## ==============================================================================
##  ソースファイル出力
## ==============================================================================

cat <<EOF > src/${UNITTEST_MAIN_CPP}
#include <iostream>
#include <scpp_unittest.hpp>

#define RUN_SUITE(tclass) { tcase = new tclass(); tcase->suite(); delete tcase; }

EOF

REGIST_TEST_FILES=`ls -1 src/*.cpp | sed -s "s/src\///" | grep -v ${UNITTEST_MAIN_CPP}`
for f in ${REGIST_TEST_FILES}; do
	echo "#include \"${f}\"" >> src/${UNITTEST_MAIN_CPP}
done


cat <<EOF >> src/${UNITTEST_MAIN_CPP}



int main(int argc, char* argv[])
{
	scpp::TestCase* tcase;

EOF


for f in ${REGIST_CLASSES}; do
	echo "	RUN_SUITE(${f})" >> src/${UNITTEST_MAIN_CPP}
done
cat <<EOF >> src/${UNITTEST_MAIN_CPP}

	return 0;
}
EOF

