From 8ecc2d18bf86b1021a31a2e5d01e71afbaa1efd0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Jan 2017 18:38:06 +0200 Subject: Add missing diagnostics in testscript parser --- build2/test/script/parser.cxx | 25 +++++++++ unit-tests/test/script/parser/setup-teardown.test | 68 +++++++++++++++++++++++ 2 files changed, 93 insertions(+) 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 + : + $* <>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 + : + $* <>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 + : + $* <>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 + : + $* <>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 + : + $* <>EOO + cmd + x = y + if true + y = x + end + EOI + cmd + ? true + EOO +} -- cgit v1.1