| // Copyright (c) 2023, 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') |
| library; |
| |
| import 'dart:io'; |
| |
| import 'package:firehose/src/health/license.dart'; |
| import 'package:test/test.dart'; |
| import 'package:test_descriptor/test_descriptor.dart' as d; |
| |
| void main() { |
| group('getFilesWithoutLicenses', () { |
| test('finds files missing licenses', () async { |
| await d.file('with.dart', '// Copyright (c) 2023\n').create(); |
| await d.file('without.dart', '').create(); |
| |
| final result = await getFilesWithoutLicenses( |
| Directory(d.sandbox), [], '// Copyright'); |
| expect(result, ['without.dart']); |
| }); |
| |
| test('ignores .dart_tool directory', () async { |
| await d.dir('.dart_tool', [ |
| d.file('some_file.dart', ''), |
| ]).create(); |
| |
| final result = await getFilesWithoutLicenses( |
| Directory(d.sandbox), [], '// Copyright'); |
| expect(result, isEmpty); |
| }); |
| |
| test('supports %YEAR% wildcard', () async { |
| await d.file('2023.dart', '// Copyright (c) 2023\n').create(); |
| await d.file('2024.dart', '// Copyright (c) 2024\n').create(); |
| await d.file('invalid.dart', '// Copyright (c) year\n').create(); |
| |
| final result = await getFilesWithoutLicenses( |
| Directory(d.sandbox), [], '// Copyright (c) %YEAR%'); |
| expect(result, ['invalid.dart']); |
| }); |
| |
| test('ignores generated files', () async { |
| await d.file('gen.g.dart', '').create(); |
| await d |
| .file('gen_comment.dart', '// This file was generated by tool') |
| .create(); |
| await d |
| .file('gen_comment_2.dart', '// GENERATED FILE. DO NOT EDIT.') |
| .create(); |
| |
| final result = await getFilesWithoutLicenses( |
| Directory(d.sandbox), [], '// Copyright'); |
| expect(result, isEmpty); |
| }); |
| }); |
| |
| group('fileIsGenerated', () { |
| test('detects .g.dart', () { |
| expect(fileIsGenerated('', 'foo.g.dart'), isTrue); |
| }); |
| |
| test('detects "generate" in header', () { |
| expect(fileIsGenerated('// This was generated', 'foo.dart'), isTrue); |
| expect(fileIsGenerated('// Please generate this', 'foo.dart'), isTrue); |
| }); |
| |
| test('detects "generated" in header', () { |
| expect(fileIsGenerated('// This file is generated', 'foo.dart'), isTrue); |
| }); |
| |
| test('ignores "generated" in body', () { |
| expect(fileIsGenerated('\n\nvar x = "generated";', 'foo.dart'), isFalse); |
| }); |
| }); |
| } |