OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Dart test program for testing native extensions. | 5 // Dart test program for testing native extensions. |
6 | 6 |
7 import "dart:async"; | 7 import "dart:async"; |
8 import "dart:io"; | 8 import "dart:io"; |
9 | 9 |
10 Future copyFileToDirectory(Path file, Path directory) { | 10 Future copyFileToDirectory(Path file, Path directory) { |
11 String src = file.toNativePath(); | 11 String src = file.toNativePath(); |
12 String dst = directory.toNativePath(); | 12 String dst = directory.toNativePath(); |
13 switch (Platform.operatingSystem) { | 13 switch (Platform.operatingSystem) { |
14 case 'linux': | 14 case 'linux': |
15 case 'macos': | 15 case 'macos': |
16 return Process.run('cp', [src, dst]); | 16 return Process.run('cp', [src, dst]); |
17 case 'windows': | 17 case 'windows': |
18 return Process.run('cmd.exe', ['/C', 'copy $src $dst']); | 18 return Process.run('cmd.exe', ['/C', 'copy $src $dst']); |
19 default: | 19 default: |
20 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); | 20 throw new RuntimeError( |
| 21 'Unknown operating system ${Platform.operatingSystem}'); |
21 } | 22 } |
22 } | 23 } |
23 | 24 |
24 Path getExtensionPath(Path buildDirectory) { | 25 Path getExtensionPath(Path buildDirectory) { |
25 switch (Platform.operatingSystem) { | 26 switch (Platform.operatingSystem) { |
26 case 'linux': | 27 case 'linux': |
27 return buildDirectory.append('lib.target/libtest_extension.so'); | 28 return buildDirectory.append('lib.target/libtest_extension.so'); |
28 case 'macos': | 29 case 'macos': |
29 return buildDirectory.append('libtest_extension.dylib'); | 30 return buildDirectory.append('libtest_extension.dylib'); |
30 case 'windows': | 31 case 'windows': |
31 return buildDirectory.append('test_extension.dll'); | 32 return buildDirectory.append('test_extension.dll'); |
32 default: | 33 default: |
33 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); | 34 throw new RuntimeError( |
| 35 'Unknown operating system ${Platform.operatingSystem}'); |
34 } | 36 } |
35 } | 37 } |
36 | 38 |
37 void main() { | 39 void main() { |
38 Options options = new Options(); | 40 Options options = new Options(); |
39 | 41 |
40 Path scriptDirectory = new Path(options.script).directoryPath; | 42 Path scriptDirectory = new Path(options.script).directoryPath; |
41 Path buildDirectory = new Path(options.executable).directoryPath; | 43 Path buildDirectory = new Path(options.executable).directoryPath; |
42 Directory tempDirectory = new Directory('').createTempSync(); | 44 Directory tempDirectory = new Directory('').createTempSync(); |
43 Path testDirectory = new Path(tempDirectory.path); | 45 Path testDirectory = new Path(tempDirectory.path); |
44 | 46 |
45 // Copy test_extension shared library, test_extension.dart and | 47 // Copy test_extension shared library, test_extension.dart and |
46 // test_extension_fail_tester.dart to the temporary test directory. | 48 // test_extension_fail_tester.dart to the temporary test directory. |
47 copyFileToDirectory(getExtensionPath(buildDirectory), | 49 copyFileToDirectory(getExtensionPath(buildDirectory), |
48 testDirectory).then((_) { | 50 testDirectory).then((_) { |
49 Path extensionDartFile = scriptDirectory.append('test_extension.dart'); | 51 Path extensionDartFile = scriptDirectory.append('test_extension.dart'); |
50 return copyFileToDirectory(extensionDartFile, testDirectory); | 52 return copyFileToDirectory(extensionDartFile, testDirectory); |
51 }).then((_) { | 53 }).then((_) { |
52 Path testExtensionTesterFile = | 54 Path testExtensionTesterFile = |
53 scriptDirectory.append('test_extension_fail_tester.dart'); | 55 scriptDirectory.append('test_extension_fail_tester.dart'); |
54 return copyFileToDirectory(testExtensionTesterFile, testDirectory); | 56 return copyFileToDirectory(testExtensionTesterFile, testDirectory); |
55 }).then((_) { | 57 }).then((_) { |
56 Path script = testDirectory.append('test_extension_fail_tester.dart'); | 58 Path script = testDirectory.append('test_extension_fail_tester.dart'); |
57 return Process.run(options.executable, [script.toNativePath()]); | 59 return Process.run(options.executable, [script.toNativePath()]); |
58 }).then((ProcessResult result) { | 60 }).then((ProcessResult result) { |
59 print("ERR: ${result.stderr}\n\n"); | 61 print("ERR: ${result.stderr}\n\n"); |
60 print("OUT: ${result.stdout}\n\n"); | 62 print("OUT: ${result.stdout}\n\n"); |
61 Expect.equals(255, result.exitCode); | 63 if (result.exitCode != 255) { |
62 Expect.isTrue(result.stderr.contains("Unhandled exception:")); | 64 throw new RuntimeError("bad exit code"); |
63 Expect.isTrue(result.stderr.contains("ball")); | 65 } |
| 66 if (!result.stderr.contains("Unhandled exception:")) { |
| 67 throw new RuntimeError("stderr doesn't contain unhandled exception."); |
| 68 } |
| 69 if (!result.stderr.contains("ball")) { |
| 70 throw new RuntimeError("stderr doesn't contain 'ball'."); |
| 71 } |
64 }).whenComplete(() => tempDirectory.deleteSync(recursive: true)); | 72 }).whenComplete(() => tempDirectory.deleteSync(recursive: true)); |
65 } | 73 } |
OLD | NEW |