diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-16 18:22:22 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-16 18:22:22 +0300 |
commit | 32cac452a834605a15a679e247f0f5faf3f2fc5d (patch) | |
tree | ca8114e9465550ffab374d58403e8b1212888e3c | |
parent | 320e849d17597aef40b9e3e62f79319f13f97e45 (diff) |
Redo testscript diagnostics not to rely on invalid paths
-rw-r--r-- | build2/test/script/parser.cxx | 35 | ||||
-rw-r--r-- | build2/test/script/runner.cxx | 41 | ||||
-rw-r--r-- | tests/test/script/runner/set.test | 9 | ||||
-rw-r--r-- | unit-tests/test/script/parser/expansion.test | 20 |
4 files changed, 50 insertions, 55 deletions
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index d3cab0a..dad397b 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -2232,34 +2232,17 @@ namespace build2 add_word (move (s), l); else { - // Come up with a "path" that contains both the original - // location as well as the expanded string. The resulting - // diagnostics will look like this: + // If the chunk re-parsing results in error, our diagnostics + // will look like this: // - // testscript:10:1 ('abc): unterminated single quote + // <string>:1:4: error: stdout merge redirect file descriptor must be 2 + // testscript:2:5: info: while parsing string '1>&a' // - path name; - { - string n (l.file->string ()); - n += ':'; - - if (!ops.no_line ()) + auto df = make_diag_frame ( + [s, &l](const diag_record& dr) { - n += to_string (l.line); - n += ':'; - - if (!ops.no_column ()) - { - n += to_string (l.column); - n += ':'; - } - } - - n += " ("; - n += s; - n += ')'; - name = path (move (n)); - } + dr << info (l) << "while parsing string '" << s << "'"; + }); // When re-lexing we do "effective escaping" and only for // ['"\] (quotes plus the backslash itself). In particular, @@ -2273,6 +2256,8 @@ namespace build2 // args = 'x=\"foo bar\"' // cmd $args # cmd x="foo bar" // + + path name ("<string>"); istringstream is (s); lexer lex (is, name, lexer_mode::command_expansion, diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx index 13f7f8a..889b27c 100644 --- a/build2/test/script/runner.cxx +++ b/build2/test/script/runner.cxx @@ -1077,38 +1077,25 @@ namespace build2 lhs.assign (move (ns), &var); else { - // Come up with a "path" that contains both the expression line - // location as well as the attributes string. The resulting - // diagnostics will look like this: + // If there is an error in the attributes string, our diagnostics + // will look like this: // - // testscript:10:1: ([x]):1:1: error: unknown value attribute x + // <attributes>:1:1 error: unknown value attribute x + // testscript:10:1 info: while parsing attributes '[x]' // - path name; - { - string n (ll.file->string ()); - n += ':'; - - if (!ops.no_line ()) + auto df = make_diag_frame ( + [ats, &ll](const diag_record& dr) { - n += to_string (ll.line); - n += ':'; - - if (!ops.no_column ()) - { - n += to_string (ll.column); - n += ':'; - } - } - - n += " ("; - n += *ats; - n += ')'; - name = path (move (n)); - } + dr << info (ll) << "while parsing attributes '" << *ats << "'"; + }); parser p; - p.apply_value_attributes( - &var, lhs, value (move (ns)), *ats, token_type::assign, name); + p.apply_value_attributes (&var, + lhs, + value (move (ns)), + *ats, + token_type::assign, + path ("<attributes>")); } } catch (const io_error& e) diff --git a/tests/test/script/runner/set.test b/tests/test/script/runner/set.test index aebe9cb..b90bb14 100644 --- a/tests/test/script/runner/set.test +++ b/tests/test/script/runner/set.test @@ -254,7 +254,8 @@ $c <<EOI && $b 2>>EOE != 0 set -w x baz EOI - testscript:1:1: (x):1:1: error: expected '[' instead of 'x' + <attributes>:1:1: error: expected '[' instead of 'x' + testscript:1:1: info: while parsing attributes 'x' EOE : unknown @@ -262,7 +263,8 @@ $c <<EOI && $b 2>>EOE != 0 set -w [x] baz EOI - testscript:1:1: ([x]):1:1: error: unknown value attribute x + <attributes>:1:1: error: unknown value attribute x + testscript:1:1: info: while parsing attributes '[x]' EOE : junk @@ -270,6 +272,7 @@ $c <<EOI && $b 2>>EOE != 0 set -w '[string] x' baz EOI - testscript:1:1: ([string] x):1:10: error: trailing junk after ']' + <attributes>:1:10: error: trailing junk after ']' + testscript:1:1: info: while parsing attributes '[string] x' EOE } diff --git a/unit-tests/test/script/parser/expansion.test b/unit-tests/test/script/parser/expansion.test index 0a40827..0f17f64 100644 --- a/unit-tests/test/script/parser/expansion.test +++ b/unit-tests/test/script/parser/expansion.test @@ -14,3 +14,23 @@ EOI cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} EOO + +: unterm-quoted-seq +: +$* <<EOI 2>>EOE != 0 +x = "'a bc" +cmd xy$x +EOI +<string>:1:8: error: unterminated single-quoted sequence + testscript:2:5: info: while parsing string 'xy'a bc' +EOE + +: invalid-redirect +: +$* <<EOI 2>>EOE != 0 +x = "1>&a" +cmd $x +EOI +<string>:1:4: error: stdout merge redirect file descriptor must be 2 + testscript:2:5: info: while parsing string '1>&a' +EOE |