| OLD | NEW |
| 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 library polymer.test.linter_test; | 5 library polymer.test.linter_test; |
| 6 | 6 |
| 7 import 'dart:convert'; |
| 8 |
| 7 import 'package:polymer/src/build/common.dart'; | 9 import 'package:polymer/src/build/common.dart'; |
| 8 import 'package:polymer/src/build/linter.dart'; | 10 import 'package:polymer/src/build/linter.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 10 | 12 |
| 11 import 'common.dart'; | 13 import 'common.dart'; |
| 12 | 14 |
| 13 void main() { | 15 void main() { |
| 14 _testLinter('nothing to report', { | 16 _testLinter('nothing to report', { |
| 15 'a|lib/test.html': '<!DOCTYPE html><html></html>', | 17 'a|lib/test.html': '<!DOCTYPE html><html></html>', |
| 16 }, []); | 18 }, []); |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 'forms are equivalent in HTML). (lib/test.html 2 28)' | 640 'forms are equivalent in HTML). (lib/test.html 2 28)' |
| 639 ]); | 641 ]); |
| 640 }); | 642 }); |
| 641 | 643 |
| 642 _testLinter("namespaced attributes don't cause an internal error", { | 644 _testLinter("namespaced attributes don't cause an internal error", { |
| 643 'a|lib/test.html': '''<html><body> | 645 'a|lib/test.html': '''<html><body> |
| 644 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> | 646 <svg xmlns="http://www.w3.org/2000/svg" width="520" height="350"> |
| 645 </svg> | 647 </svg> |
| 646 '''.replaceAll(' ', ''), | 648 '''.replaceAll(' ', ''), |
| 647 }, []); | 649 }, []); |
| 650 |
| 651 group('output logs to file', () { |
| 652 final outputLogsPhases = [[new Linter( |
| 653 new TransformOptions(injectBuildLogsInOutput: true, |
| 654 releaseMode: false))]]; |
| 655 |
| 656 testPhases("logs are output to file", outputLogsPhases, { |
| 657 'a|web/test.html': '<!DOCTYPE html><html>\n' |
| 658 '<polymer-element name="x-a"></polymer-element>' |
| 659 '<script type="application/dart" src="foo.dart">' |
| 660 '</script>' |
| 661 '<script src="packages/browser/dart.js"></script>' |
| 662 '</html>', |
| 663 }, { |
| 664 'a|web/test.html._buildLogs.1': |
| 665 '[{' |
| 666 '"level":"Warning",' |
| 667 '"message":${JSON.encode(usePolymerHtmlMessage(0))},' |
| 668 '"span":{' |
| 669 '"location":"web/test.html:2:1",' |
| 670 '"text":' |
| 671 '"${new HtmlEscape().convert('<polymer-element name="x-a">')}"' |
| 672 '}' |
| 673 '}]', |
| 674 }, [ |
| 675 // Logs should still make it to barback too. |
| 676 'warning: ${usePolymerHtmlMessage(0)} (web/test.html 1 0)', |
| 677 ]); |
| 678 }); |
| 648 } | 679 } |
| 649 | 680 |
| 650 _testLinter(String name, Map inputFiles, List outputMessages, | 681 _testLinter(String name, Map inputFiles, List outputMessages, |
| 651 [bool solo = false]) { | 682 [bool solo = false]) { |
| 652 var linter = new Linter(new TransformOptions()); | |
| 653 var outputFiles = {}; | 683 var outputFiles = {}; |
| 654 if (outputMessages.every((m) => m.startsWith('warning:'))) { | 684 if (outputMessages.every((m) => m.startsWith('warning:'))) { |
| 655 inputFiles.forEach((k, v) => outputFiles[k] = v); | 685 inputFiles.forEach((k, v) => outputFiles[k] = v); |
| 656 } | 686 } |
| 657 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); | 687 if (outputMessages.isEmpty) { |
| 688 var linter = new Linter(new TransformOptions()); |
| 689 testPhases(name, [[linter]], inputFiles, outputFiles, outputMessages, solo); |
| 690 } else { |
| 691 testLogOutput( |
| 692 (options) => new Linter(options), name, inputFiles, outputFiles, |
| 693 outputMessages, solo); |
| 694 } |
| 658 } | 695 } |
| OLD | NEW |