From ad766aff3a9f7a8abeadd000b144f3ad37ae1529 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 12 May 2015 15:42:40 -0700 Subject: [PATCH] migrate to pkg/test --- pubspec.yaml | 2 +- test/all.dart | 6 ++-- test/cli_test.dart | 6 ++-- test/common_test.dart | 4 +-- test/generators_test.dart | 4 +-- test/mock_test.dart | 45 ++++++++++++++++++++++++++++ test/web.html | 19 ------------ test/web_test.dart | 63 --------------------------------------- 8 files changed, 56 insertions(+), 93 deletions(-) create mode 100644 test/mock_test.dart delete mode 100644 test/web.html delete mode 100644 test/web_test.dart diff --git a/pubspec.yaml b/pubspec.yaml index 75d942e0..a1e10068 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,4 +28,4 @@ dev_dependencies: browser: ^0.10.0 ghpages_generator: ^0.2.4 grinder: ^0.7.0 - unittest: ^0.11.0 + test: ^0.12.0 diff --git a/test/all.dart b/test/all.dart index e2c7ff46..13a0d901 100644 --- a/test/all.dart +++ b/test/all.dart @@ -7,7 +7,7 @@ import 'common_test.dart' as common_test; import 'generators_test.dart' as generators_test; void main() { - cli_test.defineTests(); - common_test.defineTests(); - generators_test.defineTests(); + cli_test.main(); + common_test.main(); + generators_test.main(); } diff --git a/test/cli_test.dart b/test/cli_test.dart index a1f43487..5e437f16 100644 --- a/test/cli_test.dart +++ b/test/cli_test.dart @@ -1,7 +1,7 @@ // Copyright (c) 2014, Google Inc. 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 stagehand.cli_test; import 'dart:async'; @@ -10,10 +10,10 @@ import 'dart:io'; import 'package:stagehand/stagehand.dart'; import 'package:stagehand/src/cli_app.dart'; -import 'package:unittest/unittest.dart'; +import 'package:test/test.dart'; import 'package:usage/usage.dart'; -void defineTests() { +void main() { group('cli', () { CliApp app; CliLoggerMock logger; diff --git a/test/common_test.dart b/test/common_test.dart index 3fe762d5..ea43d521 100644 --- a/test/common_test.dart +++ b/test/common_test.dart @@ -5,9 +5,9 @@ library stagehand.common_test; import 'package:stagehand/src/common.dart'; -import 'package:unittest/unittest.dart'; +import 'package:test/test.dart'; -void defineTests() { +void main() { group('common', () { test('normalizeProjectName', () { expect(normalizeProjectName('foo.dart'), 'foo'); diff --git a/test/generators_test.dart b/test/generators_test.dart index 25829503..b9dcaaf4 100644 --- a/test/generators_test.dart +++ b/test/generators_test.dart @@ -5,9 +5,9 @@ library stagehand.generators_test; import 'package:stagehand/stagehand.dart'; -import 'package:unittest/unittest.dart'; +import 'package:test/test.dart'; -void defineTests() { +void main() { group('generators', () { generators.forEach((generator) { test(generator.id, () => validate(getGenerator(generator.id))); diff --git a/test/mock_test.dart b/test/mock_test.dart new file mode 100644 index 00000000..c3aa4fac --- /dev/null +++ b/test/mock_test.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2014, Google Inc. 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. + +library stagehand.mock_test; + +import 'dart:async'; + +import 'package:stagehand/stagehand.dart'; +import 'package:test/test.dart'; + +void main() { + for (var generator in generators) { + test(generator.id, () => _testGenerator(getGenerator(generator.id))); + } +} + +Future _testGenerator(Generator generator) async { + expect(generator.id, isNotNull); + + MockTarget target = new MockTarget(); + + // Assert that we can generate the template. + await generator.generate('foo', target); + + // Run some basic validation on the generated results. + expect(target.getFileContentsAsString('.gitignore'), isNotNull); + expect(target.getFileContentsAsString('pubspec.yaml'), isNotNull); +} + +class MockTarget extends GeneratorTarget { + Map> files = {}; + + Future createFile(String path, List contents) { + files[path] = contents; + return new Future.value(); + } + + bool hasFile(String path) => files.containsKey(path); + + String getFileContentsAsString(String path) { + if (!hasFile(path)) return null; + return new String.fromCharCodes(files[path]); + } +} diff --git a/test/web.html b/test/web.html deleted file mode 100644 index c5b4942f..00000000 --- a/test/web.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - Stagehand Tests - - - - - - - - diff --git a/test/web_test.dart b/test/web_test.dart deleted file mode 100644 index 6c87a927..00000000 --- a/test/web_test.dart +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2014, Google Inc. 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. - -library stagehand.web_test; - -import 'dart:async'; - -import 'package:stagehand/stagehand.dart'; -import 'package:unittest/html_config.dart'; -import 'package:unittest/unittest.dart'; - -import 'common_test.dart' as common_test; -import 'generators_test.dart' as generators_test; - -// TODO: get the tests running in content_shell - -void main() { - // Set up the test environment. - useHtmlConfiguration(); - - // Define the tests. - common_test.defineTests(); - generators_test.defineTests(); - defineIntegrationTests(); -} - -void defineIntegrationTests() { - group('integration', () { - generators.forEach((generator) { - test(generator.id, () => testGenerator(getGenerator(generator.id))); - }); - }); -} - -Future testGenerator(Generator generator) { - expect(generator.id, isNotNull); - - MockTarget target = new MockTarget(); - - // Assert that we can generate the template. - return generator.generate('foo', target).then((_) { - // Run some basic validation on the generated results. - expect(target.getFileContentsAsString('.gitignore'), isNotNull); - expect(target.getFileContentsAsString('pubspec.yaml'), isNotNull); - }); -} - -class MockTarget extends GeneratorTarget { - Map> files = {}; - - Future createFile(String path, List contents) { - files[path] = contents; - return new Future.value(); - } - - bool hasFile(String path) => files.containsKey(path); - - String getFileContentsAsString(String path) { - if (!hasFile(path)) return null; - return new String.fromCharCodes(files[path]); - } -}