template_manifest_test.dart 1.34 KB
Newer Older
1 2 3 4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:file/file.dart';
6 7
import 'package:flutter_tools/src/convert.dart';
import '../src/common.dart';
8
import 'test_utils.dart';
9

10
/// Checks that all active template files are defined in the template_manifest.json file.
11
void main() {
12
  testWithoutContext('Check template manifest is up to date', () {
13
    final Map<String, Object?> manifest = json.decode(
14
      fileSystem.file('templates/template_manifest.json').readAsStringSync(),
15
    ) as Map<String, Object?>;
16
    final Set<Uri> declaredFileList = Set<Uri>.from(
17
      (manifest['files'] as List<Object?>?)!.cast<String>().map<Uri>(fileSystem.path.toUri));
18

19
    final Set<Uri> activeTemplateList = fileSystem.directory('templates')
20 21
      .listSync(recursive: true)
      .whereType<File>()
22
      .where((File file) => fileSystem.path.basename(file.path) != 'template_manifest.json' &&
23
        fileSystem.path.basename(file.path) != 'README.md' &&
24
        fileSystem.path.basename(file.path) != '.DS_Store')
25 26 27 28 29 30 31 32
      .map((File file) => file.uri)
      .toSet();

    final Set<Uri> difference = activeTemplateList.difference(declaredFileList);

    expect(difference, isEmpty, reason: 'manifest and template directory should be in-sync');
  });
}