| 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 "package:path/path.dart"; | 7 import "package:path/path.dart"; |
| 8 import "dart:async"; | 8 import "dart:async"; |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 'Unknown operating system ${Platform.operatingSystem}'); | 34 'Unknown operating system ${Platform.operatingSystem}'); |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool checkExitCode(int code) { | 38 bool checkExitCode(int code) { |
| 39 return ((code == 255) || (code == 253)); | 39 return ((code == 255) || (code == 253)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool checkStdError(String err) { | 42 bool checkStdError(String err) { |
| 43 return err.contains("Unhandled exception:") || | 43 return err.contains("Unhandled exception:") || |
| 44 err.contains( | 44 err.contains( |
| 45 "Native extension path must be absolute, or simply the file name"); | 45 "Native extension path must be absolute, or simply the file name"); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // name is either "extension" or "relative_extension" | 48 // name is either "extension" or "relative_extension" |
| 49 Future test(String name, bool checkForBall) { | 49 Future test(String name, bool checkForBall) { |
| 50 String scriptDirectory = dirname(Platform.script.toFilePath()); | 50 String scriptDirectory = dirname(Platform.script.toFilePath()); |
| 51 String buildDirectory = dirname(Platform.executable); | 51 String buildDirectory = dirname(Platform.executable); |
| 52 Directory tempDirectory = | 52 Directory tempDirectory = |
| 53 Directory.systemTemp.createTempSync('dart_test_${name}_fail'); | 53 Directory.systemTemp.createTempSync('dart_test_${name}_fail'); |
| 54 String testDirectory = tempDirectory.path; | 54 String testDirectory = tempDirectory.path; |
| 55 | 55 |
| 56 // Copy test_extension shared library, test_extension.dart and | 56 // Copy test_extension shared library, test_extension.dart and |
| 57 // test_extension_fail_tester.dart to the temporary test directory. | 57 // test_extension_fail_tester.dart to the temporary test directory. |
| 58 copyFileToDirectory(getExtensionPath(buildDirectory), | 58 copyFileToDirectory(getExtensionPath(buildDirectory), testDirectory) |
| 59 testDirectory).then((_) { | 59 .then((_) { |
| 60 var extensionDartFile = join(scriptDirectory, 'test_${name}.dart'); | 60 var extensionDartFile = join(scriptDirectory, 'test_${name}.dart'); |
| 61 return copyFileToDirectory(extensionDartFile, testDirectory); | 61 return copyFileToDirectory(extensionDartFile, testDirectory); |
| 62 }).then((_) { | 62 }).then((_) { |
| 63 var testExtensionTesterFile = | 63 var testExtensionTesterFile = |
| 64 join(scriptDirectory, 'test_${name}_fail_tester.dart'); | 64 join(scriptDirectory, 'test_${name}_fail_tester.dart'); |
| 65 return copyFileToDirectory(testExtensionTesterFile, testDirectory); | 65 return copyFileToDirectory(testExtensionTesterFile, testDirectory); |
| 66 }).then((_) { | 66 }).then((_) { |
| 67 var script = join(testDirectory, 'test_${name}_fail_tester.dart'); | 67 var script = join(testDirectory, 'test_${name}_fail_tester.dart'); |
| 68 return Process.run(Platform.executable, ['--trace-loading', script]); | 68 return Process.run(Platform.executable, ['--trace-loading', script]); |
| 69 }).then((ProcessResult result) { | 69 }).then((ProcessResult result) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 80 throw new StateError("stderr doesn't contain 'ball'."); | 80 throw new StateError("stderr doesn't contain 'ball'."); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 }).whenComplete(() => tempDirectory.deleteSync(recursive: true)); | 83 }).whenComplete(() => tempDirectory.deleteSync(recursive: true)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 main() async { | 86 main() async { |
| 87 await test("extension", true); | 87 await test("extension", true); |
| 88 await test("relative_extension", false); | 88 await test("relative_extension", false); |
| 89 } | 89 } |
| OLD | NEW |