Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand 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

Expand All @@ -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 ""

6 changes: 6 additions & 0 deletions tests/cppunit/Makefile.am
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions tests/cppunit/TesterRunner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <stdlib.h>

#include <cppunit/TestCaller.h>
#include <cppunit/TestResult.h>

#include "arraytest.h"

int main(int argc,char **argv){

/*
A simple test to be used as a template
*/
CppUnit::TestCaller<ArrayTest> test( "testConstructor",&ArrayTest::testConstructor );
CppUnit::TestResult result;
test.run( &result );

return EXIT_SUCCESS;
}

18 changes: 18 additions & 0 deletions tests/cppunit/arraytest.cpp
Original file line number Diff line number Diff line change
@@ -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" );
}
34 changes: 34 additions & 0 deletions tests/cppunit/arraytest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef ARRAYTEST_H
#define ARRAYTEST_H

#include "../../src/modules/ArrayDeclaration.h"
#include <cppunit/TestCase.h>

/*
* 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
7 changes: 7 additions & 0 deletions tests/cppunit/configure.ac
Original file line number Diff line number Diff line change
@@ -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)