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

Prevent removal of ErrorSpecNode from execution hierarchy #1358

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public void prune() {
// without this empty override, the node is thrown away and the error is not reported
}

@Override
public void removeFromHierarchy() {
// prevent removal of this node
// As the ErrorSpecNode does not have children it would get removed when trying to select specific tests methods.
// For example, gradle will report that no test were found, and not report the actual error.
}

@Override
public SpockExecutionContext prepare(SpockExecutionContext context) throws Exception {
return ExceptionUtil.sneakyThrow(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ package org.spockframework.runtime
import spock.lang.Specification

import org.junit.platform.engine.*
import spock.lang.Subject

class ErrorSpecNodeSpec extends Specification {
TestDescriptor tdParent = Mock()

@Subject
def errorSpecNode = new ErrorSpecNode(
UniqueId.forEngine("test"),
null,
new SpecInfoBuilder(getClass()).build(),
null).tap {
parent = tdParent
}


def 'should not be pruned'() {
given:
TestDescriptor parent = Mock()
def testee = new ErrorSpecNode(
UniqueId.forEngine("test"),
null,
new SpecInfoBuilder(getClass()).build(),
null)
testee.setParent(parent)
when:
errorSpecNode.prune()

then:
0 * tdParent.removeChild(*_)
}

def 'should prevent removal of ErrorSpecNode'() {
when:
testee.prune()
errorSpecNode.removeFromHierarchy()

then:
0 * parent.removeChild(*_)
0 * tdParent.removeChild(*_)
}
}