From 10701f71581bd4053ab328254d6abacd6956b498 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 14 Jan 2012 03:25:09 +0100 Subject: Added absolute path tests to include and use tests, fixed bug using absolute paths in use and include diff --git a/src/lexer.l b/src/lexer.l index 459f92d..718874f 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -108,12 +108,18 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); } [^\t\r\n>]+ { filename = yytext; } ">" { BEGIN(INITIAL); - fs::path usepath = fs::path(parser_source_path) / filename; - if (!fs::exists(usepath)) { - usepath = fs::path(librarydir) / filename; - } - handle_dep(fs::absolute(usepath).string()); - parserlval.text = strdup(fs::absolute(usepath).string().c_str()); + fs::path usepath; + if (fs::path(filename).is_absolute()) { + usepath = filename; + } + else { + usepath = fs::path(parser_source_path) / filename; + if (!fs::exists(usepath)) { + usepath = fs::absolute(fs::path(librarydir) / filename); + } + } + handle_dep(usepath.string()); + parserlval.text = strdup(usepath.string().c_str()); return TOK_USE; } } @@ -192,7 +198,12 @@ void includefile() fs::path dirinfo = sourcepath(); if (!filepath.empty()) { - dirinfo /= filepath; + if (fs::path(filepath).is_absolute()) { + dirinfo = filepath; + } + else { + dirinfo /= filepath; + } } fs::path finfo = dirinfo / filename; diff --git a/testdata/scad/features/include test6.scad b/testdata/scad/features/include test6.scad deleted file mode 100644 index 0d96b26..0000000 --- a/testdata/scad/features/include test6.scad +++ /dev/null @@ -1,7 +0,0 @@ -module test6() -{ - difference() { - cube(center=true); - cylinder(r=0.4, h=2, center=true); - } -} diff --git a/testdata/scad/features/include-test5.scad b/testdata/scad/features/include-test5.scad deleted file mode 100644 index e4393cb..0000000 --- a/testdata/scad/features/include-test5.scad +++ /dev/null @@ -1,4 +0,0 @@ -module test5() -{ - sphere(r=0.5, $fn=8); -} diff --git a/testdata/scad/features/include-tests.scad b/testdata/scad/features/include-tests.scad deleted file mode 100644 index fc4e9d0..0000000 --- a/testdata/scad/features/include-tests.scad +++ /dev/null @@ -1,40 +0,0 @@ -//Test that the entire path is pushed onto the stack upto the last '/' -include - -//Test that a non existent path/file doesn't screw things up -include - -//Test with empty path -include - -//Test without preceding space -include - -//Test with other strange character that is allowed -include>>>>> - -//Test that filenames with spaces work -include - -//Test with empty file -include - -//Test with empty path and file -include - -//Test with empty -include <> - -module test1() -{ - test2(); - translate([2,0,0]) test3(); - translate([2,-2,0]) test4(); - translate([-2,0,0]) test5(); - translate([-2,-2,0]) test6(); - - //Just to give a top level object - translate([0,-2,0]) sphere(test2_variable, $fn=16); -} - -test1(); diff --git a/testdata/scad/features/sub1/sub2/sub3/include-test4.scad b/testdata/scad/features/sub1/sub2/sub3/include-test4.scad deleted file mode 100644 index c13368c..0000000 --- a/testdata/scad/features/sub1/sub2/sub3/include-test4.scad +++ /dev/null @@ -1,4 +0,0 @@ -module test4() -{ - cylinder(r=0.5, $fn=10, center=true); -} diff --git a/testdata/scad/features/sub1/sub2/sub3/sub4/include-test2.scad b/testdata/scad/features/sub1/sub2/sub3/sub4/include-test2.scad deleted file mode 100644 index c34632c..0000000 --- a/testdata/scad/features/sub1/sub2/sub3/sub4/include-test2.scad +++ /dev/null @@ -1,12 +0,0 @@ -//Test nested include -include - -//Test relative file location -include <../include-test4.scad> - -test2_variable = 0.7; - -module test2() -{ - cube(center=true); -} diff --git a/testdata/scad/features/sub1/sub2/sub3/sub4/include-test3.scad b/testdata/scad/features/sub1/sub2/sub3/sub4/include-test3.scad deleted file mode 100644 index 6e3537e..0000000 --- a/testdata/scad/features/sub1/sub2/sub3/sub4/include-test3.scad +++ /dev/null @@ -1,4 +0,0 @@ -module test3() -{ - cylinder(r1=0.7, r2=0.2, 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 deleted file mode 100644 index 68013db..0000000 --- a/testdata/scad/features/sub1/sub2/sub3/sub4/use-test2.scad +++ /dev/null @@ -1,14 +0,0 @@ -//Test nested use -use - -//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 deleted file mode 100644 index 6e3537e..0000000 --- a/testdata/scad/features/sub1/sub2/sub3/sub4/use-test3.scad +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index c13368c..0000000 --- a/testdata/scad/features/sub1/sub2/sub3/use-test4.scad +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 0d96b26..0000000 --- a/testdata/scad/features/use test6.scad +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index e4393cb..0000000 --- a/testdata/scad/features/use-test5.scad +++ /dev/null @@ -1,4 +0,0 @@ -module test5() -{ - sphere(r=0.5, $fn=8); -} diff --git a/testdata/scad/features/use-tests.scad b/testdata/scad/features/use-tests.scad deleted file mode 100644 index 64af692..0000000 --- a/testdata/scad/features/use-tests.scad +++ /dev/null @@ -1,39 +0,0 @@ -//Test that the entire path is pushed onto the stack upto the last '/' -use - -//Test that a non existent path/file doesn't screw things up -use - -//Test with empty path -use - -//Test without preceding space -use - -//Test with other strange character that is allowed -use>>>>> - -//Test that filenames with spaces work -use - -//Test with empty file -use - -//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/testdata/scad/misc/include test6.scad b/testdata/scad/misc/include test6.scad new file mode 100644 index 0000000..0d96b26 --- /dev/null +++ b/testdata/scad/misc/include 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/misc/include-test5.scad b/testdata/scad/misc/include-test5.scad new file mode 100644 index 0000000..e4393cb --- /dev/null +++ b/testdata/scad/misc/include-test5.scad @@ -0,0 +1,4 @@ +module test5() +{ + sphere(r=0.5, $fn=8); +} diff --git a/testdata/scad/misc/include-tests-template.scad b/testdata/scad/misc/include-tests-template.scad new file mode 100644 index 0000000..6724a6d --- /dev/null +++ b/testdata/scad/misc/include-tests-template.scad @@ -0,0 +1,41 @@ +//Test that the entire path is pushed onto the stack upto the last '/' +include + +//Test that a non existent path/file doesn't screw things up +include + +//Test with empty path +include + +//Test without preceding space +include + +//Test with other strange character that is allowed +include>>>>> + +//Test that filenames with spaces work +include + +//Test with empty file +include + +//Test with empty path and file +include + +//Test with absolute path +include <@CMAKE_SOURCE_DIR@/../testdata/scad/misc/sub2/test7.scad> + +module test1() +{ + test2(); + translate([2,0,0]) test3(); + translate([2,-2,0]) test4(); + translate([-2,0,0]) test5(); + translate([-2,-2,0]) test6(); + translate([0,2,0]) test7(); + + //Just to give a top level object + translate([0,-2,0]) sphere(test2_variable, $fn=16); +} + +test1(); diff --git a/testdata/scad/misc/sub1/sub2/sub3/include-test4.scad b/testdata/scad/misc/sub1/sub2/sub3/include-test4.scad new file mode 100644 index 0000000..c13368c --- /dev/null +++ b/testdata/scad/misc/sub1/sub2/sub3/include-test4.scad @@ -0,0 +1,4 @@ +module test4() +{ + cylinder(r=0.5, $fn=10, center=true); +} diff --git a/testdata/scad/misc/sub1/sub2/sub3/sub4/include-test2.scad b/testdata/scad/misc/sub1/sub2/sub3/sub4/include-test2.scad new file mode 100644 index 0000000..c34632c --- /dev/null +++ b/testdata/scad/misc/sub1/sub2/sub3/sub4/include-test2.scad @@ -0,0 +1,12 @@ +//Test nested include +include + +//Test relative file location +include <../include-test4.scad> + +test2_variable = 0.7; + +module test2() +{ + cube(center=true); +} diff --git a/testdata/scad/misc/sub1/sub2/sub3/sub4/include-test3.scad b/testdata/scad/misc/sub1/sub2/sub3/sub4/include-test3.scad new file mode 100644 index 0000000..6e3537e --- /dev/null +++ b/testdata/scad/misc/sub1/sub2/sub3/sub4/include-test3.scad @@ -0,0 +1,4 @@ +module test3() +{ + cylinder(r1=0.7, r2=0.2, center=true); +} diff --git a/testdata/scad/misc/sub1/sub2/sub3/sub4/use-test2.scad b/testdata/scad/misc/sub1/sub2/sub3/sub4/use-test2.scad new file mode 100644 index 0000000..68013db --- /dev/null +++ b/testdata/scad/misc/sub1/sub2/sub3/sub4/use-test2.scad @@ -0,0 +1,14 @@ +//Test nested use +use + +//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/misc/sub1/sub2/sub3/sub4/use-test3.scad b/testdata/scad/misc/sub1/sub2/sub3/sub4/use-test3.scad new file mode 100644 index 0000000..6e3537e --- /dev/null +++ b/testdata/scad/misc/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/misc/sub1/sub2/sub3/use-test4.scad b/testdata/scad/misc/sub1/sub2/sub3/use-test4.scad new file mode 100644 index 0000000..c13368c --- /dev/null +++ b/testdata/scad/misc/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/misc/sub2/test7.scad b/testdata/scad/misc/sub2/test7.scad new file mode 100644 index 0000000..12ff245 --- /dev/null +++ b/testdata/scad/misc/sub2/test7.scad @@ -0,0 +1,4 @@ +module test7() +{ + cube([0.5,0.5,1], center=true); +} diff --git a/testdata/scad/misc/use test6.scad b/testdata/scad/misc/use test6.scad new file mode 100644 index 0000000..0d96b26 --- /dev/null +++ b/testdata/scad/misc/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/misc/use-test5.scad b/testdata/scad/misc/use-test5.scad new file mode 100644 index 0000000..e4393cb --- /dev/null +++ b/testdata/scad/misc/use-test5.scad @@ -0,0 +1,4 @@ +module test5() +{ + sphere(r=0.5, $fn=8); +} diff --git a/testdata/scad/misc/use-tests-template.scad b/testdata/scad/misc/use-tests-template.scad new file mode 100644 index 0000000..c39efce --- /dev/null +++ b/testdata/scad/misc/use-tests-template.scad @@ -0,0 +1,43 @@ +//Test that the entire path is pushed onto the stack upto the last '/' +use + +//Test that a non existent path/file doesn't screw things up +use + +//Test with empty path +use + +//Test without preceding space +use + +//Test with other strange character that is allowed +use>>>>> + +//Test that filenames with spaces work +use + +//Test with empty file +use + +//Test with empty path and file +use + +//Test with absolute path +include <@CMAKE_SOURCE_DIR@/../testdata/scad/misc/sub2/test7.scad> + +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(); + translate([0,2,0]) test7(); + + // test2_variable won't be visible + translate([0,-2,0]) sphere(test2_variable, $fn=16); +} + +test1(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3b379d6..9d5e24e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -588,15 +588,15 @@ endforeach() set_directory_properties(PROPERTIES TEST_INCLUDE_FILE "${CMAKE_SOURCE_DIR}/EnforceConfig.cmake") +# Subst files +configure_file(${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests-template.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad) +configure_file(${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests-template.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad) + # Find all scad files file(GLOB MINIMAL_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/minimal/*.scad) 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/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) @@ -613,9 +613,13 @@ list(APPEND ECHO_FILES ${FUNCTION_FILES} ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-indexing.scad) list(APPEND DUMPTEST_FILES ${MINIMAL_FILES} ${FEATURES_FILES} ${EXAMPLE_FILES}) -list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test.scad) +list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad) list(APPEND CGALPNGTEST_FILES ${FEATURES_FILES} ${SCAD_DXF_FILES} ${EXAMPLE_FILES}) +list(APPEND CGALPNGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad) list(APPEND OPENCSGTEST_FILES ${CGALPNGTEST_FILES}) list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/bbox-transform-bug.scad) list(APPEND THROWNTOGETHERTEST_FILES ${OPENCSGTEST_FILES}) diff --git a/tests/regression/cgalpngtest/include-tests-expected.png b/tests/regression/cgalpngtest/include-tests-expected.png index 99ebcc7..031dcda 100644 Binary files a/tests/regression/cgalpngtest/include-tests-expected.png and b/tests/regression/cgalpngtest/include-tests-expected.png differ diff --git a/tests/regression/cgalpngtest/use-tests-expected.png b/tests/regression/cgalpngtest/use-tests-expected.png index 21747cc..5afa74e 100644 Binary files a/tests/regression/cgalpngtest/use-tests-expected.png and b/tests/regression/cgalpngtest/use-tests-expected.png differ diff --git a/tests/regression/dumptest/include-tests-expected.txt b/tests/regression/dumptest/include-tests-expected.txt index d4b5065..00e7beb 100644 --- a/tests/regression/dumptest/include-tests-expected.txt +++ b/tests/regression/dumptest/include-tests-expected.txt @@ -25,6 +25,11 @@ } } } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { + group() { + cube(size = [0.5, 0.5, 1], 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 = 0.7); } diff --git a/tests/regression/dumptest/use-tests-expected.txt b/tests/regression/dumptest/use-tests-expected.txt index 7ba3ac5..c320af6 100644 --- a/tests/regression/dumptest/use-tests-expected.txt +++ b/tests/regression/dumptest/use-tests-expected.txt @@ -27,6 +27,11 @@ } } } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { + group() { + cube(size = [0.5, 0.5, 1], 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/include-tests-expected.png b/tests/regression/opencsgtest/include-tests-expected.png index 62be03c..c1e780b 100644 Binary files a/tests/regression/opencsgtest/include-tests-expected.png and b/tests/regression/opencsgtest/include-tests-expected.png differ diff --git a/tests/regression/opencsgtest/use-tests-expected.png b/tests/regression/opencsgtest/use-tests-expected.png index 8a85ad5..5141b37 100644 Binary files a/tests/regression/opencsgtest/use-tests-expected.png and b/tests/regression/opencsgtest/use-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/include-tests-expected.png b/tests/regression/throwntogethertest/include-tests-expected.png index 5b1857b..b6dc00e 100644 Binary files a/tests/regression/throwntogethertest/include-tests-expected.png and b/tests/regression/throwntogethertest/include-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/use-tests-expected.png b/tests/regression/throwntogethertest/use-tests-expected.png index e5bf382..7e2f702 100644 Binary files a/tests/regression/throwntogethertest/use-tests-expected.png and b/tests/regression/throwntogethertest/use-tests-expected.png differ -- cgit v0.10.1