001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.dev.cfg;
017:
018: import com.google.gwt.core.ext.UnableToCompleteException;
019: import com.google.gwt.dev.GWTCompiler;
020: import com.google.gwt.dev.util.Util;
021: import com.google.gwt.dev.util.log.AbstractTreeLogger;
022: import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
023:
024: import junit.framework.TestCase;
025:
026: import java.io.File;
027:
028: /**
029: * Tests various permutations of the GWT module's &public& tag,
030: * specifically its ant-like inclusion support.
031: */
032: public class PublicTagTest extends TestCase {
033:
034: /**
035: * Provides a convenient interface to the {@link GWTCompiler}. This test
036: * cannot simply call {@link GWTCompiler#main(String[])} since it always
037: * terminates with a call to {@link System#exit(int)}.
038: */
039: private static class Compiler extends GWTCompiler {
040: /**
041: * Run the {@link GWTCompiler} with the specified arguments.
042: *
043: * @param args arguments passed to the compiler.
044: */
045: static void compile(String[] args) {
046: try {
047: final Compiler compiler = new Compiler();
048: if (compiler.processArgs(args)) {
049: final AbstractTreeLogger logger = new PrintWriterTreeLogger();
050: logger.setMaxDetail(compiler.getLogLevel());
051: compiler.distill(logger, ModuleDefLoader
052: .loadFromClassPath(logger, compiler
053: .getModuleName()));
054: }
055: } catch (UnableToCompleteException e) {
056: throw new RuntimeException("Compilation failed.", e);
057: }
058: }
059: }
060:
061: public void testPublicTag() {
062: // Find the current directory
063: String userDir = System.getProperty("user.dir");
064: assertNotNull(userDir);
065: File curDir = new File(userDir);
066: assertTrue(curDir.isDirectory());
067:
068: // Our module name is the same as this class's name
069: String moduleName = PublicTagTest.class.getName();
070:
071: // Find our module output directory and delete it
072: File moduleDir = new File(curDir, "www/" + moduleName);
073: if (moduleDir.exists()) {
074: Util.recursiveDelete(moduleDir, false);
075: }
076: assertFalse(moduleDir.exists());
077:
078: // Compile the dummy app; suppress output to stdout
079: Compiler.compile(new String[] { moduleName, "-logLevel",
080: "ERROR", "-out", "www" });
081:
082: // Check the output folder
083: assertTrue(new File(moduleDir, "good0.html").exists());
084: assertTrue(new File(moduleDir, "good1.html").exists());
085: assertTrue(new File(moduleDir, "bar/good.html").exists());
086: assertTrue(new File(moduleDir, "good2.html").exists());
087: assertTrue(new File(moduleDir, "good3.html").exists());
088: assertTrue(new File(moduleDir, "good4.html").exists());
089: assertTrue(new File(moduleDir, "good5.html").exists());
090: assertTrue(new File(moduleDir, "good6.html").exists());
091: assertTrue(new File(moduleDir, "good7.html").exists());
092: assertTrue(new File(moduleDir, "good8.html").exists());
093: assertTrue(new File(moduleDir, "good10.html").exists());
094: assertTrue(new File(moduleDir, "good11.html").exists());
095: assertTrue(new File(moduleDir, "good9.html").exists());
096: assertTrue(new File(moduleDir, "bar/CVS/good.html").exists());
097: assertTrue(new File(moduleDir, "CVS/good.html").exists());
098: assertTrue(new File(moduleDir, "GOOD/bar/GOOD/good.html")
099: .exists());
100: assertTrue(new File(moduleDir, "GOOD/good.html").exists());
101:
102: assertFalse(new File(moduleDir, "bad.Html").exists());
103: assertFalse(new File(moduleDir, "bar/CVS/bad.html").exists());
104: assertFalse(new File(moduleDir, "CVS/bad.html").exists());
105: assertFalse(new File(moduleDir, "bad1.html").exists());
106: assertFalse(new File(moduleDir, "bad2.html").exists());
107: assertFalse(new File(moduleDir, "bad3.html").exists());
108: assertFalse(new File(moduleDir, "bad.html").exists());
109: assertFalse(new File(moduleDir, "bar/bad.html").exists());
110: assertFalse(new File(moduleDir, "GOOD/bar/bad.html").exists());
111: assertFalse(new File(moduleDir, "GOOD/bar/GOOD/bar/bad.html")
112: .exists());
113: }
114:
115: }
|