I have a directory that looks like this:
. ├── makefile ├── solution │ ├── weather.cpp │ └── weather.h ├── student │ ├── weather.cpp │ └── weather.h └── tests └── test_Weather_Weather.cpp
solution/weather.h
#ifndef _WEATHER_H_
#define _WEATHER_H_
#include <string>
using namespace std;
class Weather {
private:
int temp;
public:
Weather();
string announce();
};
#endif
solution/weather.cpp
#include <iostream>
#include "weather.h"
using namespace std;
Weather::Weather() {
temp = 0;
}
string Weather::announce() {
if (temp <= 0) {
return "It's freezing!";
} else {
return "It's hot!";
}
}
What I'm trying to accomplish is that I want to compile and run test_Weather_Weather.cpp
, which will catch a bug in the default constructor of Weather in the student definition. I want to unit test this constructor (and eventually announce
), so I want to use the solution
symbols for everything except the student
constructor.
I want to be able to accomplish this at compile time, aka before compiling I want both student
and solution
source/header files to be exactly the same (aside from their definition differences).
I have tried to get it to work using g++ -D flag, but I've been unsuccessful.