From 4c65926ae3634ac3d33a7a9a54c1ec8dd2a51e8b Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 12 Aug 2022 08:35:56 +0200 Subject: [PATCH] Keep test folders of failed build tools integration tests --- .../fixtures/AbstractGradleFuncTest.groovy | 12 +++++- .../internal/test/TestResultExtension.java | 37 +++++++++++++++++++ ...amework.runtime.extension.IGlobalExtension | 9 +++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 build-tools/src/testFixtures/java/org/elasticsearch/gradle/internal/test/TestResultExtension.java create mode 100644 build-tools/src/testFixtures/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension diff --git a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy index 7719c63f37710..87bff62d0184e 100644 --- a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy +++ b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy @@ -12,6 +12,7 @@ import org.apache.commons.io.FileUtils import org.elasticsearch.gradle.internal.test.ConfigurationCacheCompatibleAwareGradleRunner import org.elasticsearch.gradle.internal.test.InternalAwareGradleRunner import org.elasticsearch.gradle.internal.test.NormalizeOutputGradleRunner +import org.elasticsearch.gradle.internal.test.TestResultExtension import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner import org.junit.Rule @@ -47,9 +48,9 @@ abstract class AbstractGradleFuncTest extends Specification { } def cleanup() { -// if (Boolean.getBoolean('test.keep.samplebuild')) { + if (featureFailed()) { FileUtils.copyDirectory(testProjectDir.root, new File("build/test-debug/" + testProjectDir.root.name)) -// } + } } File subProject(String subProjectPath) { @@ -205,6 +206,13 @@ checkstyle = "com.puppycrawl.tools:checkstyle:10.3" } + boolean featureFailed() { + specificationContext.currentSpec.listeners + .findAll { it instanceof TestResultExtension.ErrorListener } + .any { + (it as TestResultExtension.ErrorListener).errorInfo != null } + } + static class ProjectConfigurer { private File projectDir diff --git a/build-tools/src/testFixtures/java/org/elasticsearch/gradle/internal/test/TestResultExtension.java b/build-tools/src/testFixtures/java/org/elasticsearch/gradle/internal/test/TestResultExtension.java new file mode 100644 index 0000000000000..c08f25843c721 --- /dev/null +++ b/build-tools/src/testFixtures/java/org/elasticsearch/gradle/internal/test/TestResultExtension.java @@ -0,0 +1,37 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.gradle.internal.test; + +import org.spockframework.runtime.AbstractRunListener; +import org.spockframework.runtime.extension.IGlobalExtension; +import org.spockframework.runtime.model.ErrorInfo; +import org.spockframework.runtime.model.IterationInfo; +import org.spockframework.runtime.model.SpecInfo; + +public class TestResultExtension implements IGlobalExtension { + + @Override + public void visitSpec(SpecInfo spec) { + spec.addListener(new ErrorListener()); + } + + public static class ErrorListener extends AbstractRunListener { + ErrorInfo errorInfo; + + @Override + public void beforeIteration(IterationInfo iteration) { + errorInfo = null; + } + + @Override + public void error(ErrorInfo error) { + errorInfo = error; + } + } +} diff --git a/build-tools/src/testFixtures/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension b/build-tools/src/testFixtures/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension new file mode 100644 index 0000000000000..7d1e63d129ca1 --- /dev/null +++ b/build-tools/src/testFixtures/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension @@ -0,0 +1,9 @@ +# +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. Licensed under the Elastic License +# 2.0 and the Server Side Public License, v 1; you may not use this file except +# in compliance with, at your election, the Elastic License 2.0 or the Server +# Side Public License, v 1. +# + +org.elasticsearch.gradle.internal.test.TestResultExtension \ No newline at end of file