OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
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.md file. | |
4 | |
5 library testing.test_dart; | |
6 | |
7 import 'dart:convert' show | |
8 JSON; | |
9 | |
10 import 'dart:io' show | |
11 Platform; | |
12 | |
13 import 'suite.dart' show | |
14 Suite; | |
15 | |
16 /// A suite that runs test.dart. | |
17 class TestDart extends Suite { | |
18 final String common; | |
19 | |
20 final String processes; | |
21 | |
22 final List<String> commandLines; | |
23 | |
24 TestDart(String name, this.common, this.processes, this.commandLines) | |
25 : super(name, "test_dart", | |
26 // This suite doesn't know what it's status file is because test.dart | |
27 // doesn't know. | |
28 null); | |
29 | |
30 factory TestDart.fromJsonMap(Uri base, Map json, String name, String kind) { | |
31 String common = json["common"] ?? ""; | |
32 // TODO(ahe): Compute this value based on number of cores. | |
33 String processes = json["processes"] ?? "-j16"; | |
34 List<String> commandLines = json["command-lines"] ?? <String>[]; | |
35 return new TestDart(name, common, processes, commandLines); | |
36 } | |
37 | |
38 void writeFirstImportOn(StringSink sink) { | |
39 sink.writeln("import 'dart:io' as io;"); | |
40 sink.writeln( | |
41 "import 'package:testing/src/stdio_process.dart' show StdioProcess;"); | |
42 } | |
43 | |
44 void writeRunCommandOn(StringSink sink) { | |
45 Uri dartVm; | |
46 if (Platform.isMacOS) { | |
47 dartVm = Uri.base.resolve("tools/sdks/mac/dart-sdk/bin/dart"); | |
48 } else if (Platform.isWindows) { | |
49 dartVm = Uri.base.resolve("tools/sdks/linux/dart-sdk/bin/dart"); | |
Johnni Winther
2017/02/14 08:22:49
linux -> win
/dart -> /dart.exe
ahe
2017/02/14 09:40:29
Done.
| |
50 } else if (Platform.isLinux) { | |
51 dartVm = Uri.base.resolve("tools/sdks/win/dart-sdk/bin/dart"); | |
Johnni Winther
2017/02/14 08:22:49
win -> linux
ahe
2017/02/14 09:40:29
Done.
| |
52 } else { | |
53 throw "Operating system not supported: ${Platform.operatingSystem}"; | |
54 } | |
55 List<String> processedArguments = <String>[]; | |
56 processedArguments.add(Uri.base.resolve( | |
57 "tools/testing/dart/package_testing_support.dart").toFilePath()); | |
58 for (String commandLine in commandLines) { | |
59 String arguments = common; | |
60 arguments += " $processes"; | |
61 arguments += " $commandLine"; | |
62 processedArguments.add(arguments); | |
63 } | |
64 String executable = JSON.encode(dartVm.toFilePath()); | |
65 String arguments = JSON.encode(processedArguments); | |
66 sink.write(""" | |
67 { | |
68 print('Running $arguments'); | |
69 StdioProcess process = await StdioProcess.run($executable, $arguments, | |
70 suppressOutput: false, timeout: null); | |
71 if (process.exitCode != 0) { | |
72 print(process.output); | |
73 io.exitCode = 1; | |
74 } | |
75 } | |
76 """); | |
77 } | |
78 | |
79 String toString() { | |
80 return "TestDart($name, ${JSON.encode(common)}, ${JSON.encode(processes)}," | |
81 " ${JSON.encode(commandLines)})"; | |
82 } | |
83 } | |
OLD | NEW |