feat(errors): enable verrors=context globally (#20576)

Signed-off-by: royalpinto007 <royalpinto007@gmail.com>
This commit is contained in:
Royal Simpson Pinto 2025-01-03 02:47:59 +05:30 committed by GitHub
parent c57da0cf59
commit 45e4a09a3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 87 additions and 52 deletions

View file

@ -400,6 +400,7 @@ extern (C++) struct Global
params.v.color = detectTerminal(); params.v.color = detectTerminal();
} }
params.v.errorPrintMode = ErrorPrintMode.printErrorContext; // Enable error context globally by default
compileEnv.versionNumber = parseVersionNumber(versionString()); compileEnv.versionNumber = parseVersionNumber(versionString());
/* Initialize date, time, and timestamp /* Initialize date, time, and timestamp

View file

@ -365,13 +365,23 @@ auto splitLines(const char[] text)
public this(const char[] text) public this(const char[] text)
{ {
this.text = text; this.text = text;
this.index = 0;
this.eolIndex = 0;
this.nextIndex = 0;
} }
public bool empty() { return index == text.length; } public bool empty() { advance(); return index >= text.length; }
public void popFront() { advance(); index = nextIndex; } public void popFront() { advance(); index = nextIndex; }
public const(char)[] front() { advance(); return text[index .. eolIndex]; } public const(char)[] front()
{
advance();
if (index > eolIndex || index >= text.length) {
return "";
}
return text[index .. eolIndex];
}
private void advance() private void advance()
{ {
@ -418,7 +428,7 @@ auto splitLines(const char[] text)
if (i + 2 < text.length && if (i + 2 < text.length &&
text[i + 1] == 0x80 && text[i + 1] == 0x80 &&
(text[i + 2] == 0xA8 || text[i + 2] == 0xA9) (text[i + 2] == 0xA8 || text[i + 2] == 0xA9)
) )
{ {
eolIndex = i; eolIndex = i;
nextIndex = i + 3; nextIndex = i + 3;
@ -430,6 +440,10 @@ auto splitLines(const char[] text)
break; break;
} }
} }
// No newline found; set indices to the end of the text
eolIndex = text.length;
nextIndex = text.length;
} }
} }

View file

@ -1,4 +1,4 @@
/* REQUIRED_ARGS: -m64 /* REQUIRED_ARGS: -verrors=simple -m64
TEST_OUTPUT: TEST_OUTPUT:
--- ---
compilable/b16976.d(33): Deprecation: foreach: loop index implicitly converted from `size_t` to `int` compilable/b16976.d(33): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`

View file

@ -1,9 +1,10 @@
// https://issues.dlang.org/show_bug.cgi?id=20643 // https://issues.dlang.org/show_bug.cgi?id=20643
// https://issues.dlang.org/show_bug.cgi?id=20644 // https://issues.dlang.org/show_bug.cgi?id=20644
// REQUIRED_ARGS: -verrors=simple
/* /*
TEST_OUTPUT: TEST_OUTPUT:
---- ----
compilable/chkformat.d(14): Deprecation: more format specifiers than 0 arguments compilable/chkformat.d(15): Deprecation: more format specifiers than 0 arguments
---- ----
*/ */
import core.stdc.stdio; import core.stdc.stdio;

View file

@ -1,9 +1,10 @@
// COMPILABLE_MATH_TEST // COMPILABLE_MATH_TEST
// PERMUTE_ARGS: // PERMUTE_ARGS:
// REQUIRED_ARGS: -verrors=simple
// EXTRA_FILES: imports/a12506.d // EXTRA_FILES: imports/a12506.d
/* TEST_OUTPUT: /* TEST_OUTPUT:
--- ---
compilable/compile1.d(230): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead compilable/compile1.d(231): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead
--- ---
*/ */

View file

@ -1,5 +1,5 @@
// PERMUTE_ARGS: // PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -wi -o- // REQUIRED_ARGS: -verrors=simple -D -Dd${RESULTS_DIR}/compilable -wi -o-
/* /*
TEST_OUTPUT: TEST_OUTPUT:

View file

@ -1,5 +1,5 @@
// PERMUTE_ARGS: // PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -wi -o- // REQUIRED_ARGS: -verrors=simple -D -Dd${RESULTS_DIR}/compilable -wi -o-
/* /*
TEST_OUTPUT: TEST_OUTPUT:

View file

@ -1,5 +1,5 @@
// PERMUTE_ARGS: // PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -wi -o- // REQUIRED_ARGS: -verrors=simple -D -Dd${RESULTS_DIR}/compilable -wi -o-
/* /*
TEST_OUTPUT: TEST_OUTPUT:
--- ---

View file

@ -1,5 +1,5 @@
// PERMUTE_ARGS: // PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -wi -o- // REQUIRED_ARGS: -verrors=simple -D -Dd${RESULTS_DIR}/compilable -wi -o-
/* /*
TEST_OUTPUT: TEST_OUTPUT:

View file

@ -1,5 +1,5 @@
/* /*
REQUIRED_ARGS: -dw REQUIRED_ARGS: -verrors=simple -dw
TEST_OUTPUT: TEST_OUTPUT:
--- ---
compilable/depmsg.d(39): Deprecation: struct `depmsg.main.Inner.A` is deprecated - With message! compilable/depmsg.d(39): Deprecation: struct `depmsg.main.Inner.A` is deprecated - With message!

View file

@ -1,5 +1,5 @@
// https://issues.dlang.org/show_bug.cgi?id=22668 // https://issues.dlang.org/show_bug.cgi?id=22668
// REQUIRED_ARGS: -verrors=simple
// Overrides with same deprecated'ness are allowed // Overrides with same deprecated'ness are allowed
class SameParent class SameParent

View file

@ -1,5 +1,5 @@
/* /*
REQUIRED_ARGS: -verrors=3 REQUIRED_ARGS: -verrors=simple -verrors=3
TEST_OUTPUT: TEST_OUTPUT:
--- ---
compilable/deprecationlimit.d(18): Deprecation: function `deprecationlimit.f` is deprecated compilable/deprecationlimit.d(18): Deprecation: function `deprecationlimit.f` is deprecated

View file

@ -1,3 +1,4 @@
// REQUIRED_ARGS: -verrors=simple
/* /*
TEST_OUTPUT: TEST_OUTPUT:
--- ---

View file

@ -1,5 +1,5 @@
/+ /+
REQUIRED_ARGS: -HC -c -o- -wi -extern-std=c++20 REQUIRED_ARGS: -verrors=simple -HC -c -o- -wi -extern-std=c++20
PERMUTE_ARGS: PERMUTE_ARGS:
TEST_OUTPUT: TEST_OUTPUT:
--- ---

View file

@ -1,8 +1,9 @@
// PERMUTE_ARGS: -inline // PERMUTE_ARGS: -inline
// REQUIRED_ARGS: -verrors=simple
/* /*
TEST_OUTPUT: TEST_OUTPUT:
--- ---
compilable/interpret3.d(6350): Deprecation: identity comparison of static arrays implicitly coerces them to slices, which are compared by reference compilable/interpret3.d(6351): Deprecation: identity comparison of static arrays implicitly coerces them to slices, which are compared by reference
--- ---
*/ */

View file

@ -1,5 +1,5 @@
/* /*
REQUIRED_ARGS: -inline -wi REQUIRED_ARGS: -verrors=simple -inline -wi
TEST_OUTPUT: TEST_OUTPUT:
--- ---
compilable/pragmainline2.d(14): Warning: cannot inline function `pragmainline2.foo` compilable/pragmainline2.d(14): Warning: cannot inline function `pragmainline2.foo`

View file

@ -1,5 +1,5 @@
// PERMUTE_ARGS: // PERMUTE_ARGS:
// REQUIRED_ARGS: -unittest -verrors=0 // REQUIRED_ARGS: -verrors=simple -unittest -verrors=0
/* /*
TEST_OUTPUT: TEST_OUTPUT:

View file

@ -1,4 +1,4 @@
// REQUIRED_ARGS: // REQUIRED_ARGS: -verrors=simple
// EXTRA_FILES: imports/a12567.d // EXTRA_FILES: imports/a12567.d
// PERMUTE_ARGS: // PERMUTE_ARGS:
/* /*

View file

@ -1,7 +1,8 @@
// https://issues.dlang.org/show_bug.cgi?id=19227 // https://issues.dlang.org/show_bug.cgi?id=19227
// REQUIRED_ARGS: -verrors=simple
/* TEST_OUTPUT: /* TEST_OUTPUT:
--- ---
compilable/test19227.d(16): Deprecation: use of complex type `cfloat` is deprecated, use `std.complex.Complex!(float)` instead compilable/test19227.d(17): Deprecation: use of complex type `cfloat` is deprecated, use `std.complex.Complex!(float)` instead
Deprecation: use of complex type `const(cfloat)` is deprecated, use `std.complex.Complex!(float)` instead Deprecation: use of complex type `const(cfloat)` is deprecated, use `std.complex.Complex!(float)` instead
--- ---
*/ */

View file

@ -1,11 +1,12 @@
// https://issues.dlang.org/show_bug.cgi?id=19609 // https://issues.dlang.org/show_bug.cgi?id=19609
// REQUIRED_ARGS: -verrors=simple
// EXTRA_FILES: imports/test19609a.d imports/test19609b.d imports/test19609c.d // EXTRA_FILES: imports/test19609a.d imports/test19609b.d imports/test19609c.d
/* /*
TEST_OUTPUT: TEST_OUTPUT:
--- ---
compilable/test19609.d(11): Deprecation: module `imports.test19609a` is deprecated compilable/test19609.d(12): Deprecation: module `imports.test19609a` is deprecated
compilable/test19609.d(12): Deprecation: module `imports.test19609b` is deprecated - hello compilable/test19609.d(13): Deprecation: module `imports.test19609b` is deprecated - hello
compilable/test19609.d(13): Deprecation: module `imports.test19609c` is deprecated compilable/test19609.d(14): Deprecation: module `imports.test19609c` is deprecated
--- ---
*/ */
import imports.test19609a; import imports.test19609a;

View file

@ -1,7 +1,8 @@
// REQUIRED_ARGS: -verrors=simple
/* TEST_OUTPUT: /* TEST_OUTPUT:
--- ---
compilable/test20063.d(10): Deprecation: function `test20063.main.f!(delegate () pure nothrow @safe => new C).f` function requires a dual-context, which is deprecated compilable/test20063.d(11): Deprecation: function `test20063.main.f!(delegate () pure nothrow @safe => new C).f` function requires a dual-context, which is deprecated
compilable/test20063.d(19): instantiated from here: `f!(delegate () pure nothrow @safe => new C)` compilable/test20063.d(20): instantiated from here: `f!(delegate () pure nothrow @safe => new C)`
--- ---
*/ */

View file

@ -1,15 +1,16 @@
// https://issues.dlang.org/show_bug.cgi?id=21514 // https://issues.dlang.org/show_bug.cgi?id=21514
// REQUIRED_ARGS: -verrors=simple
// DISABLED: win32 win64 // DISABLED: win32 win64
/* TEST_OUTPUT: /* TEST_OUTPUT:
--- ---
compilable/test21514.d(16): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead compilable/test21514.d(17): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead
compilable/test21514.d(16): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead compilable/test21514.d(17): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead
compilable/test21514.d(17): Deprecation: use of complex type `creal` is deprecated, use `std.complex.Complex!(real)` instead compilable/test21514.d(18): Deprecation: use of complex type `creal` is deprecated, use `std.complex.Complex!(real)` instead
compilable/test21514.d(17): Deprecation: use of complex type `creal` is deprecated, use `std.complex.Complex!(real)` instead compilable/test21514.d(18): Deprecation: use of complex type `creal` is deprecated, use `std.complex.Complex!(real)` instead
compilable/test21514.d(19): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead compilable/test21514.d(20): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead
compilable/test21514.d(19): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead compilable/test21514.d(20): Deprecation: use of complex type `cdouble` is deprecated, use `std.complex.Complex!(double)` instead
compilable/test21514.d(20): Deprecation: use of complex type `creal` is deprecated, use `std.complex.Complex!(real)` instead compilable/test21514.d(21): Deprecation: use of complex type `creal` is deprecated, use `std.complex.Complex!(real)` instead
compilable/test21514.d(20): Deprecation: use of complex type `creal` is deprecated, use `std.complex.Complex!(real)` instead compilable/test21514.d(21): Deprecation: use of complex type `creal` is deprecated, use `std.complex.Complex!(real)` instead
--- ---
*/ */

View file

@ -1,5 +1,5 @@
/* https://issues.dlang.org/show_bug.cgi?id=23097 /* https://issues.dlang.org/show_bug.cgi?id=23097
REQUIRED_ARGS: -verrors=spec REQUIRED_ARGS: -verrors=simple -verrors=spec
TEST_OUTPUT: TEST_OUTPUT:
--- ---
(spec:2) compilable/test23097.d(14): Error: `inout` constructor `test23097.S23097.this` creates const object, not mutable (spec:2) compilable/test23097.d(14): Error: `inout` constructor `test23097.S23097.this` creates const object, not mutable

View file

@ -1,11 +1,12 @@
// REQUIRED_ARGS: -verrors=simple
/* TEST_OUTPUT: /* TEST_OUTPUT:
--- ---
compilable/test324.d(17): Deprecation: function `test324.main.doStuff!((i) compilable/test324.d(18): Deprecation: function `test324.main.doStuff!((i)
{ {
return i; return i;
} }
).doStuff` function requires a dual-context, which is deprecated ).doStuff` function requires a dual-context, which is deprecated
compilable/test324.d(23): instantiated from here: `doStuff!((i) compilable/test324.d(24): instantiated from here: `doStuff!((i)
{ {
return i; return i;
} }

View file

@ -1,9 +1,10 @@
// https://issues.dlang.org/show_bug.cgi?id=9701 // https://issues.dlang.org/show_bug.cgi?id=9701
// REQUIRED_ARGS: -verrors=simple
/* /*
TEST_OUTPUT: TEST_OUTPUT:
--- ---
compilable/test9701.d(68): Deprecation: enum member `test9701.Enum.value7` is deprecated compilable/test9701.d(69): Deprecation: enum member `test9701.Enum.value7` is deprecated
compilable/test9701.d(68): Deprecation: enum member `test9701.Enum.value8` is deprecated - message compilable/test9701.d(69): Deprecation: enum member `test9701.Enum.value8` is deprecated - message
--- ---
*/ */

View file

@ -15,17 +15,24 @@ compare()
fi fi
} }
normalize() { tr -d "\n\r" ; } normalize()
{
if uname | grep -qi "freebsd"; then
tr -d "\n\r" | sed 's/void foo() {} void main() { goo(); }//; s/[[:space:]]\+\^$//'
else
tr -d "\n\r" | sed -E 's/void foo\(\) \{\} void main\(\) \{ goo\(\); \}//; s/\s+\^$//'
fi
}
check() check()
{ {
local actual expected local actual expected
actual=$(echo "$2" | ("$DMD" -c -o- "$1" - 2>&1 || true) | normalize) actual=$(echo "$2" | ("$DMD" -c -o- -verrors=simple "$1" - 2>&1 || true) | normalize)
compare "$actual" "$3" compare "$actual" "$3"
} }
expectedWithoutColor=__stdin.d\(2\):\ Error:\ no\ identifier\ for\ declarator\ \`test\` expectedWithoutColor='__stdin.d(2): Error: no identifier for declarator `test`'
expectedWithColor=$'\033'\[1m__stdin.d\(2\):\ $'\033'\[1\;31mError:\ $'\033'\[mno\ identifier\ for\ declarator\ \`$'\033'\[0\;36m$'\033'\[m$'\033'\[1mtest$'\033'\[0\;36m$'\033'\[m\` expectedWithColor=$'\033[1m__stdin.d(2): \033[1;31mError: \033[mno identifier for declarator `\033[0;36m\033[m\033[1mtest\033[0;36m\033[m`'
check -c "test" "$expectedWithoutColor" check -c "test" "$expectedWithoutColor"
check -color=auto "test" "$expectedWithoutColor" check -color=auto "test" "$expectedWithoutColor"
@ -40,7 +47,7 @@ check -color=off "$gooCode" "$gooExpectedWithoutColor"
if [[ "$(script --version)" == script\ from\ util-linux\ * ]] if [[ "$(script --version)" == script\ from\ util-linux\ * ]]
then then
actual="$(SHELL="$(command -v bash)" TERM="faketerm" script -q -c "echo test | ( $DMD -c -o- -)" /dev/null | normalize)" || true actual="$(SHELL="$(command -v bash)" TERM="faketerm" script -q -c "echo test | ( $DMD -c -o- -verrors=simple -)" /dev/null | normalize)" || true
# Weird results for WSL, probably some environmental issue # Weird results for WSL, probably some environmental issue
if uname -a | grep -i linux | grep -i microsoft &> /dev/null if uname -a | grep -i linux | grep -i microsoft &> /dev/null

View file

@ -1,4 +1,4 @@
// REQUIRED_ARGS: // REQUIRED_ARGS: -verrors=simple
// PERMUTE_ARGS: // PERMUTE_ARGS:
// EXTRA_FILES: imports/udamodule1.d // EXTRA_FILES: imports/udamodule1.d
/* /*

View file

@ -1,6 +1,6 @@
/* /*
PERMUTE_ARGS: PERMUTE_ARGS:
REQUIRED_ARGS: -verrors=spec REQUIRED_ARGS: -verrors=simple -verrors=spec
TEST_OUTPUT: TEST_OUTPUT:
--- ---
(spec:1) compilable/verrors_spec.d(13): Error: cannot implicitly convert expression `& i` of type `int*` to `int` (spec:1) compilable/verrors_spec.d(13): Error: cannot implicitly convert expression `& i` of type `int*` to `int`

View file

@ -1,8 +1,9 @@
/* PERMUTE_ARGS: /* PERMUTE_ARGS:
REQUIRED_ARGS: -verrors=simple
TEST_OUTPUT: TEST_OUTPUT:
--- ---
runnable/future.d(16): Deprecation: method `future.B.msg` implicitly overrides `@__future` base class method; rename the former runnable/future.d(17): Deprecation: method `future.B.msg` implicitly overrides `@__future` base class method; rename the former
runnable/future.d(11): base method `future.A.msg` defined here runnable/future.d(12): base method `future.A.msg` defined here
--- ---
*/ */

View file

@ -1,8 +1,9 @@
/* /*
REQUIRED_ARGS: -verrors=simple
TEST_OUTPUT: TEST_OUTPUT:
--- ---
runnable/implicit.d(162): Deprecation: slice of static array temporary returned by `pureMaker3c()` assigned to longer lived variable `z1` runnable/implicit.d(163): Deprecation: slice of static array temporary returned by `pureMaker3c()` assigned to longer lived variable `z1`
runnable/implicit.d(163): Deprecation: slice of static array temporary returned by `pureMaker3c()` assigned to longer lived variable `z2` runnable/implicit.d(164): Deprecation: slice of static array temporary returned by `pureMaker3c()` assigned to longer lived variable `z2`
--- ---
RUN_OUTPUT: RUN_OUTPUT:

View file

@ -1,4 +1,4 @@
// REQUIRED_ARGS: // REQUIRED_ARGS: -verrors=simple
/* /*
TEST_OUTPUT: TEST_OUTPUT:
--- ---

View file

@ -1,5 +1,5 @@
// PERMUTE_ARGS: -inline // PERMUTE_ARGS: -inline
// REQUIRED_ARGS: -verrors=0 // REQUIRED_ARGS: -verrors=simple -verrors=0
/* TEST_OUTPUT: /* TEST_OUTPUT:
--- ---
runnable/template10.d(89): Deprecation: function `template10.test1b.f0.f!(a).f` function requires a dual-context, which is deprecated runnable/template10.d(89): Deprecation: function `template10.test1b.f0.f!(a).f` function requires a dual-context, which is deprecated

View file

@ -1,7 +1,8 @@
/* /*
REQUIRED_ARGS: -verrors=simple
TEST_OUTPUT: TEST_OUTPUT:
--- ---
runnable/test8.d(261): Deprecation: identity comparison of static arrays implicitly coerces them to slices, which are compared by reference runnable/test8.d(262): Deprecation: identity comparison of static arrays implicitly coerces them to slices, which are compared by reference
--- ---
*/ */

View file

@ -687,7 +687,7 @@ bool gatherTestParameters(ref TestArgs testArgs, string input_dir, string input_
// tests can override -verrors by using REQUIRED_ARGS // tests can override -verrors by using REQUIRED_ARGS
if (testArgs.mode == TestMode.FAIL_COMPILE) if (testArgs.mode == TestMode.FAIL_COMPILE)
testArgs.requiredArgs = "-verrors=0 " ~ testArgs.requiredArgs; testArgs.requiredArgs = "-verrors=simple -verrors=0 " ~ testArgs.requiredArgs;
{ {
string argSetsStr; string argSetsStr;