-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2934 Implemented tests for the classpath in tests #2935
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Object[]> 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} | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Constants are properly defined but EMBEDDED_PATTERN_STRING needs attention The constants are defined in the parent class
The comment states: "this is wrong, should be build/libs/lang\.embedded-.+?\.jar!" 🔗 Analysis chainLGTM! Test data structure properly updated. The test data array has been correctly extended to include the pattern strings. Let's verify the pattern string constants are properly defined in the parent class: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify that PLUGIN_PATTERN_STRING and EMBEDDED_PATTERN_STRING constants exist in PerlInstrumentationTestCase
# Search for the constant definitions
ast-grep --pattern 'class PerlInstrumentationTestCase {
$$$
$_ PLUGIN_PATTERN_STRING = $_;
$$$
$_ EMBEDDED_PATTERN_STRING = $_;
$$$
}'
Length of output: 146 Script: #!/bin/bash
# Let's try a different approach to find these constants
# First, let's find the parent test class file
fd -e java PerlInstrumentationTestCase
# Then let's search for the constants with ripgrep for better context
rg "PLUGIN_PATTERN_STRING|EMBEDDED_PATTERN_STRING" -A 2 -B 2
Length of output: 7561 |
||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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!"; | ||||||||||||||||||||||||||||||||||
Comment on lines
+33
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect pattern for EMBEDDED_PATTERN_STRING As noted in the comment, the pattern for embedded library path is incorrect. It's missing the '!' terminator and uses incorrect path structure. Apply this fix: - protected static final String EMBEDDED_PATTERN_STRING = "/embedded/core/build/libs/core-.+?\\.jar";
+ protected static final String EMBEDDED_PATTERN_STRING = "/embedded/build/libs/lang\\.embedded-.+?\\.jar!"; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
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); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
Comment on lines
+61
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider improving test robustness and error reporting The new test method is good, but could be enhanced in two ways:
Consider this enhancement: @Test
public void testProperClassSource() {
var className = myClass.getName();
- var classPath = myClass.getResource("/" + className.replace('.', '/') + ".class").getPath();
+ var classPath = myClass.getResource("/" + className.replace('.', '/') + ".class")
+ .getPath().replace('\\', '/'); // Normalize path separators
if (!myClassPathPattern.matcher(classPath).find()) {
- fail("Classpath for the " + className + " is expected to match " + myClassPathPattern + ", but was " + classPath);
+ fail(String.format("Classpath for %s is invalid.%nExpected pattern: %s%nActual path: %s%nExample valid path: %s",
+ className, myClassPathPattern, classPath,
+ "/plugin/build/libs/plugin-1.0.0.jar!"));
}
}
|
||||||||||||||||||||||||||||||||||
} |
Check warning
Code scanning / QDJVM
Unused declaration Warning test