Skip to content

Commit 7ddd756

Browse files
committed
Add a test case to verify that the pubspec version is bumped
1 parent 99c5802 commit 7ddd756

File tree

2 files changed

+54
-32
lines changed

2 files changed

+54
-32
lines changed

test/double_check_test.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2017 Google Inc. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
7+
import 'dart:io';
8+
import 'dart:convert';
9+
10+
import 'package:crypto/crypto.dart';
11+
import 'package:test/test.dart';
12+
import 'package:yaml/yaml.dart';
13+
14+
import '../tool/grind/synchronize.dart' as synchronize;
15+
16+
/// Tests that double-check that everything in the repo looks sensible.
17+
void main() {
18+
group("synchronized file is up-to-date:", () {
19+
/// The pattern of a checksum in a generated file.
20+
var checksumPattern = RegExp(r"^// Checksum: (.*)$", multiLine: true);
21+
22+
synchronize.sources.forEach((sourcePath, targetPath) {
23+
test(targetPath, () {
24+
var target = File(targetPath).readAsStringSync();
25+
var actualHash = checksumPattern.firstMatch(target)[1];
26+
27+
var source = File(sourcePath).readAsBytesSync();
28+
var expectedHash = sha1.convert(source).toString();
29+
expect(actualHash, equals(expectedHash),
30+
reason: "$targetPath is out-of-date.\n"
31+
"Run pub run grinder to update it.");
32+
});
33+
});
34+
},
35+
// Windows sees different bytes than other OSes, possibly because of
36+
// newline normalization issues.
37+
testOn: "!windows");
38+
39+
test("pubspec version matches CHANGELOG version", () {
40+
var firstLine = const LineSplitter()
41+
.convert(File("CHANGELOG.md").readAsStringSync())
42+
.first;
43+
expect(firstLine, startsWith("## "));
44+
var changelogVersion = firstLine.substring(3);
45+
46+
var pubspec = loadYaml(File("pubspec.yaml").readAsStringSync(),
47+
sourceUrl: "pubspec.yaml") as Map<Object, Object>;
48+
expect(pubspec, containsPair("version", isA<String>()));
49+
var pubspecVersion = pubspec["version"] as String;
50+
51+
expect(pubspecVersion,
52+
anyOf(equals(changelogVersion), equals("$changelogVersion-dev")));
53+
});
54+
}

test/synchronize_test.dart

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)