Skip to content

Fix ensure_build_test #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
env: PKG="example"
dart: dev
- stage: unit_test
script: ./tool/travis.sh test
script: ./tool/travis.sh test_0
env: PKG="example"
dart: dev
- stage: analyzer_and_format
Expand All @@ -42,7 +42,11 @@ jobs:
env: PKG="json_serializable"
dart: dev
- stage: unit_test
script: ./tool/travis.sh test
script: ./tool/travis.sh test_1
env: PKG="json_serializable"
dart: dev
- stage: unit_test
script: ./tool/travis.sh test_2
env: PKG="json_serializable"
dart: dev
- stage: unit_test
Expand Down
3 changes: 2 additions & 1 deletion json_serializable/.mono_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ stages:
- dartanalyzer: --fatal-infos --fatal-warnings .
- unit_test:
# Run the tests -- include the default-skipped presubmit tests
- test: --run-skipped
- test
- test: --run-skipped test/ensure_build_test.dart
- command: pub run build_runner test -- -p chrome
50 changes: 6 additions & 44 deletions json_serializable/test/ensure_build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,15 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
@Tags(const ['presubmit-only'])

import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:test/test.dart';

String _getExampleContent(String fileName) {
var lines = new File(p.join('example', fileName)).readAsLinesSync();

var lastHadContent = false;

// All lines with content, except those starting with `/`.
// Also exclude blank lines that follow other blank lines
var cleanedSource = lines.where((l) {
if (l.startsWith(r'/')) {
return false;
}

if (l.trim().isNotEmpty) {
lastHadContent = true;
return true;
}

if (lastHadContent) {
lastHadContent = false;
return true;
}

return false;
}).join('\n');

return '''
```dart
$cleanedSource
```''';
}

void main() {
test('README example', () {
var readmeContent = new File('README.md').readAsStringSync();

var exampleContent = _getExampleContent('example.dart');
expect(readmeContent, contains(exampleContent));

var exampleGeneratedContent = _getExampleContent('example.g.dart');
expect(readmeContent, contains(exampleGeneratedContent));
});

// TODO(kevmoo): replace with a common utility
// https://github.com/dart-lang/build/issues/716
test('ensure local build succeeds with no changes', () {
Expand All @@ -67,14 +27,16 @@ void main() {
expect(_changedGeneratedFiles(), isEmpty);

// 2 - run build - should be no output, since nothing should change
var result = _runProc('pub',
['run', 'build_runner', 'build', '--delete-conflicting-outputs']);
var result = _runProc(
'dart', ['tool/build.dart', 'build', '--delete-conflicting-outputs']);

print(result);
expect(result,
contains(new RegExp(r'\[INFO\] Succeeded after \S+ with \d+ outputs')));

// 3 - get a list of modified `.g.dart` files - should still be empty
expect(_changedGeneratedFiles(), isEmpty);
}, tags: 'presubmit-only');
});
}

final _whitespace = new RegExp(r'\s');
Expand Down
53 changes: 53 additions & 0 deletions json_serializable/test/readme_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')

import 'dart:io';

import 'package:test/test.dart';
import 'package:path/path.dart' as p;

void main() {
test('README example', () {
var readmeContent = new File('README.md').readAsStringSync();

var exampleContent = _getExampleContent('example.dart');
expect(readmeContent, contains(exampleContent));

var exampleGeneratedContent = _getExampleContent('example.g.dart');
expect(readmeContent, contains(exampleGeneratedContent));
});
}

String _getExampleContent(String fileName) {
var lines = new File(p.join('example', fileName)).readAsLinesSync();

var lastHadContent = false;

// All lines with content, except those starting with `/`.
// Also exclude blank lines that follow other blank lines
var cleanedSource = lines.where((l) {
if (l.startsWith(r'/')) {
return false;
}

if (l.trim().isNotEmpty) {
lastHadContent = true;
return true;
}

if (lastHadContent) {
lastHadContent = false;
return true;
}

return false;
}).join('\n');

return '''
```dart
$cleanedSource
```''';
}
14 changes: 12 additions & 2 deletions tool/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ while (( "$#" )); do
echo -e 'dartfmt -n --set-exit-if-changed .'
dartfmt -n --set-exit-if-changed . || EXIT_CODE=$?
;;
test) echo
echo -e '\033[1mTASK: test\033[22m'
test_0) echo
echo -e '\033[1mTASK: test_0\033[22m'
echo -e 'pub run test --run-skipped'
pub run test --run-skipped || EXIT_CODE=$?
;;
test_1) echo
echo -e '\033[1mTASK: test_1\033[22m'
echo -e 'pub run test'
pub run test || EXIT_CODE=$?
;;
test_2) echo
echo -e '\033[1mTASK: test_2\033[22m'
echo -e 'pub run test --run-skipped test/ensure_build_test.dart'
pub run test --run-skipped test/ensure_build_test.dart || EXIT_CODE=$?
;;
*) echo -e "\033[31mNot expecting TASK '${TASK}'. Error!\033[0m"
EXIT_CODE=1
;;
Expand Down