summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testdata/scad/misc/value-reassignment-tests.scad7
-rw-r--r--testdata/scad/misc/value-reassignment-tests2.scad9
-rw-r--r--testdata/scad/misc/variable-scope-tests.scad13
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/regression/echotest/value-reassignment-tests-expected.txt2
-rw-r--r--tests/regression/echotest/value-reassignment-tests2-expected.txt1
-rw-r--r--tests/regression/echotest/variable-scope-tests-expected.txt2
7 files changed, 32 insertions, 3 deletions
diff --git a/testdata/scad/misc/value-reassignment-tests.scad b/testdata/scad/misc/value-reassignment-tests.scad
index 475f78f..4370c11 100644
--- a/testdata/scad/misc/value-reassignment-tests.scad
+++ b/testdata/scad/misc/value-reassignment-tests.scad
@@ -1,4 +1,9 @@
+// Test reassignment which depends on a previously assigned variable,
+// as this could be messed up if order of assignment evaluation
+// changes
+
myval = 2;
i = 2;
myval = i * 2;
-echo(myval);
+echo(myval, i); // Should output 4, 2
+
diff --git a/testdata/scad/misc/value-reassignment-tests2.scad b/testdata/scad/misc/value-reassignment-tests2.scad
new file mode 100644
index 0000000..9d7cf50
--- /dev/null
+++ b/testdata/scad/misc/value-reassignment-tests2.scad
@@ -0,0 +1,9 @@
+// Test reassignment where another variable has used the previous
+// value before the reassignment. This could get messed up if order of
+// assignment evaluation changes
+
+myval = 2;
+i = myval;
+myval = 3;
+echo(myval, i); // Should output 3, 2
+
diff --git a/testdata/scad/misc/variable-scope-tests.scad b/testdata/scad/misc/variable-scope-tests.scad
index 8426fbb..104d1a4 100644
--- a/testdata/scad/misc/variable-scope-tests.scad
+++ b/testdata/scad/misc/variable-scope-tests.scad
@@ -49,5 +49,16 @@ echo("undeclared variable can still be passed and used");
module undeclared_var() {
echo(d);
}
-
undeclared_var(d=6);
+
+echo("attempt to assign from a not-yet-defined variable which also exists globally");
+
+globalval = 1;
+// Test that b = a turns into b = 1, heeding the order of the assignments
+// See issue #399 for more discussion
+module global_lookup() {
+ b = globalval; // Should be assigned 1 since the local one isn't yet defined
+ globalval = 5; // Overrides the value for the local scope only
+ echo(globalval,b); // Should output 5, 1
+}
+global_lookup();
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4dbe8ce..7509ed1 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -779,6 +779,7 @@ list(APPEND ECHO_FILES ${FUNCTION_FILES}
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/search-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/recursion-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/value-reassignment-tests.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/value-reassignment-tests2.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/variable-scope-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/lookup-tests.scad)
diff --git a/tests/regression/echotest/value-reassignment-tests-expected.txt b/tests/regression/echotest/value-reassignment-tests-expected.txt
index 05a6741..fc7b7b1 100644
--- a/tests/regression/echotest/value-reassignment-tests-expected.txt
+++ b/tests/regression/echotest/value-reassignment-tests-expected.txt
@@ -1 +1 @@
-ECHO: 4
+ECHO: 4, 2
diff --git a/tests/regression/echotest/value-reassignment-tests2-expected.txt b/tests/regression/echotest/value-reassignment-tests2-expected.txt
new file mode 100644
index 0000000..99b37a2
--- /dev/null
+++ b/tests/regression/echotest/value-reassignment-tests2-expected.txt
@@ -0,0 +1 @@
+ECHO: 3, 2
diff --git a/tests/regression/echotest/variable-scope-tests-expected.txt b/tests/regression/echotest/variable-scope-tests-expected.txt
index 92db05d..5994778 100644
--- a/tests/regression/echotest/variable-scope-tests-expected.txt
+++ b/tests/regression/echotest/variable-scope-tests-expected.txt
@@ -14,3 +14,5 @@ ECHO: undef
ECHO: 5
ECHO: "undeclared variable can still be passed and used"
ECHO: 6
+ECHO: "attempt to assign from a not-yet-defined variable which also exists globally"
+ECHO: 5, 1
contact: Jan Huwald // Impressum