|
| 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 | +} |
0 commit comments