aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorArnstein Ressem <aressem@gmail.com>2016-08-23 15:10:36 +0200
committerVegard Sjonfjell <vegardsjo@gmail.com>2016-08-23 15:10:36 +0200
commit55e5a91901109161186e05d3a6e959e06958bbba (patch)
treef312bab2c60207ee305dbcfa047fcc4fa8fd2dc1 /vespalib
parentd337a29392fb752dc725e4aea5efa0cc0df5f17a (diff)
Aressem/cmake more out of source tests (#441)
* vespalib tests run out of source. * staging_vespalib run tests out of source. * fastos tests run out of source. * Fixed storage tests out of source. * Fixed some of the config tests. * config* tests run out of source. * document_* tests run out of source. * documentapi_ tests run out of source. * Fixed fsa out of source tests. * Fix jrt_test out of source. * More tests run out of source. * Fix some slobrok and messagebus tests. * More fixes for out of source tests. * Done with first pass of regular tests out of source. * Only use SOURCE_DIRECTORY in a limited set of places. * Fix some remaining tests. * Some cleanups. * No need for extra slash.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/guard/guard_test.cpp2
-rw-r--r--vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp7
-rw-r--r--vespalib/src/tests/slime/slime_json_format_test.cpp3
-rw-r--r--vespalib/src/tests/stllike/asciistream_test.cpp2
-rw-r--r--vespalib/src/tests/testapp-debug/testapp-debug.cpp7
-rw-r--r--vespalib/src/tests/testapp-state/testapp-state.cpp6
-rw-r--r--vespalib/src/tests/testkit-subset/CMakeLists.txt2
-rwxr-xr-xvespalib/src/tests/testkit-subset/testkit-subset_test.sh9
-rw-r--r--vespalib/src/tests/text/lowercase/lowercase_test.cpp2
-rw-r--r--vespalib/src/tests/text/utf8/utf8_test.cpp2
-rw-r--r--vespalib/src/tests/tutorial/CMakeLists.txt2
-rwxr-xr-xvespalib/src/tests/tutorial/compare-tutorials.sh6
-rw-r--r--vespalib/src/tests/tutorial/make_tutorial.cpp24
-rw-r--r--vespalib/src/vespa/vespalib/testkit/testapp.cpp17
-rw-r--r--vespalib/src/vespa/vespalib/testkit/testapp.h7
15 files changed, 74 insertions, 24 deletions
diff --git a/vespalib/src/tests/guard/guard_test.cpp b/vespalib/src/tests/guard/guard_test.cpp
index a663edc4eec..83de03e3f20 100644
--- a/vespalib/src/tests/guard/guard_test.cpp
+++ b/vespalib/src/tests/guard/guard_test.cpp
@@ -132,7 +132,7 @@ Test::testDirPointer()
EXPECT_TRUE(!dir.valid());
}
{
- DirPointer dir(opendir("."));
+ DirPointer dir(opendir(vespalib::TestApp::GetSourceDirectory().c_str()));
EXPECT_TRUE(dir.valid());
dirent *de;
diff --git a/vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp b/vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp
index 3c2b9455fe8..5718592203a 100644
--- a/vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp
+++ b/vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp
@@ -1,6 +1,7 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/fastos.h>
#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/util/slaveproc.h>
using namespace vespalib;
@@ -15,7 +16,11 @@ bool runPrint(const char *cmd) {
TEST("make fixture macros") {
EXPECT_FALSE(runPrint("../../apps/make_fixture_macros/vespalib_make_fixture_macros_app"));
EXPECT_TRUE(runPrint("../../apps/make_fixture_macros/vespalib_make_fixture_macros_app 9 > macros.tmp"));
- EXPECT_TRUE(runPrint("diff -u ../../vespa/vespalib/testkit/generated_fixture_macros.h macros.tmp"));
+
+ std::string diffCmd("diff -u ");
+ diffCmd += vespalib::TestApp::GetSourceDirectory();
+ diffCmd += "../../vespa/vespalib/testkit/generated_fixture_macros.h macros.tmp";
+ EXPECT_TRUE(runPrint(diffCmd.c_str()));
}
TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); }
diff --git a/vespalib/src/tests/slime/slime_json_format_test.cpp b/vespalib/src/tests/slime/slime_json_format_test.cpp
index e04bc8aa325..7995584f60b 100644
--- a/vespalib/src/tests/slime/slime_json_format_test.cpp
+++ b/vespalib/src/tests/slime/slime_json_format_test.cpp
@@ -1,6 +1,7 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/fastos.h>
#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/data/slime/slime.h>
#include <iostream>
#include <fstream>
@@ -351,7 +352,7 @@ TEST("decode simplified form") {
}
TEST_F("decode bytes not null-terminated", Slime) {
- std::ifstream file("large_json.txt");
+ std::ifstream file(vespalib::TestApp::GetSourceDirectory() + "large_json.txt");
ASSERT_TRUE(file.is_open());
std::stringstream buf;
buf << file.rdbuf();
diff --git a/vespalib/src/tests/stllike/asciistream_test.cpp b/vespalib/src/tests/stllike/asciistream_test.cpp
index bca3d431405..1dcfda2b53f 100644
--- a/vespalib/src/tests/stllike/asciistream_test.cpp
+++ b/vespalib/src/tests/stllike/asciistream_test.cpp
@@ -342,7 +342,7 @@ AsciistreamTest::testCreateFromFile()
asciistream is(asciistream::createFromFile("non-existing.txt"));
EXPECT_TRUE(is.eof());
- is = asciistream::createFromFile("test.txt");
+ is = asciistream::createFromFile(vespalib::TestApp::GetSourceDirectory() + "test.txt");
EXPECT_FALSE(is.eof());
EXPECT_EQUAL(12u, is.size());
string s;
diff --git a/vespalib/src/tests/testapp-debug/testapp-debug.cpp b/vespalib/src/tests/testapp-debug/testapp-debug.cpp
index 7b332220f1d..cbe032f19f8 100644
--- a/vespalib/src/tests/testapp-debug/testapp-debug.cpp
+++ b/vespalib/src/tests/testapp-debug/testapp-debug.cpp
@@ -1,11 +1,16 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/fastos.h>
#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/testkit/testapp.h>
using namespace vespalib;
TEST_MAIN() {
system("./vespalib_debug_test_app");
system("diff lhs.out rhs.out > diff.out");
- EXPECT_EQUAL(system("diff diff.out diff.ref"), 0);
+
+
+ std::string diff_cmd("diff diff.out ");
+ diff_cmd += vespalib::TestApp::GetSourceDirectory() + "diff.ref";
+ EXPECT_EQUAL(system(diff_cmd.c_str()), 0);
}
diff --git a/vespalib/src/tests/testapp-state/testapp-state.cpp b/vespalib/src/tests/testapp-state/testapp-state.cpp
index 016ad90dd50..df126f8dcfc 100644
--- a/vespalib/src/tests/testapp-state/testapp-state.cpp
+++ b/vespalib/src/tests/testapp-state/testapp-state.cpp
@@ -1,11 +1,15 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/fastos.h>
#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/testkit/testapp.h>
using namespace vespalib;
TEST_MAIN() {
system("./vespalib_state_test_app > out.txt 2>&1 out.txt");
system("cat out.txt | grep STATE | sed 's/([^)].*\\//(/' > actual.txt");
- EXPECT_EQUAL(system("diff -u expect.txt actual.txt"), 0);
+
+ std::string diff_cmd("diff -u actual.txt ");
+ diff_cmd += vespalib::TestApp::GetSourceDirectory() + "expect.txt";
+ EXPECT_EQUAL(system(diff_cmd.c_str()), 0);
}
diff --git a/vespalib/src/tests/testkit-subset/CMakeLists.txt b/vespalib/src/tests/testkit-subset/CMakeLists.txt
index cde1a0c5cc1..d6d278a6628 100644
--- a/vespalib/src/tests/testkit-subset/CMakeLists.txt
+++ b/vespalib/src/tests/testkit-subset/CMakeLists.txt
@@ -6,4 +6,4 @@ vespa_add_executable(vespalib_testkit-subset_test_app TEST
DEPENDS
vespalib
)
-vespa_add_test(NAME vespalib_testkit-subset_test_app COMMAND sh testkit-subset_test.sh)
+vespa_add_test(NAME vespalib_testkit-subset_test_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/testkit-subset_test.sh)
diff --git a/vespalib/src/tests/testkit-subset/testkit-subset_test.sh b/vespalib/src/tests/testkit-subset/testkit-subset_test.sh
index 44c4f5251b4..12f5a9e63fc 100755
--- a/vespalib/src/tests/testkit-subset/testkit-subset_test.sh
+++ b/vespalib/src/tests/testkit-subset/testkit-subset_test.sh
@@ -1,9 +1,12 @@
#!/bin/bash
-
set -e
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
TEST_SUBSET=pass $VALGRIND ./vespalib_testkit-subset_test_app 2> out.txt
TEST_SUBSET="extra\.cpp:.*pass.*" $VALGRIND ./vespalib_testkit-subset_test_app 2>> out.txt
cat out.txt | grep "\.cpp: " > out.relpath.txt
-cmp -s out.relpath.txt out.ref.2.txt && exit 0
-diff -u out.relpath.txt out.ref.txt
+cmp -s out.relpath.txt $SOURCE_DIRECTORY/out.ref.2.txt && exit 0
+diff -u out.relpath.txt $SOURCE_DIRECTORY/out.ref.txt
diff --git a/vespalib/src/tests/text/lowercase/lowercase_test.cpp b/vespalib/src/tests/text/lowercase/lowercase_test.cpp
index b226690790d..39ae5c0aea0 100644
--- a/vespalib/src/tests/text/lowercase/lowercase_test.cpp
+++ b/vespalib/src/tests/text/lowercase/lowercase_test.cpp
@@ -20,7 +20,7 @@ Test::Main()
EXPECT_EQUAL((int8_t)'a', LowerCase::convert((int8_t)'A'));
EXPECT_EQUAL((uint8_t)'a', LowerCase::convert((uint8_t)'A'));
- std::ifstream yellData("yell-want.dat");
+ std::ifstream yellData(vespalib::TestApp::GetSourceDirectory() + "yell-want.dat");
EXPECT_TRUE(yellData.good());
diff --git a/vespalib/src/tests/text/utf8/utf8_test.cpp b/vespalib/src/tests/text/utf8/utf8_test.cpp
index 99a926f8088..e88fe756e40 100644
--- a/vespalib/src/tests/text/utf8/utf8_test.cpp
+++ b/vespalib/src/tests/text/utf8/utf8_test.cpp
@@ -54,7 +54,7 @@ Test::Main()
{
// read data produced from Java program
- int fd = ::open("regular-utf8.dat", O_RDONLY);
+ int fd = ::open((vespalib::TestApp::GetSourceDirectory() + "regular-utf8.dat").c_str(), O_RDONLY);
ASSERT_TRUE(fd > 0);
vespalib::string data;
data.clear();
diff --git a/vespalib/src/tests/tutorial/CMakeLists.txt b/vespalib/src/tests/tutorial/CMakeLists.txt
index 120c848b2ae..9ca6951525c 100644
--- a/vespalib/src/tests/tutorial/CMakeLists.txt
+++ b/vespalib/src/tests/tutorial/CMakeLists.txt
@@ -5,7 +5,7 @@ vespa_add_executable(vespalib_make_tutorial_app TEST
DEPENDS
vespalib
)
-vespa_add_test(NAME vespalib_make_tutorial_app COMMAND sh ./compare-tutorials.sh)
+vespa_add_test(NAME vespalib_make_tutorial_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/compare-tutorials.sh)
vespa_add_executable(vespalib_xml_escape_app
SOURCES
xml_escape.cpp
diff --git a/vespalib/src/tests/tutorial/compare-tutorials.sh b/vespalib/src/tests/tutorial/compare-tutorials.sh
index 4e328bb9742..01f22295395 100755
--- a/vespalib/src/tests/tutorial/compare-tutorials.sh
+++ b/vespalib/src/tests/tutorial/compare-tutorials.sh
@@ -1,6 +1,10 @@
#!/bin/bash
set -e
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
./vespalib_make_tutorial_app > tutorial_out.html
-diff -u tutorial.html tutorial_out.html || true
+diff -u $SOURCE_DIRECTORY/tutorial.html tutorial_out.html || true
echo "IGNORED: vespalib_make_tutorial_app"
diff --git a/vespalib/src/tests/tutorial/make_tutorial.cpp b/vespalib/src/tests/tutorial/make_tutorial.cpp
index 3f83caef67c..a18c33afeeb 100644
--- a/vespalib/src/tests/tutorial/make_tutorial.cpp
+++ b/vespalib/src/tests/tutorial/make_tutorial.cpp
@@ -1,5 +1,6 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/util/slaveproc.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <sys/mman.h>
@@ -29,20 +30,20 @@ std::string runCommand(const std::string &cmd) {
return out;
}
-void insertExample(const std::string &name) {
- std::string str = runCommand(make_string("./make_example.sh %s",
+void insertExample(const std::string &name, const std::string &src_dir) {
+ std::string str = runCommand(make_string("%s/make_example.sh %s", src_dir.c_str(),
name.c_str()));
fprintf(stdout, "%s", str.c_str());
}
-void insertSource(const std::string &name) {
- std::string str = runCommand(make_string("./make_source.sh %s",
+void insertSource(const std::string &name, const std::string &src_dir) {
+ std::string str = runCommand(make_string("%s/make_source.sh %s", src_dir.c_str(),
name.c_str()));
fprintf(stdout, "%s", str.c_str());
}
-void insertFile(const std::string &name) {
- std::string str = readFile(name);
+void insertFile(const std::string &name, const std::string &src_dir) {
+ std::string str = readFile(src_dir + "/" + name);
fprintf(stdout, "%s", str.c_str());
}
@@ -56,7 +57,7 @@ TEST_MAIN_WITH_PROCESS_PROXY() {
size_t pos = 0;
size_t end = 0;
size_t cursor = 0;
- std::string input = readFile("tutorial_source.html");
+ std::string input = readFile(vespalib::TestApp::GetSourceDirectory() + "tutorial_source.html");
while ((pos = input.find(pre, cursor)) < input.size() &&
(end = input.find(post, pos)) < input.size())
{
@@ -64,13 +65,16 @@ TEST_MAIN_WITH_PROCESS_PROXY() {
pos += pre.size();
if (input.find(example, pos) == pos) {
pos += example.size();
- insertExample(std::string((input.data() + pos), (end - pos)));
+ insertExample(std::string((input.data() + pos), (end - pos)),
+ vespalib::TestApp::GetSourceDirectory());
} else if (input.find(source, pos) == pos) {
pos += source.size();
- insertSource(std::string((input.data() + pos), (end - pos)));
+ insertSource(std::string((input.data() + pos), (end - pos)),
+ vespalib::TestApp::GetSourceDirectory());
} else if (input.find(file, pos) == pos) {
pos += file.size();
- insertFile(std::string((input.data() + pos), (end - pos)));
+ insertFile(std::string((input.data() + pos), (end - pos)),
+ vespalib::TestApp::GetSourceDirectory());
} else {
std::string str((input.data() + pos), (end - pos));
TEST_FATAL(make_string("invalid directive >%s<", str.c_str()).c_str());
diff --git a/vespalib/src/vespa/vespalib/testkit/testapp.cpp b/vespalib/src/vespa/vespalib/testkit/testapp.cpp
index a4bb01e525c..ee5a76a0500 100644
--- a/vespalib/src/vespa/vespalib/testkit/testapp.cpp
+++ b/vespalib/src/vespa/vespalib/testkit/testapp.cpp
@@ -17,6 +17,23 @@ TestApp::~TestApp()
{
}
+const std::string&
+TestApp::GetSourceDirectory()
+{
+ static const std::string srcDir = [] () {
+ std::string dir(".");
+ const char* env = getenv("SOURCE_DIRECTORY");
+ if (env) {
+ dir = env;
+ }
+ if (*dir.rbegin() != '/') {
+ dir += "/";
+ }
+ return dir;
+ } ();
+ return srcDir;
+}
+
void
TestApp::ReportInit(const char *name)
{
diff --git a/vespalib/src/vespa/vespalib/testkit/testapp.h b/vespalib/src/vespa/vespalib/testkit/testapp.h
index 644c85e4be7..25e4c060822 100644
--- a/vespalib/src/vespa/vespalib/testkit/testapp.h
+++ b/vespalib/src/vespa/vespalib/testkit/testapp.h
@@ -179,6 +179,13 @@ public:
const char *GetName() { return _name.c_str(); }
/**
+ * @brief Obtain the source directory for the current test
+ *
+ * @return Path to source directory with trailing /
+ */
+ static const std::string& GetSourceDirectory();
+
+ /**
* @brief Report test initialization
*
* @param name the name of this test