Define TEST_DATA_DIR so unit tests can be run from any current working directory
This commit is contained in:
parent
08e663d7e2
commit
9e71a5cd23
5 changed files with 26 additions and 17 deletions
|
@ -31,6 +31,7 @@ DEFS=-D_MT -DWIN32 -D_WINDOWS -DNOPCH -DBOOST_THREAD_USE_LIB
|
||||||
DEBUGFLAGS=-g
|
DEBUGFLAGS=-g
|
||||||
CFLAGS=-O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
CFLAGS=-O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
||||||
|
|
||||||
|
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||||
|
|
||||||
ifdef USE_UPNP
|
ifdef USE_UPNP
|
||||||
LIBPATHS += -L"$(DEPSDIR)/miniupnpc"
|
LIBPATHS += -L"$(DEPSDIR)/miniupnpc"
|
||||||
|
@ -78,20 +79,19 @@ obj/%.o: %.cpp $(HEADERS)
|
||||||
bitcoind.exe: $(OBJS:obj/%=obj/%)
|
bitcoind.exe: $(OBJS:obj/%=obj/%)
|
||||||
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
||||||
|
|
||||||
|
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
|
||||||
|
|
||||||
obj/test/%.o: obj/test/%.cpp $(HEADERS)
|
obj-test/%.o: test/%.cpp $(HEADERS)
|
||||||
i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $<
|
i586-mingw32msvc-g++ -c $(TESTDEFS) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
||||||
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework-mt-s
|
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework $(LIBS)
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f obj/*.o
|
-rm -f obj/*.o
|
||||||
-rm -f obj/test/*.o
|
|
||||||
-rm -f test/*.o
|
|
||||||
-rm -f headers.h.gch
|
|
||||||
-rm -f bitcoind.exe
|
-rm -f bitcoind.exe
|
||||||
|
-rm -f obj-test/*.o
|
||||||
-rm -f test_bitcoin.exe
|
-rm -f test_bitcoin.exe
|
||||||
-rm -f src/build.h
|
-rm -f src/build.h
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ DEFS=-DWIN32 -D_WINDOWS -DNOPCH -DBOOST_THREAD_USE_LIB
|
||||||
DEBUGFLAGS=-g
|
DEBUGFLAGS=-g
|
||||||
CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
|
||||||
|
|
||||||
|
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||||
|
|
||||||
ifdef USE_UPNP
|
ifdef USE_UPNP
|
||||||
INCLUDEPATHS += -I"C:\miniupnpc-1.6-mgw"
|
INCLUDEPATHS += -I"C:\miniupnpc-1.6-mgw"
|
||||||
|
@ -71,17 +72,16 @@ obj/%.o: %.cpp $(HEADERS)
|
||||||
bitcoind.exe: $(OBJS:obj/%=obj/%)
|
bitcoind.exe: $(OBJS:obj/%=obj/%)
|
||||||
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
||||||
|
|
||||||
obj/test/test_bitcoin.o: $(wildcard test/*.cpp) $(HEADERS)
|
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
|
||||||
g++ -c $(CFLAGS) -o $@ test/test_bitcoin.cpp
|
|
||||||
|
|
||||||
test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
obj-test/%.o: test/%.cpp $(HEADERS)
|
||||||
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
|
g++ -c $(TESTDEFS) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
||||||
|
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-del /Q bitcoind test_bitcoin
|
-del /Q bitcoind test_bitcoin
|
||||||
-del /Q obj\*
|
-del /Q obj\*
|
||||||
-del /Q obj\nogui\*
|
-del /Q obj-test\*
|
||||||
-del /Q obj\test\*
|
|
||||||
-del /Q test\*.o
|
|
||||||
-del /Q headers.h.gch
|
|
||||||
-del /Q build.h
|
-del /Q build.h
|
||||||
|
|
|
@ -22,6 +22,9 @@ LIBPATHS= \
|
||||||
USE_UPNP:=1
|
USE_UPNP:=1
|
||||||
|
|
||||||
LIBS= -dead_strip
|
LIBS= -dead_strip
|
||||||
|
|
||||||
|
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||||
|
|
||||||
ifdef STATIC
|
ifdef STATIC
|
||||||
# Build STATIC if you are redistributing the bitcoind binary
|
# Build STATIC if you are redistributing the bitcoind binary
|
||||||
TESTLIBS += \
|
TESTLIBS += \
|
||||||
|
|
|
@ -9,6 +9,8 @@ DEFS=-DNOPCH
|
||||||
DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
|
DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
|
||||||
LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
|
LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
|
||||||
|
|
||||||
|
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
||||||
|
|
||||||
LMODE = dynamic
|
LMODE = dynamic
|
||||||
LMODE2 = dynamic
|
LMODE2 = dynamic
|
||||||
ifdef STATIC
|
ifdef STATIC
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/preprocessor/stringize.hpp>
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
#include "json/json_spirit_reader_template.h"
|
#include "json/json_spirit_reader_template.h"
|
||||||
#include "json/json_spirit_writer_template.h"
|
#include "json/json_spirit_writer_template.h"
|
||||||
#include "json/json_spirit_utils.h"
|
#include "json/json_spirit_utils.h"
|
||||||
|
@ -87,10 +88,13 @@ read_json(const std::string& filename)
|
||||||
{
|
{
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
fs::path testFile = fs::current_path() / "test" / "data" / filename;
|
fs::path testFile = fs::current_path() / "test" / "data" / filename;
|
||||||
|
|
||||||
|
#ifdef TEST_DATA_DIR
|
||||||
if (!fs::exists(testFile))
|
if (!fs::exists(testFile))
|
||||||
{
|
{
|
||||||
fs::path testFile = fs::path(__FILE__).parent_path() / "data" / filename;
|
testFile = fs::path(BOOST_PP_STRINGIZE(TEST_DATA_DIR)) / filename;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ifstream ifs(testFile.string().c_str(), ifstream::in);
|
ifstream ifs(testFile.string().c_str(), ifstream::in);
|
||||||
Value v;
|
Value v;
|
||||||
|
|
Loading…
Reference in a new issue