| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of test_suite; | 5 part of test_suite; |
| 6 | 6 |
| 7 String getHtmlContents(String title, | 7 String getHtmlContents(String title, |
| 8 Path controllerScript, | |
| 9 Path dartJsScript, | |
| 10 String scriptType, | 8 String scriptType, |
| 11 Path sourceScript) => | 9 Path sourceScript) => |
| 12 """ | 10 """ |
| 13 <!DOCTYPE html> | 11 <!DOCTYPE html> |
| 14 <html> | 12 <html> |
| 15 <head> | 13 <head> |
| 16 <meta http-equiv="X-UA-Compatible" content="IE=edge"> | 14 <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 17 <title> Test $title </title> | 15 <title> Test $title </title> |
| 18 <style> | 16 <style> |
| 19 .unittest-table { font-family:monospace; border:1px; } | 17 .unittest-table { font-family:monospace; border:1px; } |
| 20 .unittest-pass { background: #6b3;} | 18 .unittest-pass { background: #6b3;} |
| 21 .unittest-fail { background: #d55;} | 19 .unittest-fail { background: #d55;} |
| 22 .unittest-error { background: #a11;} | 20 .unittest-error { background: #a11;} |
| 23 </style> | 21 </style> |
| 24 </head> | 22 </head> |
| 25 <body> | 23 <body> |
| 26 <h1> Running $title </h1> | 24 <h1> Running $title </h1> |
| 27 <script type="text/javascript" src="$controllerScript"></script> | 25 <script type="text/javascript" |
| 26 src="/root_dart/pkg/unittest/lib/test_controller.js"> |
| 27 </script> |
| 28 <script type="$scriptType" src="$sourceScript" onerror="externalError(null)"> | 28 <script type="$scriptType" src="$sourceScript" onerror="externalError(null)"> |
| 29 </script> | 29 </script> |
| 30 <script type="text/javascript" src="$dartJsScript"></script> | 30 <script type="text/javascript" |
| 31 src="/root_dart/pkg/browser/lib/dart.js"></script> |
| 31 </body> | 32 </body> |
| 32 </html> | 33 </html> |
| 33 """; | 34 """; |
| 34 | 35 |
| 35 String getHtmlLayoutContents(String scriptType, String sourceScript) => | 36 String getHtmlLayoutContents(String scriptType, String sourceScript) => |
| 36 """ | 37 """ |
| 37 <!DOCTYPE html> | 38 <!DOCTYPE html> |
| 38 <html> | 39 <html> |
| 39 <head> | 40 <head> |
| 40 <meta http-equiv="X-UA-Compatible" content="IE=edge"> | 41 <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 41 </head> | 42 </head> |
| 42 <body> | 43 <body> |
| 43 <script type="text/javascript"> | 44 <script type="text/javascript"> |
| 44 if (navigator.webkitStartDart) navigator.webkitStartDart(); | 45 if (navigator.webkitStartDart) navigator.webkitStartDart(); |
| 45 </script> | 46 </script> |
| 46 <script type="$scriptType" src="$sourceScript"></script> | 47 <script type="$scriptType" src="$sourceScript"></script> |
| 47 </body> | 48 </body> |
| 48 </html> | 49 </html> |
| 49 """; | 50 """; |
| 50 | 51 |
| 51 String wrapDartTestInLibrary(Path test, String testPath) => | 52 String wrapDartTestInLibrary(Path testRelativeToDart) => |
| 52 """ | 53 """ |
| 53 library libraryWrapper; | 54 library libraryWrapper; |
| 54 part '${pathLib.relative(test.toNativePath(), | 55 part '/$testRelativeToDart'; |
| 55 from: pathLib.dirname(testPath)).replaceAll('\\', '\\\\')}'; | |
| 56 """; | 56 """; |
| 57 | 57 |
| 58 String dartTestWrapper(Path dartHome, String testPath, Path library) { | 58 String dartTestWrapper(bool usePackageImport, String libraryPathComponent) { |
| 59 var testPathDir = pathLib.dirname(testPath); | |
| 60 var dartHomePath = dartHome.toNativePath(); | |
| 61 // TODO(efortuna): Unify path libraries used in test.dart. | |
| 62 var unitTest = pathLib.relative(pathLib.join(dartHomePath, | |
| 63 'pkg/unittest/lib'), from: testPathDir).replaceAll('\\', '\\\\'); | |
| 64 | |
| 65 var libString = library.toNativePath(); | |
| 66 if (!pathLib.isAbsolute(libString)) { | |
| 67 libString = pathLib.join(dartHome.toNativePath(), libString); | |
| 68 } | |
| 69 // Tests inside "pkg" import unittest using "package:". All others use a | 59 // Tests inside "pkg" import unittest using "package:". All others use a |
| 70 // relative path. The imports need to agree, so use a matching form here. | 60 // relative path. The imports need to agree, so use a matching form here. |
| 71 if (pathLib.split(pathLib.relative(libString, | 61 var unitTest; |
| 72 from: dartHome.toNativePath())).contains("pkg")) { | 62 if (usePackageImport) { |
| 73 unitTest = 'package:unittest'; | 63 unitTest = 'package:unittest'; |
| 64 } else { |
| 65 unitTest = '/root_dart/pkg/unittest/lib'; |
| 74 } | 66 } |
| 75 return """ | 67 return """ |
| 76 library test; | 68 library test; |
| 77 | 69 |
| 78 import '$unitTest/unittest.dart' as unittest; | 70 import '$unitTest/unittest.dart' as unittest; |
| 79 import '$unitTest/html_config.dart' as config; | 71 import '$unitTest/html_config.dart' as config; |
| 80 import '${pathLib.relative(libString, from: testPathDir).replaceAll( | 72 import '$libraryPathComponent' as Test; |
| 81 '\\', '\\\\')}' as Test; | |
| 82 | 73 |
| 83 main() { | 74 main() { |
| 84 config.useHtmlConfiguration(); | 75 config.useHtmlConfiguration(); |
| 85 unittest.group('', Test.main); | 76 unittest.group('', Test.main); |
| 86 } | 77 } |
| 87 """; | 78 """; |
| 88 } | 79 } |
| OLD | NEW |