Skip to content
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

Fix compatibility with Kotlin MPP plugin #23026

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions subprojects/architecture-test/build.gradle.kts
Expand Up @@ -17,6 +17,7 @@ dependencies {
testImplementation(project(":model-core"))
testImplementation(project(":file-temp"))
testImplementation(project(":core"))
testImplementation(project(":testing-base"))
testImplementation(libs.inject)

testImplementation(libs.archunitJunit5)
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.resources.TextResource;
import org.gradle.api.tasks.testing.TestFailure;
import org.gradle.internal.reflect.PropertyAccessorType;

import javax.inject.Inject;
Expand Down Expand Up @@ -77,6 +78,7 @@ public boolean test(JavaClass input) {
.and(not(declaredIn(Configuration.class)))
.and(not(declaredIn(FileCollection.class)))
.and(not(declaredIn(ConfigurableFileCollection.class)))
.and(not(declaredIn(TestFailure.class))) // extends Throwable which has setter
.and(are(declaredIn(class_with_any_mutable_property)))
.and(are(getters))
.and(not(annotatedWith(Inject.class)))
Expand Down
Expand Up @@ -27,20 +27,19 @@

public class DefaultTestFailure extends TestFailure {

private final Throwable rawFailure;
private final TestFailureDetails details;

private final List<TestFailure> causes;

public DefaultTestFailure(Throwable rawFailure, TestFailureDetails details, List<TestFailure> causes) {
this.rawFailure = rawFailure;
super(rawFailure);
this.details = details;
this.causes = causes;
}

@Override
public Throwable getRawFailure() {
return rawFailure;
return getCause();
}

@Override
Expand All @@ -64,15 +63,15 @@ public boolean equals(Object o) {

DefaultTestFailure that = (DefaultTestFailure) o;

if (rawFailure != null ? !rawFailure.equals(that.rawFailure) : that.rawFailure != null) {
if (getCause() != null ? !getCause().equals(that.getCause()) : that.getCause() != null) {
return false;
}
return details != null ? details.equals(that.details) : that.details == null;
}

@Override
public int hashCode() {
int result = rawFailure != null ? rawFailure.hashCode() : 0;
int result = getCause() != null ? getCause().hashCode() : 0;
result = 31 * result + (details != null ? details.hashCode() : 0);
return result;
}
Expand Down
Expand Up @@ -16,7 +16,6 @@

package org.gradle.api.internal.tasks.testing;

import org.gradle.api.tasks.testing.TestFailure;
import org.gradle.api.tasks.testing.TestOutputEvent;
import org.gradle.internal.scan.UsedByScanPlugin;

Expand Down Expand Up @@ -47,5 +46,5 @@ public interface TestResultProcessor {
* Notifies this processor that a failure has occurred in the given test.
*/
@UsedByScanPlugin("test-distribution")
void failure(Object testId, TestFailure result);
void failure(Object testId, Throwable result);
}
Expand Up @@ -20,7 +20,6 @@
import org.gradle.api.internal.tasks.testing.TestDescriptorInternal;
import org.gradle.api.internal.tasks.testing.TestResultProcessor;
import org.gradle.api.internal.tasks.testing.TestStartEvent;
import org.gradle.api.tasks.testing.TestFailure;
import org.gradle.api.tasks.testing.TestOutputEvent;

import java.util.Map;
Expand Down Expand Up @@ -89,7 +88,7 @@ public void output(Object testId, TestOutputEvent event) {
}

@Override
public void failure(Object testId, TestFailure result) {
public void failure(Object testId, Throwable result) {
processor.failure(testId, result);
}
}
Expand Up @@ -20,7 +20,6 @@
import org.gradle.api.internal.tasks.testing.TestDescriptorInternal;
import org.gradle.api.internal.tasks.testing.TestResultProcessor;
import org.gradle.api.internal.tasks.testing.TestStartEvent;
import org.gradle.api.tasks.testing.TestFailure;
import org.gradle.api.tasks.testing.TestOutputEvent;

public class AttachParentTestResultProcessor implements TestResultProcessor {
Expand All @@ -43,7 +42,7 @@ public void started(TestDescriptorInternal test, TestStartEvent event) {
}

@Override
public void failure(Object testId, TestFailure result) {
public void failure(Object testId, Throwable result) {
processor.failure(testId, result);
}

Expand Down
Expand Up @@ -98,14 +98,18 @@ public final void completed(Object testId, TestCompleteEvent event) {
}

@Override
public final void failure(Object testId, TestFailure testFailure) {
public final void failure(Object testId, Throwable testFailure) {
TestState testState = executing.get(testId);
if (testState == null) {
throw new IllegalArgumentException(String.format(
"Received a failure event for test with unknown id '%s'. Registered test ids: '%s'",
testId, executing.keySet()));
}
testState.failures.add(testFailure);
if (testFailure instanceof TestFailure) {
testState.failures.add((TestFailure) testFailure);
} else {
testState.failures.add(TestFailure.fromTestFrameworkFailure(testFailure));
}
}

@Override
Expand Down
Expand Up @@ -27,7 +27,16 @@
* @since 7.6
*/
@Incubating
public abstract class TestFailure {
public abstract class TestFailure extends Throwable {

/**
* Constructor storing the raw failure.
*
* @since 7.6.1
*/
protected TestFailure(Throwable rawFailure) {
super(rawFailure);
}

/**
* Returns the list of causes.
Expand Down
Expand Up @@ -95,7 +95,7 @@ public void output(Object testId, TestOutputEvent event) {
}

@Override
public void failure(Object testId, TestFailure result) {
public void failure(Object testId, Throwable result) {
resultProcessor.failure(testId, result);
}
}