Chromium Code Reviews| 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.build.script_compactor_test; | 5 library polymer.test.build.script_compactor_test; |
| 6 | 6 |
| 7 import 'dart:convert'; | |
| 8 | |
| 7 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory; | 9 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory; |
| 8 import 'package:polymer/src/build/common.dart'; | 10 import 'package:polymer/src/build/common.dart'; |
| 9 import 'package:polymer/src/build/script_compactor.dart'; | 11 import 'package:polymer/src/build/script_compactor.dart'; |
| 10 import 'package:smoke/codegen/generator.dart' show DEFAULT_IMPORTS; | 12 import 'package:smoke/codegen/generator.dart' show DEFAULT_IMPORTS; |
| 11 import 'package:unittest/compact_vm_config.dart'; | 13 import 'package:unittest/compact_vm_config.dart'; |
| 12 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 13 | 15 |
| 14 import 'common.dart'; | 16 import 'common.dart'; |
| 15 | 17 |
| 16 void main() { | 18 void main() { |
| 17 useCompactVMConfiguration(); | 19 useCompactVMConfiguration(); |
| 18 var phases = [[new ScriptCompactor(new TransformOptions(), | 20 var phases = [[new ScriptCompactor(new TransformOptions(), |
| 19 sdkDir: testingDartSdkDirectory)]]; | 21 sdkDir: testingDartSdkDirectory)]]; |
| 20 group('initializers', () => initializerTests(phases)); | 22 group('initializers', () => initializerTests(phases)); |
| 21 group('experimental', () => initializerTestsExperimental(phases)); | 23 group('experimental', () => initializerTestsExperimental(phases)); |
| 22 group('codegen', () => codegenTests(phases)); | 24 group('codegen', () => codegenTests(phases)); |
| 25 group('log element injection', logElementInjectionTests); | |
| 23 } | 26 } |
| 24 | 27 |
| 25 initializerTests(phases) { | 28 initializerTests(phases) { |
| 26 testPhases('no changes', phases, { | 29 testPhases('no changes', phases, { |
| 27 'a|web/test.html': '<!DOCTYPE html><html></html>', | 30 'a|web/test.html': '<!DOCTYPE html><html></html>', |
| 28 'a|web/test.html._data': EMPTY_DATA, | 31 'a|web/test.html._data': EMPTY_DATA, |
| 29 }, { | 32 }, { |
| 30 'a|web/test.html': '<!DOCTYPE html><html></html>', | 33 'a|web/test.html': '<!DOCTYPE html><html></html>', |
| 31 }); | 34 }); |
| 32 | 35 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 smoke_0.XFoo: {}, | 149 smoke_0.XFoo: {}, |
| 147 })); | 150 })); |
| 148 configureForDeployment([ | 151 configureForDeployment([ |
| 149 () => Polymer.register(\'x-foo2\', i0.XFoo), | 152 () => Polymer.register(\'x-foo2\', i0.XFoo), |
| 150 ]); | 153 ]); |
| 151 i0.main(); | 154 i0.main(); |
| 152 } | 155 } |
| 153 '''.replaceAll('\n ', '\n'), | 156 '''.replaceAll('\n ', '\n'), |
| 154 }); | 157 }); |
| 155 | 158 |
| 156 testPhases('invalid const expression', phases, { | 159 |
| 157 'a|web/test.html': | 160 testLogOutput( |
| 161 (options) => | |
| 162 new ScriptCompactor(options, sdkDir: testingDartSdkDirectory), | |
| 163 'invalid const expression logs', { | |
|
Siggi Cherem (dart-lang)
2014/08/05 23:35:25
nit: I think it's fine to combine this and the tes
jakemac
2014/08/06 14:11:34
The problem is the output changes based on the dif
Siggi Cherem (dart-lang)
2014/08/06 17:25:22
Ah, got it. makes sense.
| |
| 164 'a|web/test.html': | |
| 165 '<!DOCTYPE html><html><head>', | |
| 166 'a|web/test.html._data': expectedData(['web/a.dart']), | |
| 167 'a|web/a.dart': | |
| 168 'library a;\n' | |
| 169 'import "package:polymer/polymer.dart";\n' | |
| 170 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined | |
| 171 'class XFoo extends PolymerElement {\n' | |
| 172 '}\n' | |
| 173 'main(){}', | |
| 174 }, {}, [ | |
| 175 'warning: The parameter to @CustomTag seems to be invalid. ' | |
| 176 '(web/a.dart 2 11)', | |
| 177 ]); | |
| 178 | |
| 179 testPhases( | |
| 180 'invalid const expression', phases, { | |
| 181 'a|web/test.html': | |
| 158 '<!DOCTYPE html><html><head>', | 182 '<!DOCTYPE html><html><head>', |
| 159 'a|web/test.html._data': expectedData(['web/a.dart']), | 183 'a|web/test.html._data': expectedData(['web/a.dart']), |
| 160 'a|web/a.dart': | 184 'a|web/a.dart': |
| 161 'library a;\n' | 185 'library a;\n' |
| 162 'import "package:polymer/polymer.dart";\n' | 186 'import "package:polymer/polymer.dart";\n' |
| 163 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined | 187 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined |
| 164 'class XFoo extends PolymerElement {\n' | 188 'class XFoo extends PolymerElement {\n' |
| 165 '}\n' | 189 '}\n' |
| 166 'main(){}', | 190 'main(){}', |
| 167 }, { | 191 }, { |
| 168 'a|web/test.html_bootstrap.dart': | 192 'a|web/test.html_bootstrap.dart': |
| 169 '''$MAIN_HEADER | 193 '''$MAIN_HEADER |
| 170 import 'a.dart' as i0; | 194 import 'a.dart' as i0; |
| 171 ${DEFAULT_IMPORTS.join('\n')} | 195 ${DEFAULT_IMPORTS.join('\n')} |
| 172 import 'a.dart' as smoke_0; | 196 import 'a.dart' as smoke_0; |
| 173 import 'package:polymer/polymer.dart' as smoke_1; | 197 import 'package:polymer/polymer.dart' as smoke_1; |
| 174 | 198 |
| 175 void main() { | 199 void main() { |
| 176 useGeneratedCode(new StaticConfiguration( | 200 useGeneratedCode(new StaticConfiguration( |
| 177 checkedMode: false, | 201 checkedMode: false, |
| 178 parents: { | 202 parents: { |
| 179 smoke_0.XFoo: smoke_1.PolymerElement, | 203 smoke_0.XFoo: smoke_1.PolymerElement, |
| 180 }, | 204 }, |
| 181 declarations: { | 205 declarations: { |
| 182 smoke_0.XFoo: {}, | 206 smoke_0.XFoo: {}, |
| 183 })); | 207 })); |
| 184 configureForDeployment([]); | 208 configureForDeployment([]); |
| 185 i0.main(); | 209 i0.main(); |
| 186 } | 210 } |
| 187 '''.replaceAll('\n ', '\n'), | 211 '''.replaceAll('\n ', '\n'), |
| 188 | 212 |
| 189 }, [ | 213 }); |
| 190 'warning: The parameter to @CustomTag seems to be invalid. ' | |
| 191 '(web/a.dart 2 11)', | |
| 192 ]); | |
| 193 | 214 |
| 194 testPhases('no polymer import (no warning, but no crash either)', phases, { | 215 testPhases('no polymer import (no warning, but no crash either)', phases, { |
| 195 'a|web/test.html': | 216 'a|web/test.html': |
| 196 '<!DOCTYPE html><html><head>', | 217 '<!DOCTYPE html><html><head>', |
| 197 'a|web/test.html._data': expectedData(['web/a.dart']), | 218 'a|web/test.html._data': expectedData(['web/a.dart']), |
| 198 'a|web/a.dart': | 219 'a|web/a.dart': |
| 199 'library a;\n' | 220 'library a;\n' |
| 200 'import "package:polymer/polymer.broken.import.dart";\n' | 221 'import "package:polymer/polymer.broken.import.dart";\n' |
| 201 '@CustomTag("x-foo")\n' | 222 '@CustomTag("x-foo")\n' |
| 202 'class XFoo extends PolymerElement {\n' | 223 'class XFoo extends PolymerElement {\n' |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 declarations: { | 479 declarations: { |
| 459 smoke_0.XFoo: {}, | 480 smoke_0.XFoo: {}, |
| 460 })); | 481 })); |
| 461 startPolymer([ | 482 startPolymer([ |
| 462 () => Polymer.register(\'x-foo2\', i0.XFoo), | 483 () => Polymer.register(\'x-foo2\', i0.XFoo), |
| 463 ]); | 484 ]); |
| 464 } | 485 } |
| 465 '''.replaceAll('\n ', '\n'), | 486 '''.replaceAll('\n ', '\n'), |
| 466 }); | 487 }); |
| 467 | 488 |
| 468 testPhases('invalid const expression', phases, { | 489 testLogOutput( |
|
Siggi Cherem (dart-lang)
2014/08/05 23:35:25
same for these and below
| |
| 469 'a|web/test.html': | 490 (options) => |
| 470 '<!DOCTYPE html><html><head>', | 491 new ScriptCompactor(options, sdkDir: testingDartSdkDirectory), |
| 471 'a|web/test.html._data': expectedData(['web/a.dart'], experimental: true), | 492 'invalid const expression logs', { |
| 472 'a|web/a.dart': | 493 'a|web/test.html': |
| 473 'library a;\n' | 494 '<!DOCTYPE html><html><head>', |
| 474 'import "package:polymer/polymer.dart";\n' | 495 'a|web/test.html._data': |
| 475 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined | 496 expectedData(['web/a.dart'], experimental: true), |
| 476 'class XFoo extends PolymerElement {\n' | 497 'a|web/a.dart': |
| 477 '}\n' | 498 'library a;\n' |
| 478 'main(){}', | 499 'import "package:polymer/polymer.dart";\n' |
| 479 }, { | 500 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined |
| 480 'a|web/test.html_bootstrap.dart': | 501 'class XFoo extends PolymerElement {\n' |
| 481 '''$MAIN_HEADER | 502 '}\n' |
| 482 import 'a.dart' as i0; | 503 'main(){}', |
| 483 ${DEFAULT_IMPORTS.join('\n')} | 504 }, {}, [ |
| 484 import 'a.dart' as smoke_0; | 505 'warning: The parameter to @CustomTag seems to be invalid. ' |
| 485 import 'package:polymer/polymer.dart' as smoke_1; | 506 '(web/a.dart 2 11)', |
| 507 'warning: $NO_INITIALIZERS_ERROR', | |
| 508 ]); | |
| 486 | 509 |
| 487 void main() { | 510 testPhases( |
| 488 useGeneratedCode(new StaticConfiguration( | 511 'invalid const expression', phases, { |
| 489 checkedMode: false, | 512 'a|web/test.html': |
| 490 parents: { | 513 '<!DOCTYPE html><html><head>', |
| 491 smoke_0.XFoo: smoke_1.PolymerElement, | 514 'a|web/test.html._data': |
| 492 }, | 515 expectedData(['web/a.dart'], experimental: true), |
| 493 declarations: { | 516 'a|web/a.dart': |
| 494 smoke_0.XFoo: {}, | 517 'library a;\n' |
| 495 })); | 518 'import "package:polymer/polymer.dart";\n' |
| 496 startPolymer([]); | 519 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined |
| 497 } | 520 'class XFoo extends PolymerElement {\n' |
| 498 '''.replaceAll('\n ', '\n'), | 521 '}\n' |
| 522 'main(){}', | |
| 523 }, { | |
| 524 'a|web/test.html_bootstrap.dart': | |
| 525 '''$MAIN_HEADER | |
| 526 import 'a.dart' as i0; | |
| 527 ${DEFAULT_IMPORTS.join('\n')} | |
| 528 import 'a.dart' as smoke_0; | |
| 529 import 'package:polymer/polymer.dart' as smoke_1; | |
| 499 | 530 |
| 500 }, [ | 531 void main() { |
| 501 'warning: The parameter to @CustomTag seems to be invalid. ' | 532 useGeneratedCode(new StaticConfiguration( |
| 502 '(web/a.dart 2 11)', | 533 checkedMode: false, |
| 503 'warning: $NO_INITIALIZERS_ERROR', | 534 parents: { |
| 504 ]); | 535 smoke_0.XFoo: smoke_1.PolymerElement, |
| 536 }, | |
| 537 declarations: { | |
| 538 smoke_0.XFoo: {}, | |
| 539 })); | |
| 540 startPolymer([]); | |
| 541 } | |
| 542 '''.replaceAll('\n ', '\n'), | |
| 543 }); | |
| 505 | 544 |
| 506 testPhases('no polymer import (no warning, but no crash either)', phases, { | 545 testLogOutput( |
| 507 'a|web/test.html': | 546 (options) => |
| 508 '<!DOCTYPE html><html><head>', | 547 new ScriptCompactor(options, sdkDir: testingDartSdkDirectory), |
| 509 'a|web/test.html._data': expectedData(['web/a.dart'], experimental: true), | 548 'no polymer import logs', { |
| 510 'a|web/a.dart': | 549 'a|web/test.html': |
| 511 'library a;\n' | 550 '<!DOCTYPE html><html><head>', |
| 512 'import "package:polymer/polymer.broken.import.dart";\n' | 551 'a|web/test.html._data': expectedData(['web/a.dart'], experimental: true ), |
| 513 '@CustomTag("x-foo")\n' | 552 'a|web/a.dart': |
| 514 'class XFoo extends PolymerElement {\n' | 553 'library a;\n' |
| 515 '}\n' | 554 'import "package:polymer/polymer.broken.import.dart";\n' |
| 516 'main(){}', | 555 '@CustomTag("x-foo")\n' |
| 517 }, { | 556 'class XFoo extends PolymerElement {\n' |
| 518 'a|web/test.html_bootstrap.dart': | 557 '}\n' |
| 519 '''$MAIN_HEADER | 558 'main(){}', |
| 520 import 'a.dart' as i0; | 559 }, {}, [ |
| 521 ${DEFAULT_IMPORTS.join('\n')} | 560 'warning: $NO_INITIALIZERS_ERROR', |
| 561 ]); | |
| 522 | 562 |
| 523 void main() { | 563 testPhases( |
| 524 useGeneratedCode(new StaticConfiguration( | 564 'no polymer import', phases, { |
| 525 checkedMode: false)); | 565 'a|web/test.html': |
| 526 startPolymer([]); | 566 '<!DOCTYPE html><html><head>', |
| 527 } | 567 'a|web/test.html._data': |
| 528 '''.replaceAll('\n ', '\n'), | 568 expectedData(['web/a.dart'], experimental: true), |
| 569 'a|web/a.dart': | |
| 570 'library a;\n' | |
| 571 'import "package:polymer/polymer.broken.import.dart";\n' | |
| 572 '@CustomTag("x-foo")\n' | |
| 573 'class XFoo extends PolymerElement {\n' | |
| 574 '}\n' | |
| 575 'main(){}', | |
| 576 }, { | |
| 577 'a|web/test.html_bootstrap.dart': | |
| 578 '''$MAIN_HEADER | |
| 579 import 'a.dart' as i0; | |
| 580 ${DEFAULT_IMPORTS.join('\n')} | |
| 529 | 581 |
| 530 }, [ | 582 void main() { |
| 531 'warning: $NO_INITIALIZERS_ERROR', | 583 useGeneratedCode(new StaticConfiguration( |
| 532 ]); | 584 checkedMode: false)); |
| 585 startPolymer([]); | |
| 586 } | |
| 587 '''.replaceAll('\n ', '\n'), | |
| 588 | |
| 589 }); | |
| 533 | 590 |
| 534 testPhases('several scripts', phases, { | 591 testPhases('several scripts', phases, { |
| 535 'a|web/test.html': | 592 'a|web/test.html': |
| 536 '<!DOCTYPE html><html><head>' | 593 '<!DOCTYPE html><html><head>' |
| 537 '</head><body><div></div>', | 594 '</head><body><div></div>', |
| 538 'a|web/test.html._data': | 595 'a|web/test.html._data': |
| 539 expectedData(['web/a.dart', 'web/b.dart', 'web/c.dart', 'web/d.dart'], experimental: true), | 596 expectedData(['web/a.dart', 'web/b.dart', 'web/c.dart', 'web/d.dart'], experimental: true), |
| 540 'a|web/d.dart': | 597 'a|web/d.dart': |
| 541 'library d;\n' | 598 'library d;\n' |
| 542 'import "package:polymer/polymer.dart";\n' | 599 'import "package:polymer/polymer.dart";\n' |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1086 })); | 1143 })); |
| 1087 configureForDeployment([ | 1144 configureForDeployment([ |
| 1088 () => Polymer.register(\'x-foo\', i0.XFoo), | 1145 () => Polymer.register(\'x-foo\', i0.XFoo), |
| 1089 ]); | 1146 ]); |
| 1090 i0.main(); | 1147 i0.main(); |
| 1091 } | 1148 } |
| 1092 '''.replaceAll('\n ', '\n'), | 1149 '''.replaceAll('\n ', '\n'), |
| 1093 }); | 1150 }); |
| 1094 } | 1151 } |
| 1095 | 1152 |
| 1153 void logElementInjectionTests() { | |
| 1154 final outputLogsPhases = [[new ScriptCompactor( | |
| 1155 new TransformOptions(injectBuildLogsInOutput: true, releaseMode: false), | |
| 1156 sdkDir: testingDartSdkDirectory)]]; | |
| 1157 | |
| 1158 testPhases('Injects logging element and styles', outputLogsPhases, { | |
| 1159 'a|web/test.html': '<!DOCTYPE html><html><head>', | |
| 1160 'a|web/test.html._data': expectedData(['web/a.dart']), | |
| 1161 'a|web/a.dart': | |
| 1162 'library a;\n' | |
| 1163 'import "package:polymer/polymer.dart";\n' | |
| 1164 'main(){}', | |
| 1165 }, { | |
| 1166 'a|web/test.html': | |
| 1167 '<!DOCTYPE html><html><head>' | |
| 1168 '<link rel="stylesheet" type="text/css" ' | |
| 1169 'href="packages/polymer/src/build/log_injector.css">' | |
| 1170 '</head><body>' | |
| 1171 '<script type="application/dart" ' | |
| 1172 'src="test.html_bootstrap.dart"></script>' | |
| 1173 '</body></html>', | |
| 1174 'a|web/test.html_bootstrap.dart': | |
| 1175 '''$MAIN_HEADER | |
| 1176 import 'a.dart' as i0; | |
| 1177 import 'package:polymer/src/build/log_injector.dart'; | |
| 1178 ${DEFAULT_IMPORTS.join('\n')} | |
| 1179 | |
| 1180 void main() { | |
| 1181 useGeneratedCode(new StaticConfiguration( | |
| 1182 checkedMode: false)); | |
| 1183 new LogInjector().injectLogsFromUrl(); | |
| 1184 configureForDeployment([]); | |
| 1185 i0.main(); | |
| 1186 } | |
| 1187 '''.replaceAll('\n ', '\n'), | |
| 1188 'a|web/a.dart': | |
| 1189 'library a;\n' | |
| 1190 'import "package:polymer/polymer.dart";\n' | |
| 1191 'main(){}', | |
| 1192 }); | |
| 1193 } | |
| OLD | NEW |