summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ctor.cc20
-rw-r--r--test/search_test.cc106
2 files changed, 125 insertions, 1 deletions
diff --git a/test/ctor.cc b/test/ctor.cc
index c24ded7..fd97c80 100644
--- a/test/ctor.cc
+++ b/test/ctor.cc
@@ -67,7 +67,9 @@ BuildConfigurations ctorTestConfigs(const Settings& settings)
"../src/build.cc",
"../src/configure.cc",
"../src/execute.cc",
+ "../src/externals_manual.cc",
"../src/rebuild.cc",
+ "../src/search.cc",
"../src/tasks.cc",
"../src/task.cc",
"../src/task_ar.cc",
@@ -76,7 +78,6 @@ BuildConfigurations ctorTestConfigs(const Settings& settings)
"../src/task_ld.cc",
"../src/task_so.cc",
"../src/util.cc",
- "../src/externals_manual.cc",
},
.flags = {
.cxxflags = {
@@ -86,6 +87,23 @@ BuildConfigurations ctorTestConfigs(const Settings& settings)
.ldflags = { "-pthread" },
},
},
+ {
+ .type = TargetType::UnitTest,
+ .target = "search_test",
+ .sources = {
+ "../src/search.cc",
+ "search_test.cc",
+ "testmain.cc",
+ },
+ .flags = {
+ .cxxflags = {
+ "-std=c++20", "-O3", "-s", "-Wall", "-Werror",
+ "-I../src", "-Iuunit",
+ "-DOUTPUT=\"search\"",
+ },
+ .ldflags = { "-pthread" },
+ },
+ },
};
}
}
diff --git a/test/search_test.cc b/test/search_test.cc
new file mode 100644
index 0000000..179fb0e
--- /dev/null
+++ b/test/search_test.cc
@@ -0,0 +1,106 @@
+#include <uunit.h>
+
+#include <string>
+#include <fstream>
+
+#include <search.h>
+#include <libctor.h>
+
+#include "paths.h"
+
+class SearchTest
+ : public uUnit
+{
+public:
+ SearchTest()
+ {
+ uTEST(SearchTest::test_include);
+ uTEST(SearchTest::test_lib);
+ }
+
+ void test_include()
+ {
+ using namespace std::string_literals;
+
+ constexpr auto verb = -1;
+
+ auto src = paths::top_srcdir / "src";
+ auto tmp = std::filesystem::temp_directory_path();
+
+ { // system
+ Settings settings{.verbose = verb}; // instantiate with default paths set
+ auto result = findHeader(settings, "stdio.h", {});
+ uASSERT_EQUAL("/usr/include"s, result.string());
+ }
+
+ { // libctor.h in src folder
+ Settings settings{.verbose = verb}; // instantiate with default paths set
+ auto result = findHeader(settings, "libctor.h", { src.string() });
+ uASSERT_EQUAL(src, result);
+ }
+
+ { // src/libctor.h in topsrc folder (ie. path with '/')
+ Settings settings{.verbose = verb}; // instantiate with default paths set
+ auto result = findHeader(settings, "src/libctor.h",
+ { paths::top_srcdir.string() });
+ uASSERT_EQUAL(paths::top_srcdir, result);
+ }
+
+ { // libctor.h in src folder over one in temp folder (system)
+ Settings settings{.verbose = verb}; // instantiate with default paths set
+ settings.include_paths = { tmp.string() };
+ auto tmpfile = tmp / "libctor.h";
+ { // create /tmp/libctor.h file
+ std::ofstream of(tmpfile.string());
+ of << "/* nop */";
+ }
+ auto result = findHeader(settings, "libctor.h", { src.string() });
+ std::filesystem::remove(tmpfile);
+ uASSERT_EQUAL(src, result);
+ }
+
+ { // libctor.h in temp folder over one in src folder (local prio)
+ Settings settings{.verbose = verb}; // instantiate with default paths set
+ settings.include_paths = {}; // remove system search paths
+ auto tmpfile = tmp / "libctor.h";
+ { // create /tmp/libctor.h file
+ std::ofstream of(tmpfile.string());
+ of << "/* nop */";
+ }
+ auto result = findHeader(settings, "libctor.h",
+ { tmp.string(), src.string() });
+ std::filesystem::remove(tmpfile);
+ uASSERT_EQUAL(tmp, result);
+ }
+
+ { // not found
+ Settings settings{.verbose = verb};
+ settings.include_paths = {}; // remove system search paths
+ auto result = findHeader(settings, "no_such_file.h", {});
+ uASSERT(result.empty());
+ }
+ }
+
+ void test_lib()
+ {
+ using namespace std::string_literals;
+
+ constexpr auto verb = 2;
+
+ auto src = paths::top_srcdir / "src";
+ auto tmp = std::filesystem::temp_directory_path();
+
+ { // system
+ Settings settings{.verbose = verb}; // instantiate with default paths set
+ auto result = findLibrary(settings, "ffi", {});
+ for(auto f : result)
+ {
+ std::cout << f << "\n";
+ }
+ uASSERT_EQUAL("/usr/lib/libffi.so"s, result[0].string());
+ }
+ }
+};
+
+// Registers the fixture into the 'registry'
+static SearchTest test;