test_test.dart 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright 2015 The Chromium Authors. 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:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import 'src/context.dart';

// This test depends on some files in ///dev/automated_tests/flutter_test/*

void main() {
  group('test', () {
    testUsingContext('TestAsyncUtils guarded function test', () async {
      Cache.flutterRoot = '../..';
21
      return _testFile('test_async_utils_guarded', 1);
22 23 24
    });
    testUsingContext('TestAsyncUtils unguarded function test', () async {
      Cache.flutterRoot = '../..';
25
      return _testFile('test_async_utils_unguarded', 1);
26 27 28 29
    });
  }, timeout: new Timeout(const Duration(seconds: 5)));
}

30
Future<Null> _testFile(String testName, int wantedExitCode) async {
31 32 33 34 35 36 37 38 39 40 41 42
  final String manualTestsDirectory = path.join('..', '..', 'dev', 'automated_tests');
  final String fullTestName = path.join(manualTestsDirectory, 'flutter_test', '${testName}_test.dart');
  final File testFile = new File(fullTestName);
  expect(testFile.existsSync(), true);
  final String fullTestExpectation = path.join(manualTestsDirectory, 'flutter_test', '${testName}_expectation.txt');
  final File expectationFile = new File(fullTestExpectation);
  expect(expectationFile.existsSync(), true);
  final ProcessResult exec = await Process.run(
    path.join(dartSdkPath, 'bin', 'dart'),
    <String>[
      path.absolute(path.join('bin', 'flutter_tools.dart')),
      'test',
43
      '--no-color',
44 45 46 47
      fullTestName
    ],
    workingDirectory: manualTestsDirectory
  );
48
  expect(exec.exitCode, wantedExitCode);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  final List<String> output = exec.stdout.split('\n');
  final List<String> expectations = new File(fullTestExpectation).readAsLinesSync();
  bool allowSkip = false;
  int expectationLineNumber = 0;
  int outputLineNumber = 0;
  while (expectationLineNumber < expectations.length) {
    expect(output, hasLength(greaterThan(outputLineNumber)));
    final String expectationLine = expectations[expectationLineNumber];
    final String outputLine = output[outputLineNumber];
    if (expectationLine == '<<skip until matching line>>') {
      allowSkip = true;
      expectationLineNumber += 1;
      continue;
    }
    if (allowSkip) {
      if (!new RegExp(expectationLine).hasMatch(outputLine)) {
        outputLineNumber += 1;
        continue;
      }
      allowSkip = false;
    }
    expect(outputLine, matches(expectationLine));
    expectationLineNumber += 1;
    outputLineNumber += 1;
  }
  expect(allowSkip, isFalse);
  expect(exec.stderr, '');
}