| 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:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "package:path/path.dart"; |
| 8 import 'dart:async'; | 9 import 'dart:async'; |
| 9 import 'dart:io'; | 10 import 'dart:io'; |
| 10 import 'dart:isolate'; | 11 import 'dart:isolate'; |
| 11 | 12 |
| 12 Future copyFileToDirectory(Path file, Path directory) { | 13 Future copyFileToDirectory(String file, String directory) { |
| 13 String src = file.toNativePath(); | |
| 14 String dst = directory.toNativePath(); | |
| 15 switch (Platform.operatingSystem) { | 14 switch (Platform.operatingSystem) { |
| 16 case 'linux': | 15 case 'linux': |
| 17 case 'macos': | 16 case 'macos': |
| 18 return Process.run('cp', [src, dst]); | 17 return Process.run('cp', [file, directory]); |
| 19 case 'windows': | 18 case 'windows': |
| 20 return Process.run('cmd.exe', ['/C', 'copy $src $dst']); | 19 return Process.run('cmd.exe', ['/C', 'copy $file $directory']); |
| 21 default: | 20 default: |
| 22 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); | 21 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); |
| 23 } | 22 } |
| 24 } | 23 } |
| 25 | 24 |
| 26 Path getExtensionPath(Path buildDirectory) { | 25 String getExtensionPath(String buildDirectory) { |
| 27 switch (Platform.operatingSystem) { | 26 switch (Platform.operatingSystem) { |
| 28 case 'linux': | 27 case 'linux': |
| 29 return buildDirectory.append('lib.target/libtest_extension.so'); | 28 return join(buildDirectory, 'lib.target', 'libtest_extension.so'); |
| 30 case 'macos': | 29 case 'macos': |
| 31 return buildDirectory.append('libtest_extension.dylib'); | 30 return join(buildDirectory, 'libtest_extension.dylib'); |
| 32 case 'windows': | 31 case 'windows': |
| 33 return buildDirectory.append('test_extension.dll'); | 32 return join(buildDirectory, 'test_extension.dll'); |
| 34 default: | 33 default: |
| 35 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); | 34 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); |
| 36 } | 35 } |
| 37 } | 36 } |
| 38 | 37 |
| 39 void main() { | 38 void main() { |
| 40 Path scriptDirectory = new Path(Platform.script).directoryPath; | 39 String scriptDirectory = dirname(Platform.script); |
| 41 Path buildDirectory = new Path(Platform.executable).directoryPath; | 40 String buildDirectory = dirname(Platform.executable); |
| 42 Directory tempDirectory = new Directory('').createTempSync(); | 41 Directory tempDirectory = new Directory('').createTempSync(); |
| 43 Path testDirectory = new Path(tempDirectory.path); | 42 String testDirectory = tempDirectory.path; |
| 44 | 43 |
| 45 // Copy test_extension shared library, test_extension.dart and | 44 // Copy test_extension shared library, test_extension.dart and |
| 46 // test_extension_tester.dart to the temporary test directory. | 45 // test_extension_tester.dart to the temporary test directory. |
| 47 copyFileToDirectory(getExtensionPath(buildDirectory), | 46 copyFileToDirectory(getExtensionPath(buildDirectory), |
| 48 testDirectory).then((_) { | 47 testDirectory).then((_) { |
| 49 Path extensionDartFile = scriptDirectory.append('test_extension.dart'); | 48 var extensionDartFile = join(scriptDirectory, 'test_extension.dart'); |
| 50 return copyFileToDirectory(extensionDartFile, testDirectory); | 49 return copyFileToDirectory(extensionDartFile, testDirectory); |
| 51 }).then((_) { | 50 }).then((_) { |
| 52 Path testExtensionTesterFile = | 51 var testExtensionTesterFile = |
| 53 scriptDirectory.append('test_extension_tester.dart'); | 52 join(scriptDirectory, 'test_extension_tester.dart'); |
| 54 return copyFileToDirectory(testExtensionTesterFile, testDirectory); | 53 return copyFileToDirectory(testExtensionTesterFile, testDirectory); |
| 55 }).then((_) { | 54 }).then((_) { |
| 56 Path script = testDirectory.append('test_extension_tester.dart'); | 55 var script = join(testDirectory, 'test_extension_tester.dart'); |
| 57 return Process.run(Platform.executable, [script.toNativePath()]); | 56 return Process.run(Platform.executable, [script]); |
| 58 })..then((ProcessResult result) { | 57 })..then((ProcessResult result) { |
| 59 Expect.equals(0, result.exitCode); | 58 Expect.equals(0, result.exitCode); |
| 60 tempDirectory.deleteSync(recursive: true); | 59 tempDirectory.deleteSync(recursive: true); |
| 61 })..catchError((_) { | 60 })..catchError((_) { |
| 62 tempDirectory.deleteSync(recursive: true); | 61 tempDirectory.deleteSync(recursive: true); |
| 63 }); | 62 }); |
| 64 } | 63 } |
| OLD | NEW |