[Pkg-bitcoin-commits] [libunivalue] 06/76: tests: support srcdir != targetdir
Jonas Smedegaard
dr at jones.dk
Mon Apr 4 09:18:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libunivalue.
commit 4f09f276257b24747668fad5fbea81b3d8ddb739
Author: Jeff Garzik <jgarzik at bitpay.com>
Date: Thu Jun 12 17:48:10 2014 -0400
tests: support srcdir != targetdir
---
Makefile.am | 1 +
unitester.cpp | 20 +++++++++++++-------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 74f58e6..62d4d7f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,6 +14,7 @@ noinst_PROGRAMS = unitester
unitester_SOURCES = unitester.cpp
unitester_LDADD = libunivalue.a
+unitester_CXXFLAGS = -DJSON_TEST_SRC=\"$(top_srcdir)\"
EXTRA_DIST = \
fail10.json \
diff --git a/unitester.cpp b/unitester.cpp
index a614a48..fe6f9f6 100644
--- a/unitester.cpp
+++ b/unitester.cpp
@@ -5,18 +5,22 @@
#include <string>
#include "univalue.h"
+#ifndef JSON_TEST_SRC
+#error JSON_TEST_SRC must point to test source directory
+#endif
+
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
using namespace std;
+string srcdir(JSON_TEST_SRC);
-static void runtest(const char *filename, const string& jdata)
+static void runtest(string filename, const string& jdata)
{
- fprintf(stderr, "test %s\n", filename);
+ fprintf(stderr, "test %s\n", filename.c_str());
- string filename_(filename);
- string prefix = filename_.substr(0, 4);
+ string prefix = filename.substr(0, 4);
bool wantPass = (prefix == "pass");
bool wantFail = (prefix == "fail");
@@ -45,9 +49,11 @@ static void runtest(const char *filename, const string& jdata)
}
}
-static void runtest_file(const char *filename)
+static void runtest_file(const char *filename_)
{
- FILE *f = fopen(filename, "r");
+ string basename(filename_);
+ string filename = srcdir + "/" + basename;
+ FILE *f = fopen(filename.c_str(), "r");
assert(f != NULL);
string jdata;
@@ -64,7 +70,7 @@ static void runtest_file(const char *filename)
assert(!ferror(f));
fclose(f);
- runtest(filename, jdata);
+ runtest(basename, jdata);
}
static const char *filenames[] = {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/libunivalue.git
More information about the Pkg-bitcoin-commits
mailing list