Skip to content

Commit

Permalink
Test to validate copyright headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
pq committed Feb 16, 2018
1 parent eb08d64 commit 78898ca
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/rules/avoid_relative_lib_imports.dart
@@ -1,4 +1,4 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// 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.

Expand Down
4 changes: 4 additions & 0 deletions lib/src/util/condition_scope_visitor.dart
@@ -1,3 +1,7 @@
// 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.

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
Expand Down
2 changes: 2 additions & 0 deletions test/all.dart
Expand Up @@ -10,6 +10,7 @@ import 'integration_test.dart' as integration_test;
import 'mocks.dart';
import 'rule_test.dart' as rule_test;
import 'utils_test.dart' as utils_test;
import 'validate_headers_test.dart' as validate_headers;

main() {
// Redirect output.
Expand All @@ -20,4 +21,5 @@ main() {
integration_test.main();
rule_test.main();
utils_test.main();
validate_headers.main();
}
38 changes: 38 additions & 0 deletions test/validate_headers_test.dart
@@ -0,0 +1,38 @@
// 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.

import 'dart:async';
import 'dart:io';

import 'package:test/test.dart';

main() {
group('check for copyright headers', () {
test('... in lib', () async {
await validate('lib');
});
test('... in tool', () async {
await validate('tool');
});
});
}

Future validate(String dir) async {
List<String> violations = <String>[];
await for (FileSystemEntity entity
in new Directory(dir).list(recursive: true, followLinks: false)) {
if (entity is File && entity.path.endsWith('.dart')) {
RandomAccessFile file = await entity.open();
List<int> bytes = await file.read(40);
String header = new String.fromCharCodes(bytes);
if (!header.startsWith(
new RegExp('// Copyright \\(c\\) 20[0-9][0-9], the Dart project'))) {
violations.add(entity.path);
}
}
}
expect(violations, isEmpty, reason: '''Files missing copyright headers.
See CONTRIBUTING.md for format details.''');
}

0 comments on commit 78898ca

Please sign in to comment.