OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.end2end.inc; | 4 package com.google.dart.compiler.end2end.inc; |
5 | 5 |
6 import static com.google.dart.compiler.DartCompiler.EXTENSION_DEPS; | 6 import static com.google.dart.compiler.DartCompiler.EXTENSION_DEPS; |
7 import static com.google.dart.compiler.DartCompiler.EXTENSION_TIMESTAMP; | 7 import static com.google.dart.compiler.DartCompiler.EXTENSION_TIMESTAMP; |
8 import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; | 8 import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; |
9 import static com.google.dart.compiler.common.ErrorExpectation.errEx; | 9 import static com.google.dart.compiler.common.ErrorExpectation.errEx; |
10 | 10 |
11 import com.google.common.collect.Lists; | 11 import com.google.common.collect.Lists; |
| 12 import com.google.common.collect.Maps; |
12 import com.google.common.collect.Sets; | 13 import com.google.common.collect.Sets; |
13 import com.google.dart.compiler.CompilerTestCase; | 14 import com.google.dart.compiler.CompilerTestCase; |
14 import com.google.dart.compiler.DartCompilationError; | 15 import com.google.dart.compiler.DartCompilationError; |
15 import com.google.dart.compiler.DartCompiler; | 16 import com.google.dart.compiler.DartCompiler; |
16 import com.google.dart.compiler.DartCompilerErrorCode; | 17 import com.google.dart.compiler.DartCompilerErrorCode; |
17 import com.google.dart.compiler.DartCompilerListener; | 18 import com.google.dart.compiler.DartCompilerListener; |
18 import com.google.dart.compiler.DartSource; | 19 import com.google.dart.compiler.DartSource; |
19 import com.google.dart.compiler.DefaultCompilerConfiguration; | 20 import com.google.dart.compiler.DefaultCompilerConfiguration; |
20 import com.google.dart.compiler.LibrarySource; | 21 import com.google.dart.compiler.LibrarySource; |
21 import com.google.dart.compiler.MockArtifactProvider; | 22 import com.google.dart.compiler.MockArtifactProvider; |
22 import com.google.dart.compiler.Source; | 23 import com.google.dart.compiler.Source; |
23 import com.google.dart.compiler.SystemLibraryManager; | 24 import com.google.dart.compiler.SystemLibraryManager; |
24 import com.google.dart.compiler.UrlSource; | 25 import com.google.dart.compiler.UrlSource; |
25 import com.google.dart.compiler.ast.DartUnit; | 26 import com.google.dart.compiler.ast.DartUnit; |
26 import com.google.dart.compiler.ast.LibraryUnit; | 27 import com.google.dart.compiler.ast.LibraryUnit; |
27 import com.google.dart.compiler.common.ErrorExpectation; | 28 import com.google.dart.compiler.common.ErrorExpectation; |
28 import com.google.dart.compiler.resolver.ResolverErrorCode; | 29 import com.google.dart.compiler.resolver.ResolverErrorCode; |
29 import com.google.dart.compiler.resolver.TypeErrorCode; | 30 import com.google.dart.compiler.resolver.TypeErrorCode; |
30 | 31 |
31 import junit.framework.AssertionFailedError; | 32 import junit.framework.AssertionFailedError; |
32 | 33 |
33 import java.io.IOException; | 34 import java.io.IOException; |
34 import java.io.Reader; | 35 import java.io.Reader; |
35 import java.io.Writer; | 36 import java.io.Writer; |
36 import java.net.URI; | 37 import java.net.URI; |
37 import java.util.List; | 38 import java.util.List; |
| 39 import java.util.Map; |
38 import java.util.Set; | 40 import java.util.Set; |
39 import java.util.concurrent.ConcurrentSkipListSet; | 41 import java.util.concurrent.ConcurrentSkipListSet; |
40 | 42 |
41 // TODO(zundel): update this test not to rely on code generation | 43 // TODO(zundel): update this test not to rely on code generation |
42 public class IncrementalCompilation2Test extends CompilerTestCase { | 44 public class IncrementalCompilation2Test extends CompilerTestCase { |
43 private static final String APP = "Application.dart"; | 45 private static final String APP = "Application.dart"; |
44 | 46 |
45 private static class IncMockArtifactProvider extends MockArtifactProvider { | 47 private static class IncMockArtifactProvider extends MockArtifactProvider { |
46 Set<String> reads = new ConcurrentSkipListSet<String>(); | 48 Set<String> reads = new ConcurrentSkipListSet<String>(); |
47 Set<String> writes = new ConcurrentSkipListSet<String>(); | 49 Set<String> writes = new ConcurrentSkipListSet<String>(); |
(...skipping 13 matching lines...) Expand all Loading... |
61 void resetReadsAndWrites() { | 63 void resetReadsAndWrites() { |
62 reads.clear(); | 64 reads.clear(); |
63 writes.clear(); | 65 writes.clear(); |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
67 private DefaultCompilerConfiguration config; | 69 private DefaultCompilerConfiguration config; |
68 private IncMockArtifactProvider provider; | 70 private IncMockArtifactProvider provider; |
69 private MemoryLibrarySource appSource; | 71 private MemoryLibrarySource appSource; |
70 private final List<DartCompilationError> errors = Lists.newArrayList(); | 72 private final List<DartCompilationError> errors = Lists.newArrayList(); |
| 73 private final Map<String, DartUnit> units = Maps.newHashMap(); |
71 | 74 |
72 @Override | 75 @Override |
73 protected void setUp() throws Exception { | 76 protected void setUp() throws Exception { |
74 config = new DefaultCompilerConfiguration() { | 77 config = new DefaultCompilerConfiguration() { |
75 @Override | 78 @Override |
76 public boolean incremental() { | 79 public boolean incremental() { |
77 return true; | 80 return true; |
78 } | 81 } |
79 }; | 82 }; |
80 provider = new IncMockArtifactProvider(); | 83 provider = new IncMockArtifactProvider(); |
(...skipping 10 matching lines...) Expand all Loading... |
91 appSource.setContent("A.dart", ""); | 94 appSource.setContent("A.dart", ""); |
92 appSource.setContent("B.dart", ""); | 95 appSource.setContent("B.dart", ""); |
93 appSource.setContent("C.dart", ""); | 96 appSource.setContent("C.dart", ""); |
94 } | 97 } |
95 | 98 |
96 @Override | 99 @Override |
97 protected void tearDown() { | 100 protected void tearDown() { |
98 config = null; | 101 config = null; |
99 provider = null; | 102 provider = null; |
100 appSource = null; | 103 appSource = null; |
| 104 errors.clear(); |
| 105 units.clear(); |
101 } | 106 } |
102 | 107 |
103 /** | 108 /** |
104 * "not_hole" is referenced using "super" qualifier, so is not affected by dec
laring top-level | 109 * "not_hole" is referenced using "super" qualifier, so is not affected by dec
laring top-level |
105 * field with same name. | 110 * field with same name. |
106 */ | 111 */ |
107 public void test_useQualifiedFieldReference_ignoreTopLevelDeclaration() { | 112 public void test_useQualifiedFieldReference_ignoreTopLevelDeclaration() { |
108 appSource.setContent( | 113 appSource.setContent( |
109 "B.dart", | 114 "B.dart", |
110 makeCode( | 115 makeCode( |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 "#library('application');", | 878 "#library('application');", |
874 "#import('A.dart', prefix: 'prf');", | 879 "#import('A.dart', prefix: 'prf');", |
875 "main() {", | 880 "main() {", |
876 " var prf;", | 881 " var prf;", |
877 "}", | 882 "}", |
878 "")); | 883 "")); |
879 // do compile, no errors expected | 884 // do compile, no errors expected |
880 compile(); | 885 compile(); |
881 assertErrors(errors, errEx(ResolverErrorCode.CANNOT_HIDE_IMPORT_PREFIX, 5, 7
, 3)); | 886 assertErrors(errors, errEx(ResolverErrorCode.CANNOT_HIDE_IMPORT_PREFIX, 5, 7
, 3)); |
882 } | 887 } |
| 888 |
| 889 /** |
| 890 * <p> |
| 891 * http://code.google.com/p/dart/issues/detail?id=4238 |
| 892 */ |
| 893 public void test_typesPropagation_html_query() throws Exception { |
| 894 appSource.setContent( |
| 895 APP, |
| 896 makeCode( |
| 897 "// filler filler filler filler filler filler filler filler filler f
iller filler", |
| 898 "#library('application');", |
| 899 "#import('dart:html');", |
| 900 "main() {", |
| 901 " var v1 = query('a');", |
| 902 " var v2 = query('A');", |
| 903 " var v3 = query('body:active');", |
| 904 " var v4 = query('button[foo=\"bar\"]');", |
| 905 " var v5 = query('div.class');", |
| 906 " var v6 = query('input#id');", |
| 907 " // invocation of method", |
| 908 " var m1 = document.query('div');", |
| 909 " // unsupported currently", |
| 910 " var b1 = query('noSuchTag');", |
| 911 " var b2 = query('DART_EDITOR_NO_SUCH_TYPE');", |
| 912 " var b3 = query('body div');", |
| 913 "}", |
| 914 "")); |
| 915 // do compile, no errors expected |
| 916 compile(); |
| 917 assertErrors(errors); |
| 918 // validate types |
| 919 DartUnit unit = units.get(APP); |
| 920 assertNotNull(unit); |
| 921 assertInferredElementTypeString(unit, "v1", "AnchorElement"); |
| 922 assertInferredElementTypeString(unit, "v2", "AnchorElement"); |
| 923 assertInferredElementTypeString(unit, "v3", "BodyElement"); |
| 924 assertInferredElementTypeString(unit, "v4", "ButtonElement"); |
| 925 assertInferredElementTypeString(unit, "v5", "DivElement"); |
| 926 assertInferredElementTypeString(unit, "v6", "InputElement"); |
| 927 // invocation of method |
| 928 assertInferredElementTypeString(unit, "m1", "DivElement"); |
| 929 // bad cases, or unsupported now |
| 930 assertInferredElementTypeString(unit, "b1", "Element"); |
| 931 assertInferredElementTypeString(unit, "b2", "Element"); |
| 932 assertInferredElementTypeString(unit, "b3", "Element"); |
| 933 } |
883 | 934 |
884 /** | 935 /** |
885 * Libraries "dart:io" and "dart:html" can not be used together in single appl
ication. | 936 * Libraries "dart:io" and "dart:html" can not be used together in single appl
ication. |
886 * <p> | 937 * <p> |
887 * http://code.google.com/p/dart/issues/detail?id=3839 | 938 * http://code.google.com/p/dart/issues/detail?id=3839 |
888 */ | 939 */ |
889 public void test_consoleWebMix() throws Exception { | 940 public void test_consoleWebMix() throws Exception { |
890 appSource.setContent( | 941 appSource.setContent( |
891 APP, | 942 APP, |
892 makeCode( | 943 makeCode( |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 // Remember errors only between unitAboutToCompile/unitCompiled. | 1037 // Remember errors only between unitAboutToCompile/unitCompiled. |
987 Source source = event.getSource(); | 1038 Source source = event.getSource(); |
988 if (source != null && compilingUris.contains(source.getUri())) { | 1039 if (source != null && compilingUris.contains(source.getUri())) { |
989 errors.add(event); | 1040 errors.add(event); |
990 } | 1041 } |
991 } | 1042 } |
992 | 1043 |
993 @Override | 1044 @Override |
994 public void unitCompiled(DartUnit unit) { | 1045 public void unitCompiled(DartUnit unit) { |
995 compilingUris.remove(unit.getSourceInfo().getSource().getUri()); | 1046 compilingUris.remove(unit.getSourceInfo().getSource().getUri()); |
| 1047 units.put(unit.getSourceName(), unit); |
996 } | 1048 } |
997 }; | 1049 }; |
998 DartCompiler.compileLib(lib, config, provider, listener); | 1050 DartCompiler.compileLib(lib, config, provider, listener); |
999 } catch (IOException e) { | 1051 } catch (IOException e) { |
1000 throw new AssertionFailedError("Unexpected IOException: " + e.getMessage()
); | 1052 throw new AssertionFailedError("Unexpected IOException: " + e.getMessage()
); |
1001 } | 1053 } |
1002 } | 1054 } |
1003 | 1055 |
1004 private void didWrite(String sourceName, String extension) { | 1056 private void didWrite(String sourceName, String extension) { |
1005 String spec = sourceName + "/" + extension; | 1057 String spec = sourceName + "/" + extension; |
1006 assertTrue("Expected write: " + spec, provider.writes.contains(spec)); | 1058 assertTrue("Expected write: " + spec, provider.writes.contains(spec)); |
1007 } | 1059 } |
1008 | 1060 |
1009 private void didNotWrite(String sourceName, String extension) { | 1061 private void didNotWrite(String sourceName, String extension) { |
1010 String spec = sourceName + "/" + extension; | 1062 String spec = sourceName + "/" + extension; |
1011 assertFalse("Didn't expect write: " + spec, provider.writes.contains(spec)); | 1063 assertFalse("Didn't expect write: " + spec, provider.writes.contains(spec)); |
1012 } | 1064 } |
1013 } | 1065 } |
OLD | NEW |