summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-10-31 16:02:19 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2021-10-31 16:02:19 +0100
commit463f0740e1731c15917ffdb3e2f4b3f4c83aa024 (patch)
treeec733f3744009834901d61b0fc52aafd354df5d7 /test
parent406e1b1eeb2a760c0b89ff141a183c78d113a5e4 (diff)
Change to testdir before executing tests and add global paths variables for easier path testing inside the unit-tests.
Diffstat (limited to 'test')
-rw-r--r--test/ctor.cc6
-rw-r--r--test/paths.h15
-rw-r--r--test/testmain.cc36
3 files changed, 54 insertions, 3 deletions
diff --git a/test/ctor.cc b/test/ctor.cc
index 61c3515..d7cad34 100644
--- a/test/ctor.cc
+++ b/test/ctor.cc
@@ -14,7 +14,7 @@ BuildConfigurations ctorTestConfigs()
.target = "execute_test",
.sources = {
"execute_test.cc",
- "uunit/uunit.cc",
+ "testmain.cc",
"../src/execute.cc",
},
.cxxflags = {
@@ -29,7 +29,7 @@ BuildConfigurations ctorTestConfigs()
.target = "tasks_test",
.sources = {
"tasks_test.cc",
- "uunit/uunit.cc",
+ "testmain.cc",
},
.depends = {"libctor.a"},
.cxxflags = {
@@ -44,7 +44,7 @@ BuildConfigurations ctorTestConfigs()
.target = "source_type_test",
.sources = {
"source_type_test.cc",
- "uunit/uunit.cc",
+ "testmain.cc",
},
.depends = {"libctor.a"},
.cxxflags = {
diff --git a/test/paths.h b/test/paths.h
new file mode 100644
index 0000000..f149972
--- /dev/null
+++ b/test/paths.h
@@ -0,0 +1,15 @@
+// -*- c++ -*-
+// Distributed under the BSD 2-Clause License.
+// See accompanying file LICENSE for details.
+#pragma once
+
+#include <string>
+#include <filesystem>
+
+namespace paths
+{
+extern std::string argv_0;
+extern std::filesystem::path top_srcdir;
+extern std::filesystem::path top_builddir;
+extern std::filesystem::path testdir;
+}
diff --git a/test/testmain.cc b/test/testmain.cc
new file mode 100644
index 0000000..db8e22c
--- /dev/null
+++ b/test/testmain.cc
@@ -0,0 +1,36 @@
+// -*- c++ -*-
+// Distributed under the BSD 2-Clause License.
+// See accompanying file LICENSE for details.
+#define uUNIT_MAIN
+#include "uunit.h"
+
+#include <fstream>
+#include <string>
+#include <filesystem>
+
+namespace paths
+{
+std::string argv_0;
+std::filesystem::path top_srcdir;
+std::filesystem::path top_builddir;
+std::filesystem::path testdir;
+}
+
+int main(int argc, char* argv[])
+{
+ (void)argc;
+
+ paths::argv_0 = argv[0];
+
+ auto cur = std::filesystem::current_path();
+ paths::testdir = std::filesystem::path(paths::argv_0).parent_path();
+ // assuming <builddir>/test
+ paths::top_builddir = paths::testdir.parent_path();
+ paths::top_srcdir = std::filesystem::relative(cur, paths::testdir);
+
+ std::filesystem::current_path(paths::testdir);
+
+ std::ofstream xmlfile;
+ xmlfile.open("result_" OUTPUT ".xml");
+ return uUnit::runTests(xmlfile);
+}