OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, 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 /** |
| 6 * Classes and methods for running HTML tests. |
| 7 * |
| 8 * HTML tests are valid HTML files whose name ends in _test.html, and that |
| 9 * contain an annotation specifying the scripts in the test and the |
| 10 * messages the test should post to its window, when passing. |
| 11 */ |
| 12 library html_test; |
| 13 |
| 14 import "dart:convert"; |
| 15 import "dart:io"; |
| 16 |
| 17 import "test_suite.dart"; |
| 18 import "utils.dart"; |
| 19 |
| 20 RegExp htmlAnnotation = |
| 21 new RegExp("START_HTML_DART_TEST([\\s\\S]*?)END_HTML_DART_TEST"); |
| 22 |
| 23 HtmlTestInformation getInformation(String filename) { |
| 24 String contents = new File(filename).readAsStringSync(); |
| 25 var match = htmlAnnotation.firstMatch(contents); |
| 26 print(match); |
| 27 if (match == null) return null; |
| 28 print(match[1]); |
| 29 var annotation = JSON.decode(match[1]); |
| 30 if (annotation is! Map || annotation['expectedMessages'] is! List || |
| 31 annotation['scripts'] is! List) { |
| 32 DebugLogger.warning("File $filename does not have expected annotation." |
| 33 " Should have {'scripts':[...], 'expectedMessages':[...]}"); |
| 34 return null; |
| 35 } |
| 36 return new HtmlTestInformation(new Path(filename), |
| 37 annotation['expectedMessages'], |
| 38 annotation['scripts']); |
| 39 } |
| 40 |
| 41 String getContents(HtmlTestInformation info) { |
| 42 String contents = new File(info.filePath.toNativePath()).readAsStringSync(); |
| 43 return contents.replaceFirst(htmlAnnotation, ''); |
| 44 } |
OLD | NEW |