Skip to content

Commit 72456dd

Browse files
committed
Make tool/build.dart verification a “real” test
1 parent 067ebcb commit 72456dd

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

dart_test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tags:
2+
presubmit-only:
3+
skip: "Should only be run during presubmit"

test/ensure_build_test.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@Tags(const ['presubmit-only'])
2+
3+
import 'dart:convert';
4+
import 'dart:io';
5+
6+
import 'package:test/test.dart';
7+
8+
void main() {
9+
String pkgRoot;
10+
try {
11+
pkgRoot = _runProc('git', ['rev-parse', '--show-toplevel']);
12+
var currentDir = Directory.current.resolveSymbolicLinksSync();
13+
if (pkgRoot != currentDir) {
14+
throw "Expected the git root ($pkgRoot) "
15+
"to match the current directory ($currentDir).";
16+
}
17+
} catch (e) {
18+
print("Skipping this test – git didn't run correctly");
19+
print(e);
20+
return;
21+
}
22+
23+
test("ensure local build succeeds with no changes", () {
24+
// 1 - get a list of modified `.g.dart` files - should be empty
25+
//expect(_changedGeneratedFiles(), isEmpty);
26+
27+
// 2 - run build - should be no output, since nothing should change
28+
var result = _runProc('dart', ['--checked', 'tool/build.dart']);
29+
expect(result,
30+
contains(new RegExp(r"Build: Succeeded after \S+ with \d+ outputs")));
31+
32+
// 3 - get a list of modified `.g.dart` files - should still be empty
33+
expect(_changedGeneratedFiles(), isEmpty);
34+
});
35+
}
36+
37+
final _whitespace = new RegExp(r'\s');
38+
39+
Set<String> _changedGeneratedFiles() {
40+
var output = _runProc('git', ['status', '--porcelain']);
41+
42+
return LineSplitter
43+
.split(output)
44+
.map((line) => line.split(_whitespace).last)
45+
.where((path) => path.endsWith('.g.dart'))
46+
.toSet();
47+
}
48+
49+
String _runProc(String proc, List<String> args) {
50+
var result = Process.runSync(proc, args);
51+
52+
if (result.exitCode != 0) {
53+
throw new ProcessException(proc, args, result.stderr, result.exitCode);
54+
}
55+
56+
return (result.stdout as String).trim();
57+
}

tool/travis.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ set -e
66
# Skipping this until at least we have a dev release that aligns with dart_style version
77
# $(dirname -- "$0")/ensure_dartfmt.sh
88

9-
# Run the tests.
10-
pub run test
11-
12-
# Run the build.dart file - just to make sure it works
13-
dart --checked tool/build.dart
9+
# Run the tests -- include the default-skipped presubmit tests
10+
pub run test --run-skipped
1411

1512
# Install dart_coveralls; gather and send coverage data.
1613
if [ "$COVERALLS_TOKEN" ] && [ "$TRAVIS_DART_VERSION" = "stable" ]; then

0 commit comments

Comments
 (0)