Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: samples/sample_extension/test/sample_extension_test_helper.dart

Issue 2709713002: Reenable some sample tests and fix how they find their data files (Closed)
Patch Set: Feedback Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import 'dart:isolate'; 9 import 'dart:isolate';
10 10
11 import "package:expect/expect.dart"; 11 import "package:expect/expect.dart";
12 import "package:path/path.dart"; 12 import "package:path/path.dart";
13 13
14 Future copyFileToDirectory(String file, String directory) { 14 Future copyFileToDirectory(String file, String directory) async {
15 String src = file; 15 String src = file;
16 String dst = directory; 16 String dst = directory;
17 ProcessResult result;
17 switch (Platform.operatingSystem) { 18 switch (Platform.operatingSystem) {
18 case 'linux': 19 case 'linux':
19 case 'macos': 20 case 'macos':
20 return Process.run('cp', [src, dst]); 21 result = await Process.run('cp', [src, dst]);
22 break;
21 case 'windows': 23 case 'windows':
22 return Process.run('cmd.exe', ['/C', 'copy $src $dst']); 24 result = await Process.run('cmd.exe', ['/C', 'copy $src $dst']);
25 break;
23 default: 26 default:
24 Expect.fail('Unknown operating system ${Platform.operatingSystem}'); 27 Expect.fail('Unknown operating system ${Platform.operatingSystem}');
25 } 28 }
26 } 29 if (result.exitCode != 0) {
27 30 print(result.stdout);
28 String getNativeLibraryPath(String buildDirectory) { 31 print(result.stderr);
29 switch (Platform.operatingSystem) { 32 throw "Failed to copy test file ($file) to temporary directory ($directory)" ;
30 case 'linux':
31 return join(buildDirectory, 'lib.target', 'libsample_extension.so');
32 case 'macos':
33 return join(buildDirectory, 'libsample_extension.dylib');
34 case 'windows':
35 return join(buildDirectory, 'sample_extension.dll');
36 default:
37 Expect.fail('Unknown operating system ${Platform.operatingSystem}');
38 } 33 }
39 } 34 }
40 35
41 Future run(String program, List arguments) async { 36 Future run(String program, List arguments) async {
42 print("+ $program ${arguments.join(' ')}"); 37 print("+ $program ${arguments.join(' ')}");
43 ProcessResult result = await Process.run(program, arguments); 38 ProcessResult result = await Process.run(program, arguments);
44 if (result.exitCode != 0) { 39 if (result.exitCode != 0) {
45 print('Failing process stdout: ${result.stdout}'); 40 print('Failing process stdout: ${result.stdout}');
46 print('Failing process stderr: ${result.stderr}'); 41 print('Failing process stderr: ${result.stderr}');
47 print('End failing process stderr'); 42 print('End failing process stderr');
48 Expect.fail('Test failed with exit code ${result.exitCode}'); 43 Expect.fail('Test failed with exit code ${result.exitCode}');
49 } 44 }
50 } 45 }
51 46
52 Future testNativeExtensions(String snapshotKind) async { 47 Future testNativeExtensions(String snapshotKind) async {
53 String buildDirectory = dirname(Platform.executable); 48 String buildDirectory = dirname(Platform.executable);
54 Directory tempDirectory = 49 Directory tempDirectory =
55 Directory.systemTemp.createTempSync('sample_extension_'); 50 Directory.systemTemp.createTempSync('sample_extension_');
56 try { 51 try {
57 String testDirectory = tempDirectory.path; 52 String testDirectory = tempDirectory.path;
58 String sourceDirectory = Platform.script.resolve('..').toFilePath(); 53 String sourceDirectory = Platform.script.resolve('..').toFilePath();
59 54
60 // Copy sample_extension shared library, sample_extension dart files and 55 // Copy sample_extension dart files and sample_extension tests to the
61 // sample_extension tests to the temporary test directory. 56 // temporary test directory.
62 await copyFileToDirectory(getNativeLibraryPath(buildDirectory),
63 testDirectory);
64 for (var file in ['sample_synchronous_extension.dart', 57 for (var file in ['sample_synchronous_extension.dart',
65 'sample_asynchronous_extension.dart', 58 'sample_asynchronous_extension.dart',
66 'test_sample_synchronous_extension.dart', 59 'test_sample_synchronous_extension.dart',
67 'test_sample_asynchronous_extension.dart']) { 60 'test_sample_asynchronous_extension.dart']) {
68 await copyFileToDirectory(join(sourceDirectory, file), testDirectory); 61 await copyFileToDirectory(join(sourceDirectory, file), testDirectory);
69 } 62 }
70 63
71 for (var test in ['test_sample_synchronous_extension.dart', 64 for (var test in ['test_sample_synchronous_extension.dart',
72 'test_sample_asynchronous_extension.dart']) { 65 'test_sample_asynchronous_extension.dart']) {
73 String script = join(testDirectory, test); 66 String script = join(testDirectory, test);
74 String snapshot; 67 String snapshot;
75 if (snapshotKind == null) { 68 if (snapshotKind == null) {
76 snapshot = script; 69 snapshot = script;
77 } else { 70 } else {
78 snapshot = join(testDirectory, "$test.snapshot"); 71 snapshot = join(testDirectory, "$test.snapshot");
79 await run(Platform.executable, 72 await run(Platform.executable,
80 ['--snapshot=$snapshot', 73 ['--snapshot=$snapshot',
81 '--snapshot-kind=$snapshotKind', 74 '--snapshot-kind=$snapshotKind',
82 script]); 75 script]);
83 } 76 }
84 77
85 await run(Platform.executable, [snapshot]); 78 await run(Platform.executable, [snapshot]);
86 } 79 }
87 } finally { 80 } finally {
88 await tempDirectory.deleteSync(recursive: true); 81 await tempDirectory.deleteSync(recursive: true);
89 } 82 }
90 } 83 }
OLDNEW
« no previous file with comments | « samples/sample_extension/test/sample_extension_app_snapshot_test.dart ('k') | samples/samples.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698