Skip to content

[test_runner] test.py should presumably support errors in a non-entry-point library #44990

Closed
@eernstg

Description

@eernstg

I'd expect the test runner to recognize an error expectation in a library which is not the entry point, and consider an actual occurrence of such an error as a successful test run. For example:

// Store this as library 'tests/language/scratch_test.dart'.
import 'scratch_lib.dart';
main() => C();

// Store this as library 'tests/language/scratch_lib.dart'.
class C extends C {}
//    ^
// [analyzer] unspecified
// [cfe] unspecified

Running a fresh dartanalyzer from commit 65fab23, we get the following error message:

ERROR|COMPILE_TIME_ERROR|RECURSIVE_INTERFACE_INHERITANCE_EXTENDS|/usr/local/google/home/eernst/devel/dart/work/sdk/tests/language/scratch_lib.dart|1|7|1|'C' can't extend itself.

This error message should be matched by the expectation comment in scratch_lib.dart, but we still get the following outcome:

> cd $SDK_HOME
> python tools/test.py -n analyzer-asserts-strong-linux --verbose language/scratch_test
Test configuration:
    analyzer-asserts-strong-linux(architecture: x64, compiler: dart2analyzer, mode: release, runtime: none, system: linux, nnbd: strong, enable-asserts, use-sdk)
Suites tested: language
Running "dart2analyzer" command: DART_CONFIGURATION=ReleaseX64 out/ReleaseX64/dart-sdk/bin/dartanalyzer --ignore-unrecognized-flags --packages=/usr/local/google/home/eernst/devel/dart/work/sdk/.packages --format=machine --no-hints /usr/local/google/home/eernst/devel/dart/work/sdk/tests/language/scratch_test.dart

FAILED: dart2analyzer-none release_x64 language/scratch_test
Expected: Pass
Actual: CompileTimeError

--- Command "dart2analyzer" (took 02.000283s):
DART_CONFIGURATION=ReleaseX64 out/ReleaseX64/dart-sdk/bin/dartanalyzer --ignore-unrecognized-flags --packages=/usr/local/google/home/eernst/devel/dart/work/sdk/.packages --format=machine --no-hints /usr/local/google/home/eernst/devel/dart/work/sdk/tests/language/scratch_test.dart

unexpected analysis errors:
In tests/language/scratch_lib.dart:
- Line 1, column 7: COMPILE_TIME_ERROR.RECURSIVE_INTERFACE_INHERITANCE_EXTENDS
  'C' can't extend itself.

--- Re-run this test:
python tools/test.py -n analyzer-asserts-strong-linux language/scratch_test
Done dart2analyzer-none release_x64 language/scratch_test: fail

=== 0 tests passed, 1 failed ===

In other words, the test runner does not seem to expect that an error expectation comment can occur in any other library of a test than the entry point.

Motivation This can be a problem in practice: Some tests are intended to handle mixed-version programs (some libraries opt in null safety, others opt it out), and they generally need to have an entry point which is opted out (in order to avoid diagnostic messages about reverse imports, optedIn --> outedOut). Next, some errors occur in opted-in code, so they can't be in the entry point.

It is possible that the error expectation comments are supposed to work also in non-entry-point libraries of a test, in which case this issue should be labeled as type-bug. However, it could also be considered a new and possibly useful behavior, in which case it should be labeled as type-enhancement. So I haven't added any labels about this dimension.

Metadata

Metadata

Assignees

Labels

area-testCross-cutting test issues (use area- labels for specific failures; not used for package:test).

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions