Chromium Code Reviews| 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 // | |
| 5 // Dart test program for testing native extensions. | |
| 4 | 6 |
| 5 #library("test_extension_test"); | 7 #import("dart:io"); |
| 8 #import("dart:isolate"); | |
| 6 | 9 |
| 7 #import('test_extension.dart'); | 10 // The following import statements, hidden in a string, fool the test script |
|
Søren Gjesse
2012/06/29 12:32:11
import -> source
| |
| 11 // tools/testing/dart/multitest.dart | |
| 12 // into copying the files into the generated_tests directory. | |
| 13 final dummyString = ''' | |
| 14 #source('test_extension_tester.dart'); | |
| 15 #source('test_extension.dart'); | |
| 16 '''; | |
| 8 | 17 |
| 9 main() { | 18 void main() { |
| 10 Expect.equals('cat 13', new Cat(13).toString(), 'new Cat(13).toString()'); | 19 Options options = new Options(); |
| 11 | 20 |
| 12 Expect.equals(3, Cat.ifNull(null, 3), 'Cat.ifNull(null, 3)'); | 21 // Make this a multitest so that the test scripts run a copy of it in |
|
Søren Gjesse
2012/06/29 12:32:11
I am not sure that I like the way you get this fil
Bill Hesse
2012/06/29 12:46:32
You are write - if this is not a multitest, then w
| |
| 13 Expect.equals(4, Cat.ifNull(4, null), 'Cat.ifNull(4, null)'); | 22 // [build directory]/generated_tests. This way, we can copy the shared |
| 14 Expect.equals(5, Cat.ifNull(5, 9), 'Cat.ifNull(5, 9)'); | 23 // library for test_extension.dart to the test directory. |
| 15 Expect.isNull(Cat.ifNull(null, null), 'Cat.ifNull(null, null)'); | 24 // The "none" case of the multitest, without the following |
| 25 // line, is the one that runs the test of the extension. | |
| 26 foo foo foo foo foo; /// 01: compile-time error | |
| 27 | |
| 28 Path testDirectory = new Path.fromNative(options.script).directoryPath; | |
| 29 Path buildDirectory = new Path.fromNative(options.executable).directoryPath; | |
| 30 | |
| 31 // Copy test_extension shared library from the build directory to the | |
| 32 // test directory. | |
| 33 Future sharedLibraryCopied; | |
| 34 // Use the platforms' copy file commands, to preserve executable privilege. | |
| 35 switch (Platform.operatingSystem) { | |
| 36 case 'linux': | |
| 37 var source = buildDirectory.append('lib.target/libtest_extension.so'); | |
| 38 sharedLibraryCopied = Process.run('cp', | |
| 39 [source.toNativePath(), | |
| 40 testDirectory.toNativePath()]); | |
| 41 break; | |
| 42 case 'macos': | |
| 43 var source = buildDirectory.append('libtest_extension.dylib'); | |
| 44 sharedLibraryCopied = Process.run('cp', | |
| 45 [source.toNativePath(), | |
| 46 testDirectory.toNativePath()]); | |
| 47 break; | |
| 48 case 'windows': | |
| 49 var source = buildDirectory.append('test_extension.dll'); | |
| 50 sharedLibraryCopied = Process.run('cmd.exe', | |
| 51 ['/C', | |
| 52 'copy ${source.toNativePath()} ${testDirectory.toNativePath()}']); | |
| 53 break; | |
| 54 default: | |
| 55 Expect.fail("Unknown operating system ${Platform.operatingSystem}"); | |
| 56 } | |
| 57 | |
| 58 sharedLibraryCopied.handleException((e) { | |
| 59 print('Copying of shared library test_extension failed.'); | |
| 60 throw e; | |
| 61 }); | |
| 62 sharedLibraryCopied.then((ignore) { | |
| 63 print('Shared library copied to test directory.'); | |
| 64 Path copiedTest = testDirectory.append("test_extension_tester.dart"); | |
| 65 var result = Process.run(options.executable, | |
| 66 [copiedTest.toNativePath()]); | |
| 67 result.then((processResult) { | |
| 68 print('Output of test_extension_tester.dart:'); | |
| 69 print(' stdout:'); | |
| 70 print(processResult.stdout); | |
| 71 print(' stderr:'); | |
| 72 print(processResult.stderr); | |
| 73 stdout.flush(); | |
| 74 exit(processResult.exitCode); | |
| 75 }); | |
| 76 }); | |
| 16 } | 77 } |
| OLD | NEW |