summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/cgalpngtest.cc7
-rw-r--r--tests/csgtestcore.cc7
-rw-r--r--tests/dumptest.cc13
-rw-r--r--tests/tests-common.cc11
-rw-r--r--tests/tests-common.h4
6 files changed, 27 insertions, 16 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7833572..964adc2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -429,6 +429,7 @@ set(CORE_SOURCES
../src/linearextrude.cc
../src/rotateextrude.cc
../src/printutils.cc
+ ../src/fileutils.cc
../src/progress.cc
../src/boost-utils.cc
${FLEX_OpenSCADlexer_OUTPUTS}
diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc
index 81fc6b4..7b958de 100644
--- a/tests/cgalpngtest.cc
+++ b/tests/cgalpngtest.cc
@@ -113,9 +113,10 @@ int main(int argc, char **argv)
exit(1);
}
- if (fs::path(filename).has_parent_path()) {
- fs::current_path(fs::path(filename).parent_path());
- }
+ fs::path fpath = boosty::absolute(fs::path(filename));
+ fs::path fparent = fpath.parent_path();
+ fs::current_path(fparent);
+ top_ctx.setDocumentPath(fparent.string());
AbstractNode::resetIndexCounter();
AbstractNode *absolute_root_node = root_module->instantiate(&top_ctx, &root_inst);
diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc
index 320b533..7b9dbab 100644
--- a/tests/csgtestcore.cc
+++ b/tests/csgtestcore.cc
@@ -148,9 +148,10 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type)
}
if (!sysinfo_dump) {
- if (fs::path(filename).has_parent_path()) {
- fs::current_path(fs::path(filename).parent_path());
- }
+ fs::path fpath = boosty::absolute(fs::path(filename));
+ fs::path fparent = fpath.parent_path();
+ fs::current_path(fparent);
+ top_ctx.setDocumentPath(fparent.string());
}
AbstractNode::resetIndexCounter();
diff --git a/tests/dumptest.cc b/tests/dumptest.cc
index e4876fa..4477703 100644
--- a/tests/dumptest.cc
+++ b/tests/dumptest.cc
@@ -97,9 +97,10 @@ int main(int argc, char **argv)
exit(1);
}
- if (fs::path(filename).has_parent_path()) {
- fs::current_path(fs::path(filename).parent_path());
- }
+ fs::path fpath = boosty::absolute(fs::path(filename));
+ fs::path fparent = fpath.parent_path();
+ fs::current_path(fparent);
+ top_ctx.setDocumentPath(fparent.string());
AbstractNode::resetIndexCounter();
root_node = root_module->instantiate(&top_ctx, &root_inst);
@@ -130,7 +131,7 @@ int main(int argc, char **argv)
delete root_module;
fs::current_path(original_path);
- root_module = parsefile(outfilename);
+ root_module = parsefile(outfilename, fparent.string().c_str());
if (!root_module) {
fprintf(stderr, "Error: Unable to read back dumped file\n");
exit(1);
@@ -141,9 +142,7 @@ int main(int argc, char **argv)
tree.setRoot(root_node);
- if (fs::path(outfilename).has_parent_path()) {
- fs::current_path(fs::path(outfilename).parent_path());
- }
+ fs::current_path(fparent);
string readbackstr = dumptree(tree, *root_node);
if (dumpstdstr != readbackstr) {
diff --git a/tests/tests-common.cc b/tests/tests-common.cc
index ac85e37..3c66e1b 100644
--- a/tests/tests-common.cc
+++ b/tests/tests-common.cc
@@ -7,7 +7,12 @@
#include <sstream>
#include <fstream>
-FileModule *parsefile(const char *filename)
+/*!
+ fakepath is used to force the parser to believe that the file is
+ read from this location, in order to ensure that filepaths are
+ eavluated relative to this path (for testing purposes).
+*/
+FileModule *parsefile(const char *filename, const char *fakepath)
{
FileModule *root_module = NULL;
@@ -19,7 +24,9 @@ FileModule *parsefile(const char *filename)
else {
std::string text((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
text += "\n" + commandline_commands;
- std::string pathname = boosty::stringy(fs::path(filename).parent_path());
+ std::string pathname;
+ if (fakepath) pathname = fakepath;
+ else pathname = boosty::stringy(fs::path(filename).parent_path());
root_module = parse(text.c_str(), pathname.c_str(), false);
if (root_module) {
root_module->handleDependencies();
diff --git a/tests/tests-common.h b/tests/tests-common.h
index 3393884..e16bcda 100644
--- a/tests/tests-common.h
+++ b/tests/tests-common.h
@@ -1,6 +1,8 @@
#ifndef TESTS_COMMON_H_
#define TESTS_COMMON_H_
-class FileModule *parsefile(const char *filename);
+#include <stdlib.h>
+
+class FileModule *parsefile(const char *filename, const char *fakepath = NULL);
#endif
contact: Jan Huwald // Impressum