| 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 | 9 |
| 9 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| 10 import 'package:scheduled_test/descriptor.dart' as d; | 11 import 'package:scheduled_test/descriptor.dart' as d; |
| 11 import 'package:scheduled_test/scheduled_process.dart'; | 12 import 'package:scheduled_test/scheduled_process.dart'; |
| 12 import 'package:scheduled_test/scheduled_test.dart'; | 13 import 'package:scheduled_test/scheduled_test.dart'; |
| 13 | 14 |
| 14 const unformattedSource = 'void main() => print("hello") ;'; | 15 const unformattedSource = 'void main() => print("hello") ;'; |
| 15 const formattedSource = 'void main() => print("hello");\n'; | 16 const formattedSource = 'void main() => print("hello");\n'; |
| 16 | 17 |
| 17 /// Runs the command line formatter, passing it [args]. | 18 /// Runs the command line formatter, passing it [args]. |
| 18 ScheduledProcess runFormatter([List<String> args]) { | 19 ScheduledProcess runFormatter([List<String> args]) { |
| 19 if (args == null) args = []; | 20 if (args == null) args = []; |
| 20 | 21 |
| 21 var formatterPath = p.join("bin", "format.dart"); | 22 // Locate the "test" directory. Use mirrors so that this works with the test |
| 23 // package, which loads this suite into an isolate. |
| 24 var testDir = p.dirname( |
| 25 currentMirrorSystem().findLibrary(#dart_style.test.utils).uri.path); |
| 26 |
| 27 var formatterPath = p.normalize(p.join(testDir, "../bin/format.dart")); |
| 22 | 28 |
| 23 args.insert(0, formatterPath); | 29 args.insert(0, formatterPath); |
| 24 | 30 |
| 25 // Use the same package root, if there is one. | 31 // Use the same package root, if there is one. |
| 26 if (Platform.packageRoot.isNotEmpty) { | 32 if (Platform.packageRoot.isNotEmpty) { |
| 27 args.insert(0, "--package-root=${Platform.packageRoot}"); | 33 args.insert(0, "--package-root=${Platform.packageRoot}"); |
| 28 } | 34 } |
| 29 | 35 |
| 30 return new ScheduledProcess.start(Platform.executable, args); | 36 return new ScheduledProcess.start(Platform.executable, args); |
| 31 } | 37 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 46 setUp(() { | 52 setUp(() { |
| 47 var tempDir = Directory.systemTemp.createTempSync('dart_style.test.'); | 53 var tempDir = Directory.systemTemp.createTempSync('dart_style.test.'); |
| 48 d.defaultRoot = tempDir.path; | 54 d.defaultRoot = tempDir.path; |
| 49 | 55 |
| 50 currentSchedule.onComplete.schedule(() { | 56 currentSchedule.onComplete.schedule(() { |
| 51 d.defaultRoot = null; | 57 d.defaultRoot = null; |
| 52 return tempDir.delete(recursive: true); | 58 return tempDir.delete(recursive: true); |
| 53 }); | 59 }); |
| 54 }); | 60 }); |
| 55 } | 61 } |
| OLD | NEW |