summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/parser.y15
-rw-r--r--testdata/scad/features/include-tests.scad4
-rw-r--r--testdata/scad/features/sub1/sub2/sub3/sub4/include-test2.scad4
-rw-r--r--testdata/scad/features/sub1/sub2/sub3/sub4/use-test2.scad14
-rw-r--r--testdata/scad/features/sub1/sub2/sub3/sub4/use-test3.scad4
-rw-r--r--testdata/scad/features/sub1/sub2/sub3/use-test4.scad4
-rw-r--r--testdata/scad/features/use test6.scad7
-rw-r--r--testdata/scad/features/use-test5.scad4
-rw-r--r--testdata/scad/features/use-tests.scad39
-rw-r--r--tests/.gitignore4
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/regression/cgalpngtest/use-tests-expected.pngbin0 -> 10852 bytes
-rw-r--r--tests/regression/dumptest/use-tests-expected.txt34
-rw-r--r--tests/regression/opencsgtest/use-tests-expected.pngbin0 -> 11165 bytes
-rw-r--r--tests/regression/throwntogethertest/use-tests-expected.pngbin0 -> 11618 bytes
15 files changed, 126 insertions, 11 deletions
diff --git a/src/parser.y b/src/parser.y
index b0df50d..3dd933c 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -588,12 +588,15 @@ AbstractModule *parse(const char *text, const char *path, int debug)
if (!module)
return NULL;
- BOOST_FOREACH(Module::ModuleContainer::value_type &m, module->usedlibs) {
- module->usedlibs[m.first] = Module::compile_library(m.first);
- if (!module->usedlibs[m.first]) {
- PRINTF("WARNING: Failed to compile library `%s'.", m.first.c_str());
- module->usedlibs.erase(m.first);
- }
+ // Iterating manually since we want to modify the container while iterating
+ Module::ModuleContainer::iterator iter = module->usedlibs.begin();
+ while (iter != module->usedlibs.end()) {
+ Module::ModuleContainer::iterator curr = iter++;
+ curr->second = Module::compile_library(curr->first);
+ if (!curr->second) {
+ PRINTF("WARNING: Failed to compile library `%s'.", curr->first.c_str());
+ module->usedlibs.erase(curr);
+ }
}
parser_error_pos = -1;
diff --git a/testdata/scad/features/include-tests.scad b/testdata/scad/features/include-tests.scad
index 36c04ca..fc4e9d0 100644
--- a/testdata/scad/features/include-tests.scad
+++ b/testdata/scad/features/include-tests.scad
@@ -7,7 +7,7 @@ include <non/existent/path/non-file>
//Test with empty path
include <include-test5.scad>
-//Test without preceeding space
+//Test without preceding space
include<include-test5.scad>
//Test with other strange character that is allowed
@@ -34,7 +34,7 @@ module test1()
translate([-2,-2,0]) test6();
//Just to give a top level object
- translate([0,-2,0]) sphere(0.7, $fn=16);
+ translate([0,-2,0]) sphere(test2_variable, $fn=16);
}
test1();
diff --git a/testdata/scad/features/sub1/sub2/sub3/sub4/include-test2.scad b/testdata/scad/features/sub1/sub2/sub3/sub4/include-test2.scad
index 140c4ed..c34632c 100644
--- a/testdata/scad/features/sub1/sub2/sub3/sub4/include-test2.scad
+++ b/testdata/scad/features/sub1/sub2/sub3/sub4/include-test2.scad
@@ -4,7 +4,9 @@ include <include-test3.scad>
//Test relative file location
include <../include-test4.scad>
-module test2 ()
+test2_variable = 0.7;
+
+module test2()
{
cube(center=true);
}
diff --git a/testdata/scad/features/sub1/sub2/sub3/sub4/use-test2.scad b/testdata/scad/features/sub1/sub2/sub3/sub4/use-test2.scad
new file mode 100644
index 0000000..68013db
--- /dev/null
+++ b/testdata/scad/features/sub1/sub2/sub3/sub4/use-test2.scad
@@ -0,0 +1,14 @@
+//Test nested use
+use <use-test3.scad>
+
+//Test relative file location
+use <../use-test4.scad>
+
+test2_variable = 0.7;
+
+module test2()
+{
+ translate([2,0,0]) test3();
+ translate([2,-2,0]) test4();
+ cube(center=true);
+}
diff --git a/testdata/scad/features/sub1/sub2/sub3/sub4/use-test3.scad b/testdata/scad/features/sub1/sub2/sub3/sub4/use-test3.scad
new file mode 100644
index 0000000..6e3537e
--- /dev/null
+++ b/testdata/scad/features/sub1/sub2/sub3/sub4/use-test3.scad
@@ -0,0 +1,4 @@
+module test3()
+{
+ cylinder(r1=0.7, r2=0.2, center=true);
+}
diff --git a/testdata/scad/features/sub1/sub2/sub3/use-test4.scad b/testdata/scad/features/sub1/sub2/sub3/use-test4.scad
new file mode 100644
index 0000000..c13368c
--- /dev/null
+++ b/testdata/scad/features/sub1/sub2/sub3/use-test4.scad
@@ -0,0 +1,4 @@
+module test4()
+{
+ cylinder(r=0.5, $fn=10, center=true);
+}
diff --git a/testdata/scad/features/use test6.scad b/testdata/scad/features/use test6.scad
new file mode 100644
index 0000000..0d96b26
--- /dev/null
+++ b/testdata/scad/features/use test6.scad
@@ -0,0 +1,7 @@
+module test6()
+{
+ difference() {
+ cube(center=true);
+ cylinder(r=0.4, h=2, center=true);
+ }
+}
diff --git a/testdata/scad/features/use-test5.scad b/testdata/scad/features/use-test5.scad
new file mode 100644
index 0000000..e4393cb
--- /dev/null
+++ b/testdata/scad/features/use-test5.scad
@@ -0,0 +1,4 @@
+module test5()
+{
+ sphere(r=0.5, $fn=8);
+}
diff --git a/testdata/scad/features/use-tests.scad b/testdata/scad/features/use-tests.scad
new file mode 100644
index 0000000..64af692
--- /dev/null
+++ b/testdata/scad/features/use-tests.scad
@@ -0,0 +1,39 @@
+//Test that the entire path is pushed onto the stack upto the last '/'
+use <sub1/sub2/sub3/sub4/use-test2.scad>
+
+//Test that a non existent path/file doesn't screw things up
+use <non/existent/path/non-file>
+
+//Test with empty path
+use <use-test5.scad>
+
+//Test without preceding space
+use<use-test5.scad>
+
+//Test with other strange character that is allowed
+use>>>>><use-test5.scad>
+
+//Test that filenames with spaces work
+use <use test6.scad>
+
+//Test with empty file
+use<test/>
+
+//Test with empty path and file
+use </>
+
+module test1()
+{
+ test2();
+ // test3() and test4() are not directly included and thus not imported into
+ // this scope
+ translate([4,0,0]) test3();
+ translate([4,-2,0]) test4();
+ translate([-2,0,0]) test5();
+ translate([-2,-2,0]) test6();
+
+ // test2_variable won't be visible
+ translate([0,-2,0]) sphere(test2_variable, $fn=16);
+}
+
+test1();
diff --git a/tests/.gitignore b/tests/.gitignore
index ba02d4c..4dc4e40 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -19,4 +19,6 @@ out.png
/echotest
/opencsgtest
/throwntogethertest
-/yee_compare
+/cgalstlsanitytest
+/sysinfo.txt
+/CTestCustom.cmake \ No newline at end of file
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 78ef647..edab744 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -583,7 +583,9 @@ file(GLOB FEATURES_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/features/*.scad)
# Remove included files not to be used as tests
list(REMOVE_ITEM FEATURES_FILES
${CMAKE_SOURCE_DIR}/../testdata/scad/features/include\ test6.scad
- ${CMAKE_SOURCE_DIR}/../testdata/scad/features/include-test5.scad)
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/features/include-test5.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/features/use\ test6.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/features/use-test5.scad)
file(GLOB BUGS_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/*.scad)
file(GLOB SCAD_DXF_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/dxf/*.scad)
file(GLOB FUNCTION_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/functions/*.scad)
diff --git a/tests/regression/cgalpngtest/use-tests-expected.png b/tests/regression/cgalpngtest/use-tests-expected.png
new file mode 100644
index 0000000..21747cc
--- /dev/null
+++ b/tests/regression/cgalpngtest/use-tests-expected.png
Binary files differ
diff --git a/tests/regression/dumptest/use-tests-expected.txt b/tests/regression/dumptest/use-tests-expected.txt
new file mode 100644
index 0000000..7ba3ac5
--- /dev/null
+++ b/tests/regression/dumptest/use-tests-expected.txt
@@ -0,0 +1,34 @@
+ group() {
+ group() {
+ multmatrix([[1, 0, 0, 2], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ group() {
+ cylinder($fn = 0, $fa = 12, $fs = 2, h = 1, r1 = 0.7, r2 = 0.2, center = true);
+ }
+ }
+ multmatrix([[1, 0, 0, 2], [0, 1, 0, -2], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ group() {
+ cylinder($fn = 10, $fa = 12, $fs = 2, h = 1, r1 = 0.5, r2 = 0.5, center = true);
+ }
+ }
+ cube(size = [1, 1, 1], center = true);
+ }
+ multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]);
+ multmatrix([[1, 0, 0, 4], [0, 1, 0, -2], [0, 0, 1, 0], [0, 0, 0, 1]]);
+ multmatrix([[1, 0, 0, -2], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ group() {
+ sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5);
+ }
+ }
+ multmatrix([[1, 0, 0, -2], [0, 1, 0, -2], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ group() {
+ difference() {
+ cube(size = [1, 1, 1], center = true);
+ cylinder($fn = 0, $fa = 12, $fs = 2, h = 2, r1 = 0.4, r2 = 0.4, center = true);
+ }
+ }
+ }
+ multmatrix([[1, 0, 0, 0], [0, 1, 0, -2], [0, 0, 1, 0], [0, 0, 0, 1]]) {
+ sphere($fn = 16, $fa = 12, $fs = 2, r = 1);
+ }
+ }
+
diff --git a/tests/regression/opencsgtest/use-tests-expected.png b/tests/regression/opencsgtest/use-tests-expected.png
new file mode 100644
index 0000000..8a85ad5
--- /dev/null
+++ b/tests/regression/opencsgtest/use-tests-expected.png
Binary files differ
diff --git a/tests/regression/throwntogethertest/use-tests-expected.png b/tests/regression/throwntogethertest/use-tests-expected.png
new file mode 100644
index 0000000..e5bf382
--- /dev/null
+++ b/tests/regression/throwntogethertest/use-tests-expected.png
Binary files differ
contact: Jan Huwald // Impressum