From 67db742e160a65372565d06148a8f8fccdcc212a Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 7 Feb 2018 19:51:44 +0100 Subject: [PATCH] fix GroovyCompilerTest, add a test for failing single file recompilation --- .../groovy/compiler/GroovyCompilerTest.groovy | 49 +++++++++++++++++-- .../compiler/GroovyCompilerTestCase.groovy | 2 + 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy index 1e19ca528beb..c74af41faef9 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy @@ -561,7 +561,7 @@ class Indirect { touch(used.virtualFile) touch(main) - assertEmpty make() + assert make().collect { it.message } == chunkRebuildMessage('Groovy stub generator') assertEmpty compileModule(myModule) assertEmpty compileModule(myModule) @@ -577,6 +577,8 @@ class Indirect { assert findClassFile('Used2') == null } + protected abstract List chunkRebuildMessage(String builder) + void testClassLoadingDuringBytecodeGeneration() { def used = myFixture.addFileToProject('Used.groovy', 'class Used { }') def java = myFixture.addFileToProject('Java.java', ''' @@ -595,7 +597,7 @@ class Main { touch(used.virtualFile) touch(main) - assertEmpty make() + assert make().collect { it.message } == chunkRebuildMessage("Groovy compiler") } void testMakeInDependentModuleAfterChunkRebuild() { @@ -613,7 +615,7 @@ class Main { touch(main) setFileText(dep, 'class Dep { String prop = new Used().getProp(); }') - assertEmpty make() + assert make().collect { it.message } == chunkRebuildMessage('Groovy stub generator') } void "test extend package-private class from another module"() { @@ -815,7 +817,7 @@ string touch bar3.virtualFile touch using.virtualFile - assertEmpty make() + assert make().collect { it.message } == chunkRebuildMessage('Groovy compiler') } void "test rename class to java and touch its usage"() { @@ -941,6 +943,36 @@ class AppTest { assert !make().find { it.category == CompilerMessageCategory.ERROR } } + void "test recompile one file that triggers chunk rebuild inside"() { + myFixture.addFileToProject('BuildContext.groovy', ''' +@groovy.transform.CompileStatic +class BuildContext { + static BuildContext createContext(PropTools tools) { return BuildContextImpl.create(tools) } +} + +''') + myFixture.addFileToProject('PropTools.groovy', 'class PropTools { SomeTool someTool }') + myFixture.addFileToProject('SomeTool.groovy', 'interface SomeTool { void call(BuildContext ctx) }') + def subText = ''' +@groovy.transform.CompileStatic +class BuildContextImpl extends BuildContext { + static BuildContextImpl create(PropTools tools) { return new BuildContextImpl() } + void foo(SomeTool tool) { tool.call(this) } +} +''' + def sub = myFixture.addFileToProject('BuildContextImpl.groovy', subText) + assertEmpty(make()) + + setFileText(sub, subText + ' ') + assert make().collect { it.message } == chunkRebuildMessage('Groovy compiler') + def fileMessages = compileFiles(sub.virtualFile) + if (this instanceof GroovycTest) { + assert fileMessages.collect { it.message == 'Consider building whole project or rebuilding the module' } + } else { + assert fileMessages.empty + } + } + void "test report real compilation errors"() { addModule('another', true) @@ -984,6 +1016,10 @@ class Bar {}''' assert msg.message.contains('org.apache.commons.logging.Log') } + protected List chunkRebuildMessage(String builder) { + return ['Builder "' + builder + '" requested rebuild of module chunk "mainModule"'] + } + } static class EclipseTest extends GroovyCompilerTest { @@ -1008,5 +1044,10 @@ class Bar {}''' super.runTest() } + + protected List chunkRebuildMessage(String builder) { + return [] + } + } } \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy index 8b4c16c5e670..898e9a707db3 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy @@ -12,6 +12,7 @@ import com.intellij.execution.executors.DefaultRunExecutor import com.intellij.execution.impl.DefaultJavaProgramRunner import com.intellij.execution.process.* import com.intellij.execution.runners.ProgramRunner +import com.intellij.module.ModuleGroupTestsKt import com.intellij.openapi.Disposable import com.intellij.openapi.application.Result import com.intellij.openapi.command.WriteCommandAction @@ -66,6 +67,7 @@ abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase imp @Override protected void setUp() throws Exception { super.setUp() + ModuleGroupTestsKt.renameModule(myModule, "mainModule") myCompilerTester = new CompilerTester(myModule) }