| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart_style.test.utils; | 5 library dart_style.test.utils; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| 11 import 'package:scheduled_test/descriptor.dart' as d; | 11 import 'package:scheduled_test/descriptor.dart' as d; |
| 12 import 'package:scheduled_test/scheduled_process.dart'; | 12 import 'package:scheduled_test/scheduled_process.dart'; |
| 13 import 'package:scheduled_test/scheduled_test.dart'; | 13 import 'package:scheduled_test/scheduled_test.dart'; |
| 14 | 14 |
| 15 const unformattedSource = 'void main() => print("hello") ;'; | 15 const unformattedSource = 'void main() => print("hello") ;'; |
| 16 const formattedSource = 'void main() => print("hello");\n'; | 16 const formattedSource = 'void main() => print("hello");\n'; |
| 17 | 17 |
| 18 /// Runs the command line formatter, passing it [args]. | 18 /// Runs the command line formatter, passing it [args]. |
| 19 ScheduledProcess runFormatter([List<String> args]) { | 19 ScheduledProcess runFormatter([List<String> args]) { |
| 20 if (args == null) args = []; | 20 if (args == null) args = []; |
| 21 | 21 |
| 22 // Locate the "test" directory. Use mirrors so that this works with the test | 22 // Locate the "test" directory. Use mirrors so that this works with the test |
| 23 // package, which loads this suite into an isolate. | 23 // package, which loads this suite into an isolate. |
| 24 var testDir = p.dirname( | 24 var testDir = p.dirname(currentMirrorSystem() |
| 25 currentMirrorSystem().findLibrary(#dart_style.test.utils).uri.path); | 25 .findLibrary(#dart_style.test.utils) |
| 26 .uri |
| 27 .toFilePath()); |
| 26 | 28 |
| 27 var formatterPath = p.normalize(p.join(testDir, "../bin/format.dart")); | 29 var formatterPath = p.normalize(p.join(testDir, "../bin/format.dart")); |
| 28 | 30 |
| 29 args.insert(0, formatterPath); | 31 args.insert(0, formatterPath); |
| 30 | 32 |
| 31 // Use the same package root, if there is one. | 33 // Use the same package root, if there is one. |
| 32 if (Platform.packageRoot.isNotEmpty) { | 34 if (Platform.packageRoot != null && Platform.packageRoot.isNotEmpty) { |
| 33 args.insert(0, "--package-root=${Platform.packageRoot}"); | 35 args.insert(0, "--package-root=${Platform.packageRoot}"); |
| 36 } else if (Platform.packageConfig != null && |
| 37 Platform.packageConfig.isNotEmpty) { |
| 38 args.insert(0, "--packages=${Platform.packageConfig}"); |
| 34 } | 39 } |
| 35 | 40 |
| 36 return new ScheduledProcess.start(Platform.executable, args); | 41 return new ScheduledProcess.start(Platform.executable, args); |
| 37 } | 42 } |
| 38 | 43 |
| 39 /// Runs the command line formatter, passing it the test directory followed by | 44 /// Runs the command line formatter, passing it the test directory followed by |
| 40 /// [args]. | 45 /// [args]. |
| 41 ScheduledProcess runFormatterOnDir([List<String> args]) { | 46 ScheduledProcess runFormatterOnDir([List<String> args]) { |
| 42 if (args == null) args = []; | 47 if (args == null) args = []; |
| 43 return runFormatter([d.defaultRoot]..addAll(args)); | 48 return runFormatter([d.defaultRoot]..addAll(args)); |
| 44 } | 49 } |
| 45 | 50 |
| 46 /// Set up the scheduled test suite. | 51 /// Set up the scheduled test suite. |
| 47 /// | 52 /// |
| 48 /// Configures the unit test output and makes a sandbox directory for the | 53 /// Configures the unit test output and makes a sandbox directory for the |
| 49 /// scheduled tests to run in. | 54 /// scheduled tests to run in. |
| 50 void setUpTestSuite() { | 55 void setUpTestSuite() { |
| 51 // Make a sandbox directory for the scheduled tests to run in. | 56 // Make a sandbox directory for the scheduled tests to run in. |
| 52 setUp(() { | 57 setUp(() { |
| 53 var tempDir = Directory.systemTemp.createTempSync('dart_style.test.'); | 58 var tempDir = Directory.systemTemp.createTempSync('dart_style.test.'); |
| 54 d.defaultRoot = tempDir.path; | 59 d.defaultRoot = tempDir.path; |
| 55 | 60 |
| 56 currentSchedule.onComplete.schedule(() { | 61 currentSchedule.onComplete.schedule(() { |
| 57 d.defaultRoot = null; | 62 d.defaultRoot = null; |
| 58 return tempDir.delete(recursive: true); | 63 return tempDir.delete(recursive: true); |
| 59 }); | 64 }); |
| 60 }); | 65 }); |
| 61 } | 66 } |
| OLD | NEW |