@TestDataPath and @TestDataFile annotation added to facilitate navigation to test data
This commit is contained in:
@@ -35,6 +35,7 @@ import com.intellij.psi.PsiFileFactory;
|
|||||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||||
import com.intellij.testFramework.LightVirtualFile;
|
import com.intellij.testFramework.LightVirtualFile;
|
||||||
|
import com.intellij.testFramework.TestDataFile;
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
@@ -670,6 +671,10 @@ public class JetTestUtils {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String navigationMetadata(@TestDataFile String testFile) {
|
||||||
|
return testFile;
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertAllTestsPresentByMetadata(
|
public static void assertAllTestsPresentByMetadata(
|
||||||
@NotNull Class<?> testCaseClass,
|
@NotNull Class<?> testCaseClass,
|
||||||
@NotNull File testDataDir,
|
@NotNull File testDataDir,
|
||||||
|
|||||||
+21
-14
@@ -1,22 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2013 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.generators.tests.generator;
|
package org.jetbrains.jet.generators.tests.generator;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -49,6 +50,12 @@ public class DelegatingTestClassModel implements TestClassModel {
|
|||||||
return delegate.isEmpty();
|
return delegate.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getDataPathRoot() {
|
||||||
|
return delegate.getDataPathRoot();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDataString() {
|
public String getDataString() {
|
||||||
return delegate.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.openapi.util.text.StringUtil;
|
||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.utils.Printer;
|
import org.jetbrains.jet.utils.Printer;
|
||||||
|
|
||||||
@@ -155,6 +156,12 @@ public class SimpleTestClassModel implements TestClassModel {
|
|||||||
return JetTestUtils.getFilePath(rootFile);
|
return JetTestUtils.getFilePath(rootFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getDataPathRoot() {
|
||||||
|
return "$PROJECT_ROOT";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return testClassName;
|
return testClassName;
|
||||||
|
|||||||
+2
-1
@@ -42,7 +42,8 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
|||||||
@Override
|
@Override
|
||||||
public void generateBody(@NotNull Printer p) {
|
public void generateBody(@NotNull Printer p) {
|
||||||
String filePath = JetTestUtils.getFilePath(file) + (file.isDirectory() ? "/" : "");
|
String filePath = JetTestUtils.getFilePath(file) + (file.isDirectory() ? "/" : "");
|
||||||
p.println(doTestMethodName, "(\"", filePath, "\");");
|
p.println("String fileName = JetTestUtils.navigationMetadata(\"", filePath, "\");");
|
||||||
|
p.println(doTestMethodName, "(fileName);");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
|||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.utils.Printer;
|
import org.jetbrains.jet.utils.Printer;
|
||||||
|
|
||||||
@@ -105,6 +106,12 @@ public class SingleClassTestModel implements TestClassModel {
|
|||||||
return JetTestUtils.getFilePath(rootFile);
|
return JetTestUtils.getFilePath(rootFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getDataPathRoot() {
|
||||||
|
return "$PROJECT_ROOT";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return testClassName;
|
return testClassName;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.generators.tests.generator;
|
package org.jetbrains.jet.generators.tests.generator;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -29,4 +30,7 @@ public interface TestClassModel extends TestEntityModel {
|
|||||||
Collection<TestMethodModel> getTestMethods();
|
Collection<TestMethodModel> getTestMethods();
|
||||||
|
|
||||||
boolean isEmpty();
|
boolean isEmpty();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String getDataPathRoot();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
|||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.di.GeneratorsFileUtil;
|
import org.jetbrains.jet.di.GeneratorsFileUtil;
|
||||||
import org.jetbrains.jet.utils.Printer;
|
import org.jetbrains.jet.utils.Printer;
|
||||||
@@ -32,6 +33,8 @@ import java.util.Collections;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TestGenerator {
|
public class TestGenerator {
|
||||||
|
public static final String NAVIGATION_METADATA = "navigationMetadata";
|
||||||
|
|
||||||
private static final Set<String> GENERATED_FILES = ContainerUtil.newHashSet();
|
private static final Set<String> GENERATED_FILES = ContainerUtil.newHashSet();
|
||||||
|
|
||||||
private final String suiteClassPackage;
|
private final String suiteClassPackage;
|
||||||
@@ -66,6 +69,7 @@ public class TestGenerator {
|
|||||||
p.println(FileUtil.loadFile(new File("injector-generator/copyright.txt")));
|
p.println(FileUtil.loadFile(new File("injector-generator/copyright.txt")));
|
||||||
p.println("package ", suiteClassPackage, ";");
|
p.println("package ", suiteClassPackage, ";");
|
||||||
p.println();
|
p.println();
|
||||||
|
p.println("import com.intellij.testFramework.TestDataPath;");
|
||||||
p.println("import junit.framework.Test;");
|
p.println("import junit.framework.Test;");
|
||||||
p.println("import junit.framework.TestSuite;");
|
p.println("import junit.framework.TestSuite;");
|
||||||
p.println("import org.jetbrains.jet.JetTestUtils;");
|
p.println("import org.jetbrains.jet.JetTestUtils;");
|
||||||
@@ -115,6 +119,12 @@ public class TestGenerator {
|
|||||||
public String getDataString() {
|
public String getDataString() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getDataPathRoot() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +136,8 @@ public class TestGenerator {
|
|||||||
String staticModifier = isStatic ? "static " : "";
|
String staticModifier = isStatic ? "static " : "";
|
||||||
generateMetadata(p, testClassModel);
|
generateMetadata(p, testClassModel);
|
||||||
|
|
||||||
|
generateTestDataPath(p, testClassModel);
|
||||||
|
|
||||||
generateInnerClassesAnnotation(p, testClassModel);
|
generateInnerClassesAnnotation(p, testClassModel);
|
||||||
|
|
||||||
p.println("public " + staticModifier + "class ", testClassModel.getName(), " extends ", baseTestClassName, " {");
|
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) {
|
private static void generateInnerClassesAnnotation(Printer p, TestClassModel testClassModel) {
|
||||||
Collection<TestClassModel> innerTestClasses = testClassModel.getInnerTestClasses();
|
Collection<TestClassModel> innerTestClasses = testClassModel.getInnerTestClasses();
|
||||||
if (innerTestClasses.isEmpty()) return;
|
if (innerTestClasses.isEmpty()) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user