lundi 27 juin 2016

The executable test file is not running the tests

I have created a project:

// func.h :
#ifndef FUNCS_H_
#define FUNCS_H_

int addInts(int i, int j);

#endif /* FUNCS_H_ */


// func.cpp
#include "func.h"

int addInts(int i, int j) {
    return i + j;
}


// main.cpp
#include "func.h"

#include <iostream>

int main() {
    std::cout << addInts(5, 7) << std::endl;
    return 0;
}


//makefile
OBJS := \
    main.o \
    func.o

CXX := g++

CXX_FLAGS := -Wall -Werror -Wextra -std=c++11

all: main_prj

main_prj: $(OBJS)
    $(CXX) $(OBJS) -lm -o main

-include $(OBJS:.o=.d)

%.o: %.cpp
    $(CXX) -c $(CXX_FLAGS) $*.cpp -o $*.o

clean:
    rm -f main $(OBJS)

And I created also a test (boost test) for that function:

// test/main_test.cpp
#define BOOST_TEST_MODULE main_test
#include <boost/test/included/unit_test.hpp>

//____________________________________________________________________________//


// FIXTURES ...

//____________________________________________________________________________//


// test/addInts/addInts_test.cpp
#include <boost/test/unit_test.hpp>

#include "../../func.h"

BOOST_AUTO_TEST_CASE(addInts_5_7) {
    int addInts_5_7 = 5 + 7;
    BOOST_CHECK_EQUAL(addInts_5_7, addInts(5, 7));
}


// test/makefile
OBJS_TEST := \
    main_test.o \
    addInts/addInts_test.o \
    ../func.o

CXX_TEST := g++

CXX_FLAGS_TEST := -Wall -Werror -Wextra -std=c++11

all_test: main_test_prj

main_test_prj: $(OBJS_TEST)
    $(CXX_TEST) $(OBJS_TEST) -lm -o main_test

-include $(OBJS_TEST:.o=.d)

%.o: %.cpp
    $(CXX_TEST) -c $(CXX_FLAGS_TEST) $*.cpp -o $*.o

clean_test:
    rm -f main_test $(OBJS_TEST)


Now, the make commands work, so they clean all the created files, or create the o files and the executables. When I run the main file, the output is correct: 12 ; but when I run the main_test file, the output is a little strange:

Running 1 test case...

*** No errors detected

I would expect the output with running tests and OK/KO, or pass/not pass... I cannot figure what am I doing wrong. Can anyone help me, please?

Aucun commentaire:

Enregistrer un commentaire