Codegen tests: don't generate twice when a test fails
This commit is contained in:
@@ -230,17 +230,14 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String generateToText() {
|
protected String generateToText() {
|
||||||
if (alreadyGenerated == null)
|
if (alreadyGenerated == null) {
|
||||||
alreadyGenerated = generateCommon(ClassBuilderFactories.TEST, myEnvironment, myFiles);
|
alreadyGenerated = generateCommon(myEnvironment, myFiles);
|
||||||
|
}
|
||||||
return alreadyGenerated.getFactory().createText();
|
return alreadyGenerated.getFactory().createText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static GenerationState generateCommon(
|
protected static GenerationState generateCommon(@NotNull JetCoreEnvironment environment, @NotNull CodegenTestFiles files) {
|
||||||
@NotNull ClassBuilderFactory classBuilderFactory,
|
|
||||||
@NotNull JetCoreEnvironment environment,
|
|
||||||
@NotNull CodegenTestFiles files
|
|
||||||
) {
|
|
||||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||||
environment.getProject(),
|
environment.getProject(),
|
||||||
files.getPsiFiles(),
|
files.getPsiFiles(),
|
||||||
@@ -250,7 +247,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
||||||
CompilerConfiguration configuration = environment.getConfiguration();
|
CompilerConfiguration configuration = environment.getConfiguration();
|
||||||
GenerationState state = new GenerationState(
|
GenerationState state = new GenerationState(
|
||||||
environment.getProject(), classBuilderFactory, Progress.DEAF, analyzeExhaust.getBindingContext(), files.getPsiFiles(),
|
environment.getProject(), ClassBuilderFactories.TEST, Progress.DEAF, analyzeExhaust.getBindingContext(), files.getPsiFiles(),
|
||||||
configuration.get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
configuration.get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
||||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
|
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
|
||||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
|
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
|
||||||
@@ -291,25 +288,25 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected ClassFileFactory generateClassesInFile() {
|
protected ClassFileFactory generateClassesInFile() {
|
||||||
GenerationState generationState = generateClassesInFileGetState();
|
return generateClassesInFileGetState().getFactory();
|
||||||
return generationState.getFactory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected GenerationState generateClassesInFileGetState() {
|
protected GenerationState generateClassesInFileGetState() {
|
||||||
GenerationState generationState;
|
|
||||||
try {
|
try {
|
||||||
generationState = generateCommon(ClassBuilderFactories.TEST, myEnvironment, myFiles);
|
if (alreadyGenerated == null) {
|
||||||
|
alreadyGenerated = generateCommon(myEnvironment, myFiles);
|
||||||
if (DxChecker.RUN_DX_CHECKER) {
|
|
||||||
DxChecker.check(generationState.getFactory());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DxChecker.RUN_DX_CHECKER) {
|
||||||
|
DxChecker.check(alreadyGenerated.getFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
return alreadyGenerated;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
throw ExceptionUtils.rethrow(e);
|
throw ExceptionUtils.rethrow(e);
|
||||||
}
|
}
|
||||||
return generationState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Method generateFunction() {
|
protected Method generateFunction() {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
||||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK);
|
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK);
|
||||||
JetCoreEnvironment tmpEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
JetCoreEnvironment tmpEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
|
||||||
GenerationState state = generateCommon(ClassBuilderFactories.TEST, tmpEnvironment,
|
GenerationState state = generateCommon(tmpEnvironment,
|
||||||
CodegenTestFiles.create(tmpEnvironment.getProject(), new String[] {"notNullAssertions/noAssertionsForKotlin.kt"}));
|
CodegenTestFiles.create(tmpEnvironment.getProject(), new String[] {"notNullAssertions/noAssertionsForKotlin.kt"}));
|
||||||
File compiledDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes");
|
File compiledDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes");
|
||||||
CompileEnvironmentUtil.writeToOutputDirectory(state.getFactory(), compiledDirectory);
|
CompileEnvironmentUtil.writeToOutputDirectory(state.getFactory(), compiledDirectory);
|
||||||
|
|||||||
Reference in New Issue
Block a user