Skip to content

Commit

Permalink
Codegen tests: don't generate twice when a test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
udalov committed Jan 25, 2013
1 parent df5b809 commit 639aa9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
Expand Up @@ -230,17 +230,14 @@ protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens, bool
}

protected String generateToText() {
if (alreadyGenerated == null)
alreadyGenerated = generateCommon(ClassBuilderFactories.TEST, myEnvironment, myFiles);
if (alreadyGenerated == null) {
alreadyGenerated = generateCommon(myEnvironment, myFiles);
}
return alreadyGenerated.getFactory().createText();
}

@NotNull
protected static GenerationState generateCommon(
@NotNull ClassBuilderFactory classBuilderFactory,
@NotNull JetCoreEnvironment environment,
@NotNull CodegenTestFiles files
) {
protected static GenerationState generateCommon(@NotNull JetCoreEnvironment environment, @NotNull CodegenTestFiles files) {
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationAndCheckForErrors(
environment.getProject(),
files.getPsiFiles(),
Expand All @@ -250,7 +247,7 @@ protected static GenerationState generateCommon(
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
CompilerConfiguration configuration = environment.getConfiguration();
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.GENERATE_NOT_NULL_ASSERTIONS, true),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
Expand Down Expand Up @@ -291,25 +288,25 @@ protected Class loadClass(String fqName, @NotNull ClassFileFactory state) {

@NotNull
protected ClassFileFactory generateClassesInFile() {
GenerationState generationState = generateClassesInFileGetState();
return generationState.getFactory();
return generateClassesInFileGetState().getFactory();
}

@NotNull
protected GenerationState generateClassesInFileGetState() {
GenerationState generationState;
try {
generationState = generateCommon(ClassBuilderFactories.TEST, myEnvironment, myFiles);
if (alreadyGenerated == null) {
alreadyGenerated = generateCommon(myEnvironment, myFiles);
}

if (DxChecker.RUN_DX_CHECKER) {
DxChecker.check(generationState.getFactory());
DxChecker.check(alreadyGenerated.getFactory());
}

return alreadyGenerated;
} catch (Throwable e) {
System.out.println(generateToText());
throw ExceptionUtils.rethrow(e);
}
return generationState;
}

protected Method generateFunction() {
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void testNoAssertionsForKotlinFromBinary() throws Exception {
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK);
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"}));
File compiledDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes");
CompileEnvironmentUtil.writeToOutputDirectory(state.getFactory(), compiledDirectory);
Expand Down

0 comments on commit 639aa9e

Please sign in to comment.