Module descriptions in XML

This commit is contained in:
Andrey Breslav
2013-04-26 20:21:21 +04:00
parent 3673f8003b
commit 42505246b8
25 changed files with 833 additions and 2 deletions
@@ -0,0 +1,63 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.modules.xml;
import com.intellij.openapi.util.io.FileUtil;
import junit.framework.TestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
import org.jetbrains.jet.cli.common.modules.ModuleDescription;
import org.jetbrains.jet.cli.common.modules.ModuleXmlParser;
import org.jetbrains.jet.utils.Printer;
import java.io.File;
import java.io.IOException;
import java.util.List;
public abstract class AbstractModuleXmlParserTest extends TestCase {
protected void doTest(String xmlPath) throws IOException {
File txtFile = new File(FileUtil.getNameWithoutExtension(xmlPath) + ".txt");
List<ModuleDescription> result = ModuleXmlParser.parse(xmlPath, new MessageCollector() {
@Override
public void report(
@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location
) {
throw new AssertionError(MessageRenderer.PLAIN.render(severity, message, location));
}
});
StringBuilder sb = new StringBuilder();
Printer p = new Printer(sb);
for (ModuleDescription description : result) {
p.println(description);
}
String actual = sb.toString();
if (!txtFile.exists()) {
FileUtil.writeToFile(txtFile, actual);
fail("Expected data file does not exist. A new file created: " + txtFile);
}
assertEquals(FileUtil.loadFile(txtFile), actual);
}
}
@@ -0,0 +1,68 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.modules.xml;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.TestMetadata;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/modules.xml")
public class ModuleXmlParserTestGenerated extends AbstractModuleXmlParserTest {
public void testAllFilesPresentInModules_xml() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/modules.xml"), Pattern.compile("^(.+)\\.xml$"), true);
}
@TestMetadata("allOnce.xml")
public void testAllOnce() throws Exception {
doTest("compiler/testData/modules.xml/allOnce.xml");
}
@TestMetadata("comments.xml")
public void testComments() throws Exception {
doTest("compiler/testData/modules.xml/comments.xml");
}
@TestMetadata("empty.xml")
public void testEmpty() throws Exception {
doTest("compiler/testData/modules.xml/empty.xml");
}
@TestMetadata("emptyModule.xml")
public void testEmptyModule() throws Exception {
doTest("compiler/testData/modules.xml/emptyModule.xml");
}
@TestMetadata("manyTimes.xml")
public void testManyTimes() throws Exception {
doTest("compiler/testData/modules.xml/manyTimes.xml");
}
@TestMetadata("onlySources.xml")
public void testOnlySources() throws Exception {
doTest("compiler/testData/modules.xml/onlySources.xml");
}
@TestMetadata("twoModules.xml")
public void testTwoModules() throws Exception {
doTest("compiler/testData/modules.xml/twoModules.xml");
}
}