| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // |
| 5 // Dart test program for testing native extensions. |
| 6 |
| 7 #import('dart:io'); |
| 8 |
| 9 Future copyFileToDirectory(Path file, Path directory) { |
| 10 String src = file.toNativePath(); |
| 11 String dst = directory.toNativePath(); |
| 12 switch (Platform.operatingSystem) { |
| 13 case 'linux': |
| 14 case 'macos': |
| 15 return Process.run('cp', [src, dst]); |
| 16 case 'windows': |
| 17 return Process.run('cmd.exe', ['/C', 'copy $src $dst']); |
| 18 default: |
| 19 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); |
| 20 } |
| 21 } |
| 22 |
| 23 Path getExtensionPath(Path buildDirectory) { |
| 24 switch (Platform.operatingSystem) { |
| 25 case 'linux': |
| 26 return buildDirectory.append('lib.target/libtest_extension.so'); |
| 27 case 'macos': |
| 28 return buildDirectory.append('libtest_extension.dylib'); |
| 29 case 'windows': |
| 30 return buildDirectory.append('test_extension.dll'); |
| 31 default: |
| 32 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); |
| 33 } |
| 34 } |
| 35 |
| 36 void main() { |
| 37 Options options = new Options(); |
| 38 |
| 39 Path scriptDirectory = new Path.fromNative(options.script).directoryPath; |
| 40 Path buildDirectory = new Path.fromNative(options.executable).directoryPath; |
| 41 Directory tempDirectory = new Directory('').createTempSync(); |
| 42 Path testDirectory = new Path.fromNative(tempDirectory.path); |
| 43 |
| 44 // Copy test_extension shared library, test_extension.dart and |
| 45 // test_extension_fail_tester.dart to the temporary test directory. |
| 46 copyFileToDirectory(getExtensionPath(buildDirectory), |
| 47 testDirectory).chain((_) { |
| 48 Path extensionDartFile = scriptDirectory.append('test_extension.dart'); |
| 49 return copyFileToDirectory(extensionDartFile, testDirectory); |
| 50 }).chain((_) { |
| 51 Path testExtensionTesterFile = |
| 52 scriptDirectory.append('test_extension_fail_tester.dart'); |
| 53 return copyFileToDirectory(testExtensionTesterFile, testDirectory); |
| 54 }).chain((_) { |
| 55 Path script = testDirectory.append('test_extension_fail_tester.dart'); |
| 56 return Process.run(options.executable, [script.toNativePath()]); |
| 57 })..then((ProcessResult result) { |
| 58 print("ERR: ${result.stderr}\n\n"); |
| 59 print("OUT: ${result.stdout}\n\n"); |
| 60 Expect.equals(255, result.exitCode); |
| 61 Expect.isTrue(result.stderr.contains("Unhandled exception:\nball\n")); |
| 62 tempDirectory.deleteSync(recursive: true); |
| 63 })..handleException((_) { |
| 64 tempDirectory.deleteSync(recursive: true); |
| 65 }); |
| 66 } |
| OLD | NEW |