Skip to content

Commit e15f53d

Browse files
author
John Messerly
committed
upgrade dependencies, including migration to package:test
dart_style becomes a dev_dependency, and remove the ability to auto-run it from dart backend, instead use the test formatter migrate to package:test, which has a few tricky bits: * expect can only appear inside a test now (dart-lang/test#132) * mirrors is needed to get the test folder (dart-lang/test#110) * test `main` can't take arguments. not sure what's up there, but not a big deal for us either. [email protected] Review URL: https://codereview.chromium.org/1166683005
1 parent 498ecbc commit e15f53d

21 files changed

+95
-159
lines changed

pkg/dev_compiler/lib/src/codegen/dart_codegen.dart

+1-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'package:analyzer/src/generated/ast.dart';
1111
import 'package:analyzer/src/generated/element.dart';
1212
import 'package:analyzer/src/generated/java_core.dart' as java_core;
1313
import 'package:analyzer/src/generated/scanner.dart' show Token;
14-
import 'package:dart_style/dart_style.dart';
1514
import 'package:logging/logging.dart' as logger;
1615
import 'package:path/path.dart' as path;
1716

@@ -95,7 +94,7 @@ class FileWriter extends java_core.PrintStringWriter {
9594
bool insideForLoop = false;
9695

9796
void print(x) {
98-
if (!options.cheapTestFormat) {
97+
if (!options.formatOutput) {
9998
super.print(x);
10099
return;
101100
}
@@ -133,15 +132,6 @@ class FileWriter extends java_core.PrintStringWriter {
133132

134133
void finalize() {
135134
String s = toString();
136-
if (options.formatOutput && !options.cheapTestFormat) {
137-
DartFormatter d = new DartFormatter();
138-
try {
139-
_log.fine("Formatting file $_path ");
140-
s = d.format(s, uri: _path);
141-
} catch (e) {
142-
_log.severe("Failed to format $_path: " + e.toString());
143-
}
144-
}
145135
_log.fine("Writing file $_path");
146136
new File(_path).writeAsStringSync(s);
147137
}

pkg/dev_compiler/lib/src/options.dart

+4-6
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,11 @@ class CompilerOptions implements RulesOptions, ResolverOptions, JSCodeOptions {
124124
/// Whether to force compilation of code with static errors.
125125
final bool forceCompile;
126126

127-
/// Whether to run the dart_style formatter on the generated Dart code.
127+
/// Whether to use a cheap formatter instead of dart_style.
128+
// TODO(jmesserly): old comment said this might not be a semantically correct
129+
// formatter. Why not?
128130
final bool formatOutput;
129131

130-
/// Whether to use a cheap formatter instead of dart_style. This might not be
131-
/// a semantically correct formatter and it is used for testing only.
132-
final bool cheapTestFormat;
133-
134132
/// Output directory for generated code.
135133
final String outputDir;
136134

@@ -241,7 +239,7 @@ class CompilerOptions implements RulesOptions, ResolverOptions, JSCodeOptions {
241239
CompilerOptions({this.allowConstCasts: true, this.checkSdk: false,
242240
this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir,
243241
this.forceCompile: false, this.formatOutput: false,
244-
this.cheapTestFormat: false, this.ignoreTypes: false,
242+
this.ignoreTypes: false,
245243
this.wrapClosures: RulesOptions.wrapClosuresDefault, this.outputDir,
246244
this.outputDart: false, this.useColors: true,
247245
this.covariantGenerics: true, this.relaxedCasts: true,

pkg/dev_compiler/lib/src/testing.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:analyzer/src/generated/ast.dart';
1010
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
1111
import 'package:logging/logging.dart';
1212
import 'package:source_span/source_span.dart';
13-
import 'package:unittest/unittest.dart';
13+
import 'package:test/test.dart';
1414

1515
import 'package:dev_compiler/config.dart';
1616
import 'package:dev_compiler/devc.dart' show Compiler;

pkg/dev_compiler/pubspec.yaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ author: Dart Dev Compiler team <[email protected]>
77
homepage: https://github.com/dart-lang/dev_compiler
88
dependencies:
99
analyzer: ^0.25.0
10-
args: ^0.12.1
10+
args: ">=0.12.1 <0.14.0"
1111
cli_util: ^0.0.1
1212
crypto: ^0.9.0
13-
# We pin a specific version to ensure everyone is formatting the code exactly
14-
# the same way. This is because any change in dart_style, even non-breaking
15-
# changes, may change the output format.
16-
dart_style: 0.1.8
1713
html: ^0.12.0
18-
logging: ^0.9.2
14+
logging: ">=0.9.3 <0.12.0"
1915
path: ^1.3.0
2016
shelf: ^0.6.0
2117
shelf_static: ^0.2.1
@@ -24,8 +20,12 @@ dependencies:
2420
stack_trace: ^1.1.1
2521
yaml: ^2.1.2
2622
dev_dependencies:
23+
# We pin a specific version to ensure everyone is formatting the code exactly
24+
# the same way. This is because any change in dart_style, even non-breaking
25+
# changes, may change the output format.
26+
dart_style: 0.1.8
2727
pub_semver: ^1.1.0
28-
unittest: ^0.11.0
28+
test: ^0.12.0
2929
environment:
3030
sdk: ">=1.9.0 <2.0.0"
3131
executables:

pkg/dev_compiler/test/all_tests.dart

+4-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// Meta-test that runs all tests we have written.
66
library dev_compiler.test.all_tests;
77

8-
import 'package:unittest/unittest.dart';
8+
import 'package:test/test.dart';
99

1010
import 'checker/checker_test.dart' as checker_test;
1111
import 'checker/inferred_type_test.dart' as inferred_type_test;
@@ -15,19 +15,13 @@ import 'report_test.dart' as report_test;
1515
import 'runtime/dart_runtime_test.dart' as runtime_test;
1616
import 'dependency_graph_test.dart' as dependency_graph_test;
1717

18-
import 'test_util.dart';
19-
20-
void main(args) {
21-
configureTest();
22-
18+
void main() {
2319
group('end-to-end', e2e.main);
2420
group('inferred types', inferred_type_test.main);
2521
group('checker', checker_test.main);
2622
group('report', report_test.main);
2723
group('runtime', runtime_test.main);
2824
group('dependency_graph', dependency_graph_test.main);
29-
group('codegen', () => codegen_test.main(args));
30-
var args2 = new List.from((args == null) ? [] : args, growable: true);
31-
args2.add("--dart-gen");
32-
group('dart_codegen', () => codegen_test.main(args2));
25+
group('codegen', () => codegen_test.main([]));
26+
group('dart_codegen', () => codegen_test.main(['--dart-gen']));
3327
}

pkg/dev_compiler/test/checker/checker_test.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
/// General type checking tests
66
library dev_compiler.test.checker_test;
77

8-
import 'package:unittest/unittest.dart';
8+
import 'package:test/test.dart';
99

1010
import 'package:dev_compiler/src/testing.dart';
1111

12-
import '../test_util.dart';
13-
1412
void main() {
15-
configureTest();
16-
1713
test('ternary operator', () {
1814
testChecker({
1915
'/main.dart': '''

pkg/dev_compiler/test/checker/inferred_type_test.dart

+30-31
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
/// Tests for type inference.
66
library dev_compiler.test.inferred_type_test;
77

8-
import 'package:unittest/unittest.dart';
8+
import 'package:test/test.dart';
99

1010
import 'package:dev_compiler/src/testing.dart';
1111

12-
import '../test_util.dart';
13-
1412
void main() {
15-
configureTest();
16-
1713
test('infer type on var', () {
1814
// Error also expected when declared type is `int`.
1915
testChecker({
@@ -36,34 +32,37 @@ void main() {
3632
});
3733
});
3834

39-
// Error when declared type is `int` and assigned null.
40-
testChecker({
41-
'/main.dart': '''
42-
test1() {
43-
int x = 3;
44-
x = /*severe:StaticTypeError*/null;
45-
}
46-
'''
47-
}, nonnullableTypes: <String>['int', 'double']);
35+
test('Error when declared type is `int` and assigned null.', () {
36+
testChecker({
37+
'/main.dart': '''
38+
test1() {
39+
int x = 3;
40+
x = /*severe:StaticTypeError*/null;
41+
}
42+
'''
43+
}, nonnullableTypes: <String>['int', 'double']);
44+
});
4845

49-
// Error when inferred type is `int` and assigned null.
50-
testChecker({
51-
'/main.dart': '''
52-
test1() {
53-
var x = 3;
54-
x = /*severe:StaticTypeError*/null;
55-
}
56-
'''
57-
}, nonnullableTypes: <String>['int', 'double']);
46+
test('Error when inferred type is `int` and assigned null.', () {
47+
testChecker({
48+
'/main.dart': '''
49+
test1() {
50+
var x = 3;
51+
x = /*severe:StaticTypeError*/null;
52+
}
53+
'''
54+
}, nonnullableTypes: <String>['int', 'double']);
55+
});
5856

59-
// No error when declared type is `num` and assigned null.
60-
testChecker({
61-
'/main.dart': '''
62-
test1() {
63-
num x = 3;
64-
x = null;
65-
}
66-
'''
57+
test('No error when declared type is `num` and assigned null.', () {
58+
testChecker({
59+
'/main.dart': '''
60+
test1() {
61+
num x = 3;
62+
x = null;
63+
}
64+
'''
65+
});
6766
});
6867

6968
test('do not infer type on dynamic', () {

pkg/dev_compiler/test/checker/self_host_test.dart

+5-10
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@ import 'package:cli_util/cli_util.dart' show getSdkDir;
1010
import 'package:dev_compiler/devc.dart' show Compiler;
1111
import 'package:dev_compiler/src/options.dart';
1212
import 'package:path/path.dart' as path;
13-
import 'package:unittest/unittest.dart';
14-
15-
import '../test_util.dart';
16-
17-
void main(args) {
18-
configureTest();
19-
20-
var testDir = path.absolute(path.dirname(Platform.script.path));
13+
import 'package:test/test.dart';
14+
import '../test_util.dart' show testDirectory;
2115

16+
void main() {
2217
test('checker can run on itself ', () {
2318
var options = new CompilerOptions(
24-
entryPointFile: '$testDir/../all_tests.dart',
25-
dartSdkPath: getSdkDir(args).path);
19+
entryPointFile: '$testDirectory/all_tests.dart',
20+
dartSdkPath: getSdkDir().path);
2621
new Compiler(options).run();
2722
});
2823
}

pkg/dev_compiler/test/codegen_test.dart

+7-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
1414
import 'package:args/args.dart';
1515
import 'package:logging/logging.dart' show Level;
1616
import 'package:path/path.dart' as path;
17-
import 'package:unittest/unittest.dart';
17+
import 'package:test/test.dart';
1818

1919
import 'package:dev_compiler/devc.dart';
2020
import 'package:dev_compiler/src/options.dart';
@@ -24,6 +24,8 @@ import 'package:dev_compiler/src/utils.dart'
2424
show computeHash, computeHashFromFile;
2525
import 'package:html/parser.dart' as html;
2626

27+
import 'test_util.dart' show testDirectory;
28+
2729
final ArgParser argParser = new ArgParser()
2830
..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null)
2931
..addFlag('dart-gen',
@@ -32,7 +34,6 @@ final ArgParser argParser = new ArgParser()
3234
main(arguments) {
3335
if (arguments == null) arguments = [];
3436
ArgResults args = argParser.parse(arguments);
35-
var script = Platform.script.path;
3637
var dartGen = args['dart-gen'];
3738
var filePattern = new RegExp(args.rest.length > 0 ? args.rest[0] : '.');
3839
var compilerMessages = new StringBuffer();
@@ -50,10 +51,7 @@ main(arguments) {
5051
}
5152
});
5253

53-
var testDir = path.absolute(path.dirname(script));
54-
var inputDir = dartGen
55-
? path.join(testDir, 'dart_codegen')
56-
: path.join(testDir, 'codegen');
54+
var inputDir = path.join(testDirectory, dartGen ? 'dart_codegen' : 'codegen');
5755
var actualDir = path.join(inputDir, 'actual');
5856
var paths = new Directory(inputDir)
5957
.listSync()
@@ -65,8 +63,7 @@ main(arguments) {
6563
bool serverMode: false, bool sourceMaps: false, String subDir}) {
6664
// TODO(jmesserly): add a way to specify flags in the test file, so
6765
// they're more self-contained.
68-
var runtimeDir = path.join(
69-
path.dirname(path.dirname(Platform.script.path)), 'lib', 'runtime');
66+
var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime');
7067
var options = new CompilerOptions(
7168
allowConstCasts: !dartGen,
7269
outputDir: subDir == null ? actualDir : path.join(actualDir, subDir),
@@ -75,7 +72,6 @@ main(arguments) {
7572
formatOutput: dartGen,
7673
emitSourceMaps: sourceMaps,
7774
forceCompile: checkSdk,
78-
cheapTestFormat: checkSdk,
7975
checkSdk: checkSdk,
8076
entryPointFile: entryPoint,
8177
dartSdkPath: sdkPath,
@@ -141,8 +137,8 @@ main(arguments) {
141137
// Get the test SDK. We use a checked in copy so test expectations can
142138
// be generated against a specific SDK version.
143139
var testSdk = dartGen
144-
? path.join(testDir, '..', 'tool', 'input_sdk')
145-
: path.join(testDir, 'generated_sdk');
140+
? path.join(testDirectory, '..', 'tool', 'input_sdk')
141+
: path.join(testDirectory, 'generated_sdk');
146142
var result = compile('dart:core', testSdk, checkSdk: true);
147143
var outputDir = new Directory(path.join(actualDir, 'core'));
148144
var outFile = new File(
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
library a;
2-
32
import 'package:dev_compiler/runtime/dart_logging_runtime.dart' as DEVC$RT;
4-
5-
class A {}
6-
typedef A A2A(A x);
7-
typedef dynamic D2D(dynamic x);
3+
class A {}
4+
typedef A A2A(A x);
5+
typedef dynamic D2D(dynamic x);
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
library b;
2-
32
import 'package:dev_compiler/runtime/dart_logging_runtime.dart' as DEVC$RT;
43
import 'a.dart';
5-
6-
A2A f1(A2A f) => f;
7-
D2D f2(D2D f) => f;
8-
A f3(A x) => x;
9-
dynamic f4(dynamic x) => x;
4+
A2A f1(A2A f) => f;
5+
D2D f2(D2D f) => f;
6+
A f3(A x) => x;
7+
dynamic f4(dynamic x) => x;
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
library c;
2-
32
import 'a/a.dart' as DDC$a$;
43
import 'package:dev_compiler/runtime/dart_logging_runtime.dart' as DEVC$RT;
54
import 'b.dart';
6-
7-
void bar() {
8-
f3(((__x0) => DEVC$RT.cast(__x0, dynamic, DDC$a$.A, "DynamicCast",
9-
"""line 10, column 6 of test/dart_codegen/types/c.dart: """,
10-
__x0 is DDC$a$.A, true))(f4(3)));
11-
f1(DEVC$RT.cast(f4, __CastType1, DDC$a$.A2A, "CompositeCast",
12-
"""line 11, column 6 of test/dart_codegen/types/c.dart: """,
13-
f4 is DDC$a$.A2A, false));
14-
f2(f3);
15-
}
16-
typedef dynamic __CastType1(dynamic __u2);
5+
void bar() {
6+
f3(((__x0) => DEVC$RT.cast(__x0, dynamic, DDC$a$.A, "DynamicCast", """line 10, column 6 of test/dart_codegen/types/c.dart: """, __x0 is DDC$a$.A, true))(f4(3)));
7+
f1(DEVC$RT.cast(f4, __CastType1, DDC$a$.A2A, "CompositeCast", """line 11, column 6 of test/dart_codegen/types/c.dart: """, f4 is DDC$a$.A2A, false));
8+
f2(f3);
9+
}
10+
typedef dynamic __CastType1(dynamic __u2);
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
library d;
2-
32
import 'a/a.dart' as DDC$a$;
43
import 'package:dev_compiler/runtime/dart_logging_runtime.dart' as DEVC$RT;
54
import 'b.dart';
6-
7-
void foo() {
8-
var x = f3(((__x0) => DEVC$RT.cast(__x0, dynamic, DDC$a$.A, "DynamicCast",
9-
"""line 10, column 14 of test/dart_codegen/types/d.dart: """,
10-
__x0 is DDC$a$.A, true))(f4("""hello""")));
11-
var y = f1(DEVC$RT.cast(f4, __CastType1, DDC$a$.A2A, "CompositeCast",
12-
"""line 11, column 14 of test/dart_codegen/types/d.dart: """,
13-
f4 is DDC$a$.A2A, false));
14-
var z = f2(f3);
15-
}
16-
typedef dynamic __CastType1(dynamic __u2);
5+
void foo() {
6+
var x = f3(((__x0) => DEVC$RT.cast(__x0, dynamic, DDC$a$.A, "DynamicCast", """line 10, column 14 of test/dart_codegen/types/d.dart: """, __x0 is DDC$a$.A, true))(f4("""hello""")));
7+
var y = f1(DEVC$RT.cast(f4, __CastType1, DDC$a$.A2A, "CompositeCast", """line 11, column 14 of test/dart_codegen/types/d.dart: """, f4 is DDC$a$.A2A, false));
8+
var z = f2(f3);
9+
}
10+
typedef dynamic __CastType1(dynamic __u2);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
library types;
2-
32
import 'package:dev_compiler/runtime/dart_logging_runtime.dart' as DEVC$RT;
43
import 'types/c.dart' show foo;
5-
import 'types/d.dart' show bar;
4+
import 'types/d.dart' show bar;

0 commit comments

Comments
 (0)