@TestDataPath and @TestDataFile annotation added to facilitate navigation to test data

This commit is contained in:
Andrey Breslav
2014-09-08 18:32:06 +04:00
parent e274af7be8
commit cb07c65b7d
7 changed files with 65 additions and 15 deletions
@@ -35,6 +35,7 @@ import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.impl.PsiFileFactoryImpl;
import com.intellij.rt.execution.junit.FileComparisonFailure;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.testFramework.TestDataFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.Processor;
@@ -670,6 +671,10 @@ public class JetTestUtils {
return builder.toString();
}
public static String navigationMetadata(@TestDataFile String testFile) {
return testFile;
}
public static void assertAllTestsPresentByMetadata(
@NotNull Class<?> testCaseClass,
@NotNull File testDataDir,
@@ -1,22 +1,23 @@
/*
* 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.
*/
* 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.generators.tests.generator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -49,6 +50,12 @@ public class DelegatingTestClassModel implements TestClassModel {
return delegate.isEmpty();
}
@Nullable
@Override
public String getDataPathRoot() {
return delegate.getDataPathRoot();
}
@Override
public String getDataString() {
return delegate.getDataString();
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.utils.Printer;
@@ -155,6 +156,12 @@ public class SimpleTestClassModel implements TestClassModel {
return JetTestUtils.getFilePath(rootFile);
}
@Nullable
@Override
public String getDataPathRoot() {
return "$PROJECT_ROOT";
}
@Override
public String getName() {
return testClassName;
@@ -42,7 +42,8 @@ public class SimpleTestMethodModel implements TestMethodModel {
@Override
public void generateBody(@NotNull Printer p) {
String filePath = JetTestUtils.getFilePath(file) + (file.isDirectory() ? "/" : "");
p.println(doTestMethodName, "(\"", filePath, "\");");
p.println("String fileName = JetTestUtils.navigationMetadata(\"", filePath, "\");");
p.println(doTestMethodName, "(fileName);");
}
@Override
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.utils.Printer;
@@ -105,6 +106,12 @@ public class SingleClassTestModel implements TestClassModel {
return JetTestUtils.getFilePath(rootFile);
}
@Nullable
@Override
public String getDataPathRoot() {
return "$PROJECT_ROOT";
}
@Override
public String getName() {
return testClassName;
@@ -17,6 +17,7 @@
package org.jetbrains.jet.generators.tests.generator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -29,4 +30,7 @@ public interface TestClassModel extends TestEntityModel {
Collection<TestMethodModel> getTestMethods();
boolean isEmpty();
@Nullable
String getDataPathRoot();
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.containers.ContainerUtil;
import junit.framework.TestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.di.GeneratorsFileUtil;
import org.jetbrains.jet.utils.Printer;
@@ -32,6 +33,8 @@ import java.util.Collections;
import java.util.Set;
public class TestGenerator {
public static final String NAVIGATION_METADATA = "navigationMetadata";
private static final Set<String> GENERATED_FILES = ContainerUtil.newHashSet();
private final String suiteClassPackage;
@@ -66,6 +69,7 @@ public class TestGenerator {
p.println(FileUtil.loadFile(new File("injector-generator/copyright.txt")));
p.println("package ", suiteClassPackage, ";");
p.println();
p.println("import com.intellij.testFramework.TestDataPath;");
p.println("import junit.framework.Test;");
p.println("import junit.framework.TestSuite;");
p.println("import org.jetbrains.jet.JetTestUtils;");
@@ -115,6 +119,12 @@ public class TestGenerator {
public String getDataString() {
return null;
}
@Nullable
@Override
public String getDataPathRoot() {
return null;
}
}, false);
}
@@ -126,6 +136,8 @@ public class TestGenerator {
String staticModifier = isStatic ? "static " : "";
generateMetadata(p, testClassModel);
generateTestDataPath(p, testClassModel);
generateInnerClassesAnnotation(p, testClassModel);
p.println("public " + staticModifier + "class ", testClassModel.getName(), " extends ", baseTestClassName, " {");
@@ -199,6 +211,13 @@ public class TestGenerator {
}
}
private static void generateTestDataPath(Printer p, TestClassModel testClassModel) {
String dataPathRoot = testClassModel.getDataPathRoot();
if (dataPathRoot != null) {
p.println("@TestDataPath(\"", dataPathRoot, "\")");
}
}
private static void generateInnerClassesAnnotation(Printer p, TestClassModel testClassModel) {
Collection<TestClassModel> innerTestClasses = testClassModel.getInnerTestClasses();
if (innerTestClasses.isEmpty()) return;