Skip to content

Commit

Permalink
[dartdev] add --enable-experiment support to 'dart test'
Browse files Browse the repository at this point in the history
Bug: #42339
Change-Id: Ic50493b1e9af5ae626358bee1c0c145f58bb7c2c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153323
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Jaime Wren <jwren@google.com>
Reviewed-by: Jaime Wren <jwren@google.com>
  • Loading branch information
devoncarew authored and commit-bot@chromium.org committed Jul 6, 2020
1 parent 34ad5a5 commit 68bcf1b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/dartdev/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:io';
import 'package:args/args.dart';

import '../core.dart';
import '../experiments.dart';
import '../sdk.dart';

class TestCommand extends DartdevCommand<int> {
Expand Down Expand Up @@ -42,9 +43,15 @@ class TestCommand extends DartdevCommand<int> {
@override
FutureOr<int> run() async {
final command = sdk.pub;
final args = argResults.arguments.toList();

args.insertAll(0, ['run', 'test']);
final testArgs = argResults.arguments.toList();

final args = [
'run',
if (wereExperimentsSpecified)
'--$experimentFlagName=${specifiedExperiments.join(',')}',
'test',
...testArgs,
];

log.trace('$command ${args.join(' ')}');

Expand Down
22 changes: 22 additions & 0 deletions pkg/dartdev/test/commands/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,26 @@ void main() {
expect(result.stdout, contains('All tests passed!'));
expect(result.stderr, isEmpty);
}, skip: 'https://github.com/dart-lang/sdk/issues/40854');

test('--enable-experiment', () {
p = project(mainSrc: 'int get foo => 1;\n');
p.file('test/foo_test.dart', '''
import 'package:test/test.dart';
void main() {
test('', () {
int a;
a = null;
print('a is \$a.');
});
}
''');

var result = p.runSync('pub', ['get', '--offline']);
expect(result.exitCode, 0);

result = p.runSync('--enable-experiment=non-nullable',
['test', '--no-color', '--reporter', 'expanded']);
expect(result.exitCode, 1);
}, skip: 'https://github.com/dart-lang/sdk/issues/40854');
}

0 comments on commit 68bcf1b

Please sign in to comment.