dart-lang / test

A library for writing unit tests in Dart.
https://pub.dev/packages/test
490 stars 213 forks source link

pub run --enable-experiment=non-nullable test fails #1291

Closed komuw closed 4 years ago

komuw commented 4 years ago

with this program;
main.dart

import "package:test/test.dart";

class Person {
  late int age;

  Person(this.age);
}

void main() {
  test("test something", () {
    var a = Person(45);
    expect(a.age, equals(45));
  });
}

pub fails; pub run --enable-experiment=non-nullable test main.dart

00:00 +0: loading main.dart                                                                                                                                                                                ../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/backend/stack_trace_formatter.dart:64:5: Warning: Operand of null-aware operation '??=' has type 'bool' which excludes null.
    verbose ??=
    ^
../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/backend/stack_trace_formatter.dart:65:17: Warning: Operand of null-aware operation '?.' has type 'Invoker' which excludes null.
 - 'Invoker' is from 'package:test_api/src/backend/invoker.dart' ('../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/backend/invoker.dart').
        Invoker.current?.liveTest?.test?.metadata?.verboseTrace ?? false;

../../.pub-cache/hosted/pub.dartlang.org/package_config-1.9.3/lib/src/package_config_json.dart:254:17: Warning: Operand of null-aware operation '...?' has type 'Map<String, dynamic>' which excludes null.
 - 'Map' is from 'dart:core'.
            ...?_extractExtraData(package.extraData, _packageNames),
                ^
00:01 +0 -1: loading main.dart [E]
  Failed to load "main.dart":
  Unable to spawn isolate: ../../.pub-cache/hosted/pub.dartlang.org/stream_channel-2.0.0/lib/isolate_channel.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2019, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/test_core-0.3.9/lib/src/runner/plugin/remote_platform_helpers.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/stream_channel-2.0.0/lib/src/isolate_channel.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/stream_channel-2.0.0/lib/stream_channel.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/backend/stack_trace_formatter.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/util/stack_trace_mapper.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/remote_listener.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/suite_channel_manager.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/test-1.15.1/lib/test.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file
  ^
  ../../.pub-cache/hosted/pub.dartlang.org/async-2.4.1/lib/async.dart:1:1: Error: A library can't opt out of non-nullable by default, when in nnbd-strong mode.
  // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file
  ^
00:01 +0 -1: Some tests failed.

pub --version

Pub 2.9.0-20.0.dev

dart --version

Dart VM version: 2.9.0-20.0.dev (dev) (Wed Jul 1 11:29:16 2020 +0200) on "macos_x64"

cat pubspec.yaml

name: ala
version: 0.0.1
homepage: todo

environment:
  sdk: '>=2.9.0-19.0.dev <3.0.0'

dev_dependencies:
  test: '>=1.15.1'
komuw commented 4 years ago

This appears similar to https://github.com/dart-lang/test/issues/1255 ; which seems to have been fixed??

komuw commented 4 years ago

this works though;

export DART_VM_OPTIONS='--enable-experiment=non-nullable, --no-null-safety' && \
pub run test .

https://github.com/dart-lang/sdk/issues/42465.
https://github.com/dart-lang/sdk/issues/41853
https://github.com/dart-lang/pub/pull/2542.

jakemac53 commented 4 years ago

These errors A library can't opt out of non-nullable by default, when in nnbd-strong mode. are related to the missing --no-sound-null-safety flag in pub.

The top two warnings are concerning though, I wouldn't expect to see those, cc @leafpetersen can you help explain what is happening here, should we be filing an issue on the CFE? These are not opted in libraries:

../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/backend/stack_trace_formatter.dart:65:17: Warning: Operand of null-aware operation '?.' has type 'Invoker' which excludes null.
 - 'Invoker' is from 'package:test_api/src/backend/invoker.dart' ('../../.pub-cache/hosted/pub.dartlang.org/test_api-0.2.17/lib/src/backend/invoker.dart').
        Invoker.current?.liveTest?.test?.metadata?.verboseTrace ?? false;

../../.pub-cache/hosted/pub.dartlang.org/package_config-1.9.3/lib/src/package_config_json.dart:254:17: Warning: Operand of null-aware operation '...?' has type 'Map<String, dynamic>' which excludes null.
 - 'Map' is from 'dart:core'.
            ...?_extractExtraData(package.extraData, _packageNames),
leafpetersen commented 4 years ago

@jakemac53 I believe the first two errors are spurious errors caused by the second. I believe that because the code is being run in strong mode, the CFE is compiling the code in as if it were all opted in before or concurrently with noticing that the library is not opted in.

Filed an issue here.

jakemac53 commented 4 years ago

Ok I am going to close this issue then.

Is there an issue filed somewhere on pub about the missing --no-sound-null-safety flag? @jonasfj