diff options
-rw-r--r-- | build2/test/script/parser.cxx | 25 | ||||
-rw-r--r-- | unit-tests/test/script/parser/setup-teardown.test | 68 |
2 files changed, 93 insertions, 0 deletions
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index f250d27..f381118 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -240,6 +240,19 @@ namespace build2 next (t, tt); // Get '{'. const location sl (get_location (t)); + // First check that we don't have any teardown commands yet. + // This will detect things like variable assignments between + // scopes. + // + if (!group_->tdown_.empty ()) + { + location tl ( + group_->tdown_.back ().tokens.front ().location ()); + + fail (sl) << "scope after teardown" << + info (tl) << "last teardown line appears here"; + } + // If there is no user-supplied id, use the line number // (prefixed with include id) as the scope id. // @@ -763,6 +776,18 @@ namespace build2 // const location sl (ls.back ().tokens.front ().location ()); + // First check that we don't have any teardown commands yet. This + // will detect things like variable assignments between scopes. + // + if (!group_->tdown_.empty ()) + { + location tl ( + group_->tdown_.back ().tokens.front ().location ()); + + fail (sl) << "scope after teardown" << + info (tl) << "last teardown line appears here"; + } + // If there is no user-supplied id, use the line number (prefixed with // include id) as the scope id. Note that we use the same id for all // scopes in the chain. diff --git a/unit-tests/test/script/parser/setup-teardown.test b/unit-tests/test/script/parser/setup-teardown.test index c9183ef..6711442 100644 --- a/unit-tests/test/script/parser/setup-teardown.test +++ b/unit-tests/test/script/parser/setup-teardown.test @@ -81,3 +81,71 @@ testscript:2:1: error: teardown command in test EOE } + +: var +: +{ + : between-tests + : + $* <<EOI 2>>EOE != 0 + cmd + x = y + cmd + EOI + testscript:3:1: error: test after teardown + testscript:2:1: info: last teardown line appears here + EOE + + : between-tests-scope + : + $* <<EOI 2>>EOE != 0 + cmd + x = y + { + cmd + } + EOI + testscript:3:1: error: scope after teardown + testscript:2:1: info: last teardown line appears here + EOE + + : between-tests-command-if + : + $* <<EOI 2>>EOE != 0 + cmd + x = y + if true + cmd + end + EOI + testscript:3:1: error: test after teardown + testscript:2:1: info: last teardown line appears here + EOE + + : between-tests-scope-if + : + $* <<EOI 2>>EOE != 0 + cmd + x = y + if true + { + cmd + } + EOI + testscript:3:1: error: scope after teardown + testscript:2:1: info: last teardown line appears here + EOE + + : between-tests-variable-if + : + $* <<EOI >>EOO + cmd + x = y + if true + y = x + end + EOI + cmd + ? true + EOO +} |