diff --git a/makefile b/makefile index 37e9211..d1c3bd3 100755 --- a/makefile +++ b/makefile @@ -1,8 +1,16 @@ +# OS detection : ROUINEB Hamza +OS := $(shell uname) +FLAG=-lfl +ifeq ($(OS),Darwin) +# Run MacOS commands + FLAG=-ll +endif +# OS detection + #compilateur utilisé CC = g++-5 # flags de compilation CC_FLAGS = -Wall -std=c++11 #-ggdb -EXT_SRC = CC_MOD_FLAGS = -MM #-MP # extension des fichiers lex (.XXX) @@ -11,7 +19,6 @@ LEX_EXT = lex LEX = flex LEX_FlAGS = - # extension des fichiers yacc (.XXX) YACC_EXT = ypp # interpréteur des fichiers Yacc : analyse syntaxique et sémantique @@ -21,7 +28,6 @@ YACC_FLAGS = #sources cpp # --- RAJOUTER CHAQUE FICHIER CPP DE MODULES ICI ! --- # --- FAIRE UN FICHIER CPP POUR CHAQUE FICHIER H S'IL Y A UNE CLASSE DEDANS --- - MOD_CPP = src/modules/ArrayAccess.cpp src/modules/ArrayDeclaration.cpp src/modules/Class.cpp src/modules/If.cpp src/modules/Node.cpp src/modules/Operator.cpp src/modules/Program.cpp src/modules/Range.cpp MOD_CPP += src/modules/Declaration.cpp src/modules/DeclarationFunction.cpp src/modules/DeclarationProcedure.cpp MOD_CPP += src/modules/Foreach.cpp src/modules/Forall.cpp src/modules/Repeat.cpp src/modules/While.cpp @@ -37,6 +43,9 @@ ADDONS_CPP += src/addons/String_addon.cpp # sources table des symboles HT_CPP = src/hash_table/HashElement.cpp src/hash_table/Function.cpp src/hash_table/HashTable.cpp src/hash_table/ScopeHashTable.cpp src/hash_table/Variable.cpp src/hash_table/ClassDeclaration.cpp src/hash_table/ClassHashTable.cpp +#sources de tests cpp +MOD_CPPUNIT = tests/cppunit/TesterRunner.cpp tests/cppunit/arraytest.cpp + ALL_CPP = ${MOD_CPP} ${ADDONS_CPP} ${HT_CPP} #fichiers objets @@ -52,14 +61,15 @@ ALL_DPDCY = $(ALL_OBJ:%.o=%.d) #executables # nom de l'exe, doit avoir le meme nom que le fichier lex EXEC = EZ_language_compiler +EXEC_TEST = unittests #compilateur -all: $(EXEC) +all: $(EXEC) EZ_language_compiler: obj/lex.yy.c obj/EZ_language_compiler.tab.cpp obj/EZ_language_compiler.tab.hpp $(ALL_OBJ) @echo -e "\033[1;33mCréation du compilateur en compilant les sources\033[0m" - $(CC) -o bin/$@ obj/EZ_language_compiler.tab.cpp obj/lex.yy.c $(ALL_OBJ) -lfl $(CC_FLAGS) + $(CC) -o bin/$@ obj/EZ_language_compiler.tab.cpp obj/lex.yy.c $(ALL_OBJ) $(FLAG) $(CC_FLAGS) obj/lex.yy.c: src/EZ_language_compiler.$(LEX_EXT) obj/EZ_language_compiler.tab.hpp @echo -e "\033[1;33mInterprétation du fichier Lex\033[0m" @@ -91,6 +101,7 @@ obj/%.d: src/addons/%.cpp #include ici --- A NE PAS DEPLACER -include $(ALL_DPDCY) + #objets obj/%.o: src/modules/%.cpp @echo -e "\033[1;33mFichier objet pour le fichier $< créé : \033[0m" @@ -107,6 +118,12 @@ obj/%.o: src/addons/%.cpp $(CC) -c $< -o $@ $(CC_FLAGS) @echo "" + +#tests +unittests: $(ALL_OBJ) $(MOD_CPPUNIT) + $(CC) $(CC_FLAGS) $^ -o bin/$@ -lcppunit + + #clean clean: @echo -e "\033[1;33mSuppression des fichiers générés et des fichiers objets\033[0m" @@ -119,6 +136,7 @@ mrproper: clean @echo "" @echo -e "\033[1;33mSuppression de l'exécutable\033[0m" rm -rf bin/$(EXEC) + rm -rf bin/$(EXEC_TEST) rm -rf docs/html/* launch: all @@ -133,6 +151,7 @@ doc: @echo -e "\n\033[1;33mOuverture de la documentation ...\033[0m" @xdg-open docs/html/index.html + #aide aide: help @@ -144,4 +163,3 @@ help: @echo "" @echo -e "\033[3mVersions requises : g++ (5.4.0), lex (2.6.0), yacc (3.0.4)\033[0m" @echo "" - diff --git a/tests/cppunit/Makefile.am b/tests/cppunit/Makefile.am new file mode 100644 index 0000000..c04b87f --- /dev/null +++ b/tests/cppunit/Makefile.am @@ -0,0 +1,6 @@ +# Rules for the test code (use `make check` to execute) +TESTS = globalTest +check_PROGRAMS = $(TESTS) +globalTest_SOURCES = TesterRunner.cpp arraytest.h ../../src/modules/ArrayDeclaration.cpp ../../src/modules/Node.cpp ../../src/hash_table/Variable.cpp ../../src/hash_table/HashElement.cpp +globalTest_CXXFLAGS = $(CPPUNIT_CFLAGS) -std=c++11 +globalTest_LDFLAGS = $(CPPUNIT_LIBS) diff --git a/tests/cppunit/TesterRunner.cpp b/tests/cppunit/TesterRunner.cpp new file mode 100644 index 0000000..367c797 --- /dev/null +++ b/tests/cppunit/TesterRunner.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include +#include + +#include "arraytest.h" + +int main(int argc,char **argv){ + + /* + A simple test to be used as a template + */ + CppUnit::TestCaller test( "testConstructor",&ArrayTest::testConstructor ); + CppUnit::TestResult result; + test.run( &result ); + + return EXIT_SUCCESS; +} + diff --git a/tests/cppunit/arraytest.cpp b/tests/cppunit/arraytest.cpp new file mode 100644 index 0000000..83d3cc2 --- /dev/null +++ b/tests/cppunit/arraytest.cpp @@ -0,0 +1,18 @@ +#include "arraytest.h" + +#include "../../src/modules/ArrayDeclaration.h" +#include "../../src/modules/PDVariables.h" + +void ArrayTest::setUp(){ + // arbitrary choice + _array = new ArrayDeclaration(new Variable("test","string",true),END_BORNE); +} + +void ArrayTest::tearDown(){ + delete _array; +} + +void ArrayTest::testConstructor() { + CPPUNIT_ASSERT( _array->get_size() == END_BORNE); + CPPUNIT_ASSERT( _array->get_variable()->get_type() == "string" ); +} diff --git a/tests/cppunit/arraytest.h b/tests/cppunit/arraytest.h new file mode 100644 index 0000000..77b46d4 --- /dev/null +++ b/tests/cppunit/arraytest.h @@ -0,0 +1,34 @@ +#ifndef ARRAYTEST_H +#define ARRAYTEST_H + +#include "../../src/modules/ArrayDeclaration.h" +#include + +/* + * This is a simple test case, to prove that the class Array works (or at least still works) + * */ +class ArrayTest : public CppUnit::TestCase { + +protected: + ArrayDeclaration *_array; + const int END_BORNE = 2; + +public: + /** + * initialize the variables + * */ + void setUp(); + + /** + * release any permanent resources you allocated in setUp() + * */ + void tearDown(); + + /** + * In the end, you'll have like a menu, with colors (red & green) showing what failled & what succeded + * */ + void testConstructor(); + +}; + +#endif diff --git a/tests/cppunit/configure.ac b/tests/cppunit/configure.ac new file mode 100644 index 0000000..ecbe42c --- /dev/null +++ b/tests/cppunit/configure.ac @@ -0,0 +1,7 @@ +AC_INIT(Makefile.am) +AM_INIT_AUTOMAKE(test,0.1) +AM_PATH_CPPUNIT(1.9.6) +AC_PROG_CXX +AC_PROG_CC +AC_PROG_INSTALL +AC_OUTPUT(Makefile)