Skip to content

Commit

Permalink
Fix tests after rebasing to latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
donat committed May 9, 2024
1 parent 8b171a6 commit de41444
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ package org.gradle.internal.deprecation
import org.gradle.api.internal.DocumentationRegistry
import org.gradle.api.logging.configuration.WarningMode
import org.gradle.api.problems.Severity
import org.gradle.api.problems.internal.DefaultDeprecationData
import org.gradle.api.problems.internal.DefaultProblem
import org.gradle.api.problems.internal.DefaultProblemDefinition
import org.gradle.api.problems.internal.DefaultProblemId
import org.gradle.api.problems.internal.DefaultProblems
import org.gradle.api.problems.internal.DeprecationData
import org.gradle.api.problems.internal.GradleCoreProblemGroup
import org.gradle.api.problems.internal.Problem
import org.gradle.api.problems.internal.ProblemEmitter
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.internal.logging.CollectingTestOutputEventListener
Expand Down Expand Up @@ -83,7 +86,7 @@ class DeprecationMessagesTest extends Specification {
then:
expectMessage "$summary This is scheduled to be removed in Gradle ${NEXT_GRADLE_VERSION}."

1 * problemEmitter.emit(createProblem(summary), identifier)
1 * problemEmitter.emit({ it.definition.id.displayName == 'Summary is deprecated.' }, identifier)
}

def "logs deprecation message with custom problem id"() {
Expand All @@ -99,14 +102,14 @@ class DeprecationMessagesTest extends Specification {
then:
expectMessage "$summary This is scheduled to be removed in Gradle ${NEXT_GRADLE_VERSION}."

1 * problemEmitter.emit(createProblem(deprecationDisplayName), identifier)
1 * problemEmitter.emit({ it.definition.id.displayName == 'summary deprecation' }, identifier)
}

def createProblem(deprecationDisplayName) {
def id = new DefaultProblemId(createDefaultDeprecationId(deprecationDisplayName), deprecationDisplayName, GradleCoreProblemGroup.deprecation())
def definition = new DefaultProblemDefinition(id, Severity.WARNING, null)

return new DefaultProblem(definition, "Summary is deprecated.", [], [], "This is scheduled to be removed in Gradle 9.0.", null, ["type": "USER_CODE_DIRECT"])
return new DefaultProblem(definition, "Summary is deprecated.", [], [], "This is scheduled to be removed in Gradle 9.0.", null, new DefaultDeprecationData(DeprecationData.Type.USER_CODE_DIRECT))
}

def "logs deprecation message with advice"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class JavaCompileProblemsIntegrationTest extends AbstractIntegrationSpec {
fqid == 'compilation:java:java-compilation-error'
details == 'warnings found and -Werror specified'
solutions.empty
additionalData.asMap == ["formatted" : "error: warnings found and -Werror specified"]
additionalData.asMap == ['asMap' : ["formatted" : "error: warnings found and -Werror specified"]] // TODO (donat) this seems suspicious
}

// Based on the Java version, the types in the lint message will differ...
Expand All @@ -280,19 +280,18 @@ class JavaCompileProblemsIntegrationTest extends AbstractIntegrationSpec {
it.line == 5
it.length == 21
}
additionalData.asMap == ["formatted" :
additionalData == """$fooFileLocation:5: warning: [cast] redundant cast to $expectedType
additionalData.asMap == ['asMap' : ["formatted" : """$fooFileLocation:5: warning: [cast] redundant cast to $expectedType
String s = (String)"Hello World";
^"""]
^"""]]
}
verifyAll(receivedProblem(2)) {
assertProblem(it, "WARNING", true)
fqid == 'compilation:java:java-compilation-warning'
details == 'redundant cast to java.lang.String'
solutions.empty
additionalData.asMap == ["formatted" : """${fooFileLocation}:10: warning: [cast] redundant cast to $expectedType
additionalData.asMap == ['asMap' : ["formatted" : """${fooFileLocation}:10: warning: [cast] redundant cast to $expectedType
String s = (String)"Hello World";
^"""]
^"""]]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.gradle.api.logging.Logging;
import org.gradle.api.problems.ProblemSpec;
import org.gradle.api.problems.Severity;
import org.gradle.api.problems.internal.GenericData;
import org.gradle.api.problems.internal.InternalProblemSpec;
import org.gradle.api.problems.internal.InternalProblems;
import org.gradle.api.specs.Spec;
Expand Down Expand Up @@ -113,7 +114,7 @@ private RuntimeException throwTaskSelectionException(SelectionContext context, P

private static ProblemSpec configureProblem(ProblemSpec spec, NameMatcher matcher, SelectionContext context) {
matcher.configureProblemId(spec);
((InternalProblemSpec) spec).additionalData("requestedPath", Objects.requireNonNull(context.getOriginalPath().getPath()));
((InternalProblemSpec) spec).additionalData(GenericData.class, data -> data.put("requestedPath", Objects.requireNonNull(context.getOriginalPath().getPath())));
spec.severity(Severity.ERROR);
return spec;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.gradle.api.internal.project.ProjectState;
import org.gradle.api.problems.ProblemSpec;
import org.gradle.api.problems.Severity;
import org.gradle.api.problems.internal.GenericData;
import org.gradle.api.problems.internal.GradleCoreProblemGroup;
import org.gradle.api.problems.internal.InternalProblemSpec;
import org.gradle.api.problems.internal.InternalProblems;
Expand Down Expand Up @@ -183,7 +184,7 @@ private ProjectState selectProject(TaskSelector.SelectionContext context, Projec
private static void configureProblem(ProblemSpec spec, String message, String requestedPath, RuntimeException e) {
spec.contextualLabel(message);
spec.severity(Severity.ERROR);
((InternalProblemSpec) spec).additionalData("requestedPath", Objects.requireNonNull(requestedPath));
((InternalProblemSpec) spec).additionalData(GenericData.class, data -> data.put("requestedPath", Objects.requireNonNull(requestedPath)));
spec.withException(e);
}

Expand Down

0 comments on commit de41444

Please sign in to comment.