From 5779d2e600d614adee18f35c3b40ba1f6fc616f8 Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Sat, 2 Nov 2024 10:31:39 +0400 Subject: [PATCH] #2934 Implemented tests for the classpath in tests --- embedded/build.gradle.kts | 24 ++++++---- ...EmbeddedPerlPluginInstrumentationTest.java | 10 ++-- .../HtmlMasonPluginInstrumentationTest.java | 12 ++--- .../unit/Mason2PluginInstrumentationTest.java | 12 ++--- .../unit/MojoPluginInstrumentationTest.java | 10 ++-- .../unit/PerlPluginInstrumentationTest.java | 46 +++++++++---------- .../base/PerlInstrumentationTestCase.java | 29 ++++++++++-- ...plateToolkitPluginInstrumentationTest.java | 10 ++-- 8 files changed, 90 insertions(+), 63 deletions(-) diff --git a/embedded/build.gradle.kts b/embedded/build.gradle.kts index b2d4b63c00..db950da162 100644 --- a/embedded/build.gradle.kts +++ b/embedded/build.gradle.kts @@ -16,26 +16,32 @@ fun properties(key: String) = providers.gradleProperty(key) dependencies { + // packaging, which modules to include into this one listOf( - ":plugin:core", ":lang.embedded:core", ).forEach { - compileOnly(project(it)) - testCompileOnly(project(it)) - testRuntimeOnly(project(it)) - } - listOf( - ":lang.embedded:core", - ).forEach { - runtimeOnly(project(it)) intellijPlatform{ pluginModule(implementation(project(it))) } } + + // additional compilation dependencies + listOf( + ":plugin:core", + ).forEach { + compileOnly(project(it)) + testCompileOnly(project(it)) + } + + // Test dependencies testImplementation(testFixtures(project(":plugin"))) + + // Plugin dependencies intellijPlatform { localPlugin(project(":plugin")) } + + // Useinstaller handling intellijPlatform{ val platformVersionProvider: Provider by rootProject.extra create("IC", platformVersionProvider.get(), useInstaller = properties("useInstaller").get().toBoolean()) diff --git a/embedded/src/test/java/unit/EmbeddedPerlPluginInstrumentationTest.java b/embedded/src/test/java/unit/EmbeddedPerlPluginInstrumentationTest.java index f85fa74435..6a67f820eb 100644 --- a/embedded/src/test/java/unit/EmbeddedPerlPluginInstrumentationTest.java +++ b/embedded/src/test/java/unit/EmbeddedPerlPluginInstrumentationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 Alexandr Evstigneev + * Copyright 2015-2024 Alexandr Evstigneev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,15 +29,15 @@ @RunWith(Parameterized.class) public class EmbeddedPerlPluginInstrumentationTest extends PerlInstrumentationTestCase { - public EmbeddedPerlPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls) { - super(cls); + public EmbeddedPerlPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls, @NotNull String patternString) { + super(cls, patternString); } @Parameterized.Parameters(name = "{0}") public static Collection data() { return Arrays.asList(new Object[][]{ - {"plugin.core", PerlParserDefinition.class}, - {"embedded", EmbeddedPerlParserDefinition.class} + {"plugin.core", PerlParserDefinition.class, PLUGIN_PATTERN_STRING}, + {"embedded", EmbeddedPerlParserDefinition.class, EMBEDDED_PATTERN_STRING} }); } } diff --git a/mason/htmlmason/src/test/java/unit/HtmlMasonPluginInstrumentationTest.java b/mason/htmlmason/src/test/java/unit/HtmlMasonPluginInstrumentationTest.java index 3e640f97ca..d475426925 100644 --- a/mason/htmlmason/src/test/java/unit/HtmlMasonPluginInstrumentationTest.java +++ b/mason/htmlmason/src/test/java/unit/HtmlMasonPluginInstrumentationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 Alexandr Evstigneev + * Copyright 2015-2024 Alexandr Evstigneev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,16 +29,16 @@ @RunWith(Parameterized.class) public class HtmlMasonPluginInstrumentationTest extends PerlInstrumentationTestCase { - public HtmlMasonPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls) { - super(cls); + public HtmlMasonPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls, @NotNull String patternString) { + super(cls, patternString); } @Parameterized.Parameters(name = "{0}") public static Collection data() { return Arrays.asList(new Object[][]{ - {"plugin.core", PerlParserDefinition.class}, - {"mason.framework", MasonParserUtil.class}, - {"htmlmason", HTMLMasonParserDefinition.class}, + {"plugin.core", PerlParserDefinition.class, PLUGIN_PATTERN_STRING}, + {"mason.framework", MasonParserUtil.class, MASON_FRAMEWORK_PATTERN_STRING}, + {"htmlmason", HTMLMasonParserDefinition.class, MASON_PATTERN_STRING}, }); } } diff --git a/mason/mason2/src/test/java/unit/Mason2PluginInstrumentationTest.java b/mason/mason2/src/test/java/unit/Mason2PluginInstrumentationTest.java index 731551af88..3d6ad100f7 100644 --- a/mason/mason2/src/test/java/unit/Mason2PluginInstrumentationTest.java +++ b/mason/mason2/src/test/java/unit/Mason2PluginInstrumentationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 Alexandr Evstigneev + * Copyright 2015-2024 Alexandr Evstigneev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,16 +29,16 @@ @RunWith(Parameterized.class) public class Mason2PluginInstrumentationTest extends PerlInstrumentationTestCase { - public Mason2PluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls) { - super(cls); + public Mason2PluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls, @NotNull String patternString) { + super(cls, patternString); } @Parameterized.Parameters(name = "{0}") public static Collection data() { return Arrays.asList(new Object[][]{ - {"plugin.core", PerlParserDefinition.class}, - {"mason.framework", MasonParserUtil.class}, - {"mason2", Mason2ParserDefinition.class}, + {"plugin.core", PerlParserDefinition.class, PLUGIN_PATTERN_STRING}, + {"mason.framework", MasonParserUtil.class, MASON_FRAMEWORK_PATTERN_STRING}, + {"mason2", Mason2ParserDefinition.class, MASON2_PATTERN_STRING}, }); } } diff --git a/mojo/src/test/java/unit/MojoPluginInstrumentationTest.java b/mojo/src/test/java/unit/MojoPluginInstrumentationTest.java index 2502f49b81..5ed542db17 100644 --- a/mojo/src/test/java/unit/MojoPluginInstrumentationTest.java +++ b/mojo/src/test/java/unit/MojoPluginInstrumentationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 Alexandr Evstigneev + * Copyright 2015-2024 Alexandr Evstigneev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,15 +29,15 @@ @RunWith(Parameterized.class) public class MojoPluginInstrumentationTest extends PerlInstrumentationTestCase { - public MojoPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls) { - super(cls); + public MojoPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls, @NotNull String patternString) { + super(cls, patternString); } @Parameterized.Parameters(name = "{0}") public static Collection data() { return Arrays.asList(new Object[][]{ - {"plugin.core", PerlParserDefinition.class}, - {"mojo.core", MojoliciousParserDefinition.class}, + {"plugin.core", PerlParserDefinition.class, PLUGIN_PATTERN_STRING}, + {"mojo.core", MojoliciousParserDefinition.class, MOJO_PATTERN_STRING}, }); } } diff --git a/plugin/src/test/java/unit/PerlPluginInstrumentationTest.java b/plugin/src/test/java/unit/PerlPluginInstrumentationTest.java index f8d0f3985d..ed9c513117 100644 --- a/plugin/src/test/java/unit/PerlPluginInstrumentationTest.java +++ b/plugin/src/test/java/unit/PerlPluginInstrumentationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 Alexandr Evstigneev + * Copyright 2015-2024 Alexandr Evstigneev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,33 +47,33 @@ @RunWith(Parameterized.class) public class PerlPluginInstrumentationTest extends PerlInstrumentationTestCase { - public PerlPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls) { - super(cls); + public PerlPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls, @NotNull String patternString) { + super(cls, patternString); } @Parameterized.Parameters(name = "{0}") public static Collection data() { return Arrays.asList(new Object[][]{ - {"asdf", AsdfTestUtil.getInstrumentationTestClass()}, - {"berrybrew", BerryBrewTestUtil.getInstrumentationTestClass()}, - {"carton", PerlCartonDirectoryConfigurationProvider.class}, - {"copyright", PerlCopyrightsVariablesProvider.class}, - {"core", PerlParserDefinition.class}, - {"coverage", PerlCoverageEnabledConfiguration.class}, - {"cpan", PerlInstallPackagesWithCpanAction.class}, - {"cpanminus", PerlInstallCpanmAction.class}, - {"debugger", PerlDebuggerProgramRunner.class}, - {"docker", PerlDockerTestUtil.getInstrumentationTestClass()}, - {"idea", PerlIdeaTestUtil.getInstrumentationTestClass()}, - {"intelliLang", PerlInjectionSupport.class}, - {"makeMaker", PerlMakeMakerDirectoryConfigurationProvider.class}, - {"moduleBuild", PerlModuleBuildDirectoryConfigurationProvider.class}, - {"perlInstall", PerlInstallHandlerBase.class}, - {"perlbrew", PerlBrewTestUtil.getInstrumentationTestClass()}, - {"plenv", PlenvTestUtil.getInstrumentationTestClass()}, - {"profiler", PerlProfilerBundle.class}, - {"terminal", PerlLocalTerminalCustomizer.class}, - {"wsl", PerlWslInputFilterProvider.class}, + {"asdf", AsdfTestUtil.getInstrumentationTestClass(), PLUGIN_PATTERN_STRING}, + {"berrybrew", BerryBrewTestUtil.getInstrumentationTestClass(), PLUGIN_PATTERN_STRING}, + {"carton", PerlCartonDirectoryConfigurationProvider.class, PLUGIN_PATTERN_STRING}, + {"copyright", PerlCopyrightsVariablesProvider.class, PLUGIN_PATTERN_STRING}, + {"core", PerlParserDefinition.class, PLUGIN_PATTERN_STRING}, + {"coverage", PerlCoverageEnabledConfiguration.class, PLUGIN_PATTERN_STRING}, + {"cpan", PerlInstallPackagesWithCpanAction.class, PLUGIN_PATTERN_STRING}, + {"cpanminus", PerlInstallCpanmAction.class, PLUGIN_PATTERN_STRING}, + {"debugger", PerlDebuggerProgramRunner.class, PLUGIN_PATTERN_STRING}, + {"docker", PerlDockerTestUtil.getInstrumentationTestClass(), PLUGIN_PATTERN_STRING}, + {"idea", PerlIdeaTestUtil.getInstrumentationTestClass(), PLUGIN_PATTERN_STRING}, + {"intelliLang", PerlInjectionSupport.class, PLUGIN_PATTERN_STRING}, + {"makeMaker", PerlMakeMakerDirectoryConfigurationProvider.class, PLUGIN_PATTERN_STRING}, + {"moduleBuild", PerlModuleBuildDirectoryConfigurationProvider.class, PLUGIN_PATTERN_STRING}, + {"perlInstall", PerlInstallHandlerBase.class, PLUGIN_PATTERN_STRING}, + {"perlbrew", PerlBrewTestUtil.getInstrumentationTestClass(), PLUGIN_PATTERN_STRING}, + {"plenv", PlenvTestUtil.getInstrumentationTestClass(), PLUGIN_PATTERN_STRING}, + {"profiler", PerlProfilerBundle.class, PLUGIN_PATTERN_STRING}, + {"terminal", PerlLocalTerminalCustomizer.class, PLUGIN_PATTERN_STRING}, + {"wsl", PerlWslInputFilterProvider.class, PLUGIN_PATTERN_STRING}, }); } } diff --git a/plugin/src/testFixtures/java/base/PerlInstrumentationTestCase.java b/plugin/src/testFixtures/java/base/PerlInstrumentationTestCase.java index 0634d25a6a..bb7857f04e 100644 --- a/plugin/src/testFixtures/java/base/PerlInstrumentationTestCase.java +++ b/plugin/src/testFixtures/java/base/PerlInstrumentationTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 Alexandr Evstigneev + * Copyright 2015-2024 Alexandr Evstigneev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,19 +23,31 @@ import org.junit.Test; import org.junit.experimental.categories.Category; +import java.util.regex.Pattern; import java.util.stream.Stream; +@SuppressWarnings("JUnitMixedFramework") @Category(Light.class) public abstract class PerlInstrumentationTestCase extends BasePlatformTestCase { - private final Class myClass; + protected static final String PLUGIN_PATTERN_STRING = "/plugin/build/libs/plugin-.+?\\.jar!"; + // this is wrong, should be build/libs/lang\\.embedded-.+?\\.jar! + protected static final String EMBEDDED_PATTERN_STRING = "/embedded/core/build/libs/core-.+?\\.jar"; + protected static final String MOJO_PATTERN_STRING = "/mojo/core/build/libs/core-.+?\\.jar!"; + protected static final String TT2_PATTERN_STRING = "/tt2/core/build/libs/core-.+?\\.jar!"; + protected static final String MASON_FRAMEWORK_PATTERN_STRING = "/mason/framework/build/libs/lang\\.mason\\.framework-.+?\\.jar!"; + protected static final String MASON_PATTERN_STRING = "/mason/htmlmason/core/build/libs/core-.+?\\.jar!"; + protected static final String MASON2_PATTERN_STRING = "/mason/mason2/core/build/libs/core-.+?\\.jar!"; + private final @NotNull Class myClass; - protected PerlInstrumentationTestCase(@NotNull Class aClass) { + private final @NotNull Pattern myClassPathPattern; + + protected PerlInstrumentationTestCase(@NotNull Class aClass, @NotNull String patternString) { myClass = aClass; + myClassPathPattern = Pattern.compile(patternString); } - @SuppressWarnings("JUnitMixedFramework") @Test public void testDependencyInstrumentation() { var classLoader = myClass.getClassLoader(); @@ -45,4 +57,13 @@ public void testDependencyInstrumentation() { "Class " + myClass + " does not look instrumented, classpaths: " + pathClassLoader.getClassPath().getBaseUrls(), Stream.of(myClass.getDeclaredMethods()).anyMatch(m -> m.getName().startsWith("$$$reportNull$$$"))); } + + @Test + public void testProperClassSource() { + var className = myClass.getName(); + var classPath = myClass.getResource("/" + className.replace('.', '/') + ".class").getPath(); + if (!myClassPathPattern.matcher(classPath).find()) { + fail("Classpath for the " + className + " is expected to match " + myClassPathPattern + ", but was " + classPath); + } + } } diff --git a/tt2/src/test/java/unit/TemplateToolkitPluginInstrumentationTest.java b/tt2/src/test/java/unit/TemplateToolkitPluginInstrumentationTest.java index eda4a5ac71..558abd6e05 100644 --- a/tt2/src/test/java/unit/TemplateToolkitPluginInstrumentationTest.java +++ b/tt2/src/test/java/unit/TemplateToolkitPluginInstrumentationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 Alexandr Evstigneev + * Copyright 2015-2024 Alexandr Evstigneev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,15 +29,15 @@ @RunWith(Parameterized.class) public class TemplateToolkitPluginInstrumentationTest extends PerlInstrumentationTestCase { - public TemplateToolkitPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls) { - super(cls); + public TemplateToolkitPluginInstrumentationTest(@NotNull String ignoredName, @NotNull Class cls, @NotNull String patternString) { + super(cls, patternString); } @Parameterized.Parameters(name = "{0}") public static Collection data() { return Arrays.asList(new Object[][]{ - {"plugin.core", PerlParserDefinition.class}, - {"tt2", TemplateToolkitParserDefinition.class} + {"plugin.core", PerlParserDefinition.class, PLUGIN_PATTERN_STRING}, + {"tt2", TemplateToolkitParserDefinition.class, TT2_PATTERN_STRING} }); } }