OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.tools.core.analysis; | 14 package com.google.dart.tools.core.analysis; |
15 | 15 |
| 16 import com.google.common.collect.Lists; |
| 17 import com.google.dart.compiler.PackageLibraryManager; |
| 18 import com.google.dart.engine.utilities.io.PrintStringWriter; |
| 19 import com.google.dart.tools.core.analysis.ScanTask.DartFileType; |
| 20 import com.google.dart.tools.core.internal.model.PackageLibraryManagerProvider; |
| 21 |
16 import static com.google.dart.tools.core.analysis.AnalysisTestUtilities.assertCa
chedLibraries; | 22 import static com.google.dart.tools.core.analysis.AnalysisTestUtilities.assertCa
chedLibraries; |
17 import static com.google.dart.tools.core.analysis.AnalysisTestUtilities.assertPa
ckageContexts; | 23 import static com.google.dart.tools.core.analysis.AnalysisTestUtilities.assertPa
ckageContexts; |
18 import static com.google.dart.tools.core.analysis.AnalysisTestUtilities.assertTr
ackedLibraryFiles; | 24 import static com.google.dart.tools.core.analysis.AnalysisTestUtilities.assertTr
ackedLibraryFiles; |
19 import static com.google.dart.tools.core.analysis.ScanTask.DartFileType.Library; | 25 import static com.google.dart.tools.core.analysis.ScanTask.DartFileType.Library; |
20 import static com.google.dart.tools.core.analysis.ScanTask.DartFileType.PartOf; | 26 import static com.google.dart.tools.core.analysis.ScanTask.DartFileType.PartOf; |
21 import static com.google.dart.tools.core.analysis.ScanTask.DartFileType.Unknown; | 27 import static com.google.dart.tools.core.analysis.ScanTask.DartFileType.Unknown; |
22 | 28 |
23 import com.google.common.collect.Lists; | |
24 import com.google.dart.compiler.PackageLibraryManager; | |
25 import com.google.dart.engine.utilities.io.PrintStringWriter; | |
26 import com.google.dart.tools.core.analysis.ScanTask.DartFileType; | |
27 import com.google.dart.tools.core.internal.model.PackageLibraryManagerProvider; | |
28 | |
29 import java.io.ByteArrayInputStream; | 29 import java.io.ByteArrayInputStream; |
30 import java.io.File; | 30 import java.io.File; |
31 import java.io.IOException; | 31 import java.io.IOException; |
32 import java.util.List; | 32 import java.util.List; |
33 | 33 |
34 public class ScanTaskTest extends AbstractDartAnalysisTest { | 34 public class ScanTaskTest extends AbstractDartAnalysisTest { |
35 | 35 |
36 private static final byte[] BUFFER = new byte[1024]; | 36 private static final byte[] BUFFER = new byte[1024]; |
37 | 37 |
38 /** | 38 /** |
39 * Called once prior to executing the first test in this class | 39 * Called once prior to executing the first test in this class |
40 */ | 40 */ |
41 public static void setUpOnce() throws Exception { | 41 public static void setUpOnce() throws Exception { |
42 setUpBankExample(); | 42 setUpBankExample(); |
43 } | 43 } |
44 | 44 |
45 /** | 45 /** |
46 * Called once after executing the last test in this class | 46 * Called once after executing the last test in this class |
47 */ | 47 */ |
48 public static void tearDownOnce() { | 48 public static void tearDownOnce() { |
49 tearDownBankExample(); | 49 tearDownBankExample(); |
50 } | 50 } |
51 | 51 |
52 private AnalysisServerAdapter server; | 52 private AnalysisServerAdapter server; |
53 private Listener listener; | 53 private Listener listener; |
54 | 54 |
55 /** | |
56 * TODO(scheglov) disabled because now 'part of' directive required | |
57 */ | |
58 public void _test_scan_source() throws Exception { | |
59 assertTrackedLibraryFiles(server); | |
60 server.scan(simpleMoneySrcFile, null); | |
61 server.start(); | |
62 listener.waitForIdle(1, FIVE_MINUTES_MS); | |
63 assertTrackedLibraryFiles(server, simpleMoneySrcFile); | |
64 server.assertAnalyzeContext(true); | |
65 } | |
66 | |
67 /** | |
68 * TODO(scheglov) disabled because now 'part of' directive required | |
69 */ | |
70 public void _test_scan_sourceThenLibrary() throws Exception { | |
71 _test_scan_source(); | |
72 server.resetAnalyzeContext(); | |
73 server.scan(moneyLibFile, null); | |
74 listener.waitForIdle(2, FIVE_MINUTES_MS); | |
75 assertTrackedLibraryFiles(server, moneyLibFile); | |
76 server.assertAnalyzeContext(true); | |
77 } | |
78 | |
79 public void test_packages_preference() throws Exception { | 55 public void test_packages_preference() throws Exception { |
80 PackageLibraryManager libMgr = PackageLibraryManagerProvider.getAnyLibraryMa
nager(); | 56 PackageLibraryManager libMgr = PackageLibraryManagerProvider.getAnyLibraryMa
nager(); |
81 assertTrackedLibraryFiles(server); | 57 assertTrackedLibraryFiles(server); |
82 server.assertAnalyzeContext(false); | 58 server.assertAnalyzeContext(false); |
83 | 59 |
84 List<File> packageRoots = Lists.newArrayList(packagesDir); | 60 List<File> packageRoots = Lists.newArrayList(packagesDir); |
85 libMgr.setPackageRoots(packageRoots); | 61 libMgr.setPackageRoots(packageRoots); |
86 try { | 62 try { |
87 server.scan(bankDir, null); | 63 server.scan(bankDir, null); |
88 server.start(); | 64 server.start(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 118 |
143 public void test_scan_libraryThenSource() throws Exception { | 119 public void test_scan_libraryThenSource() throws Exception { |
144 test_scan_library(); | 120 test_scan_library(); |
145 server.resetAnalyzeContext(); | 121 server.resetAnalyzeContext(); |
146 server.scan(simpleMoneySrcFile, null); | 122 server.scan(simpleMoneySrcFile, null); |
147 listener.waitForIdle(2, FIVE_MINUTES_MS); | 123 listener.waitForIdle(2, FIVE_MINUTES_MS); |
148 assertTrackedLibraryFiles(server, moneyLibFile); | 124 assertTrackedLibraryFiles(server, moneyLibFile); |
149 server.assertAnalyzeContext(false); | 125 server.assertAnalyzeContext(false); |
150 } | 126 } |
151 | 127 |
| 128 public void test_scan_source() throws Exception { |
| 129 assertTrackedLibraryFiles(server); |
| 130 server.scan(simpleMoneySrcFile, null); |
| 131 server.start(); |
| 132 listener.waitForIdle(1, FIVE_MINUTES_MS); |
| 133 assertTrackedLibraryFiles(server, simpleMoneySrcFile); |
| 134 server.assertAnalyzeContext(true); |
| 135 } |
| 136 |
| 137 public void test_scan_sourceThenLibrary() throws Exception { |
| 138 test_scan_source(); |
| 139 server.resetAnalyzeContext(); |
| 140 server.scan(moneyLibFile, null); |
| 141 listener.waitForIdle(2, FIVE_MINUTES_MS); |
| 142 assertTrackedLibraryFiles(server, moneyLibFile); |
| 143 server.assertAnalyzeContext(true); |
| 144 } |
| 145 |
152 public void test_scanContent_import() throws Exception { | 146 public void test_scanContent_import() throws Exception { |
153 PrintStringWriter writer = new PrintStringWriter(); | 147 PrintStringWriter writer = new PrintStringWriter(); |
154 writer.println("import 'foo';"); | 148 writer.println("import 'foo';"); |
155 writer.println("main() { }"); | 149 writer.println("main() { }"); |
156 assertScanContent(writer.toString(), Library); | 150 assertScanContent(writer.toString(), Library); |
157 } | 151 } |
158 | 152 |
159 public void test_scanContent_library() throws Exception { | 153 public void test_scanContent_library() throws Exception { |
160 PrintStringWriter writer = new PrintStringWriter(); | 154 PrintStringWriter writer = new PrintStringWriter(); |
161 writer.println("library 'foo';"); | 155 writer.println("library 'foo';"); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 @Override | 232 @Override |
239 protected void tearDown() throws Exception { | 233 protected void tearDown() throws Exception { |
240 server.stop(); | 234 server.stop(); |
241 } | 235 } |
242 | 236 |
243 private void assertScanContent(String content, DartFileType expected) throws I
OException { | 237 private void assertScanContent(String content, DartFileType expected) throws I
OException { |
244 DartFileType actual = ScanTask.scanContent(new ByteArrayInputStream(content.
getBytes()), BUFFER); | 238 DartFileType actual = ScanTask.scanContent(new ByteArrayInputStream(content.
getBytes()), BUFFER); |
245 assertEquals(expected, actual); | 239 assertEquals(expected, actual); |
246 } | 240 } |
247 } | 241 } |
OLD | NEW |