Skip to content

Commit

Permalink
Merge branch 'groovy-1.7' into groovy-1.8
Browse files Browse the repository at this point in the history
Conflicts:
	settings.gradle
	spock-specs/src/test/groovy/org/spockframework/smoke/extension/IgnoreIfSpec.groovy
  • Loading branch information
pniederw committed Feb 24, 2012
2 parents 5a7fcb6 + 53375d8 commit 9d7f527
Show file tree
Hide file tree
Showing 18 changed files with 487 additions and 217 deletions.
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include 'spock-core'
include 'spock-guice'
include "spock-core"
include "spock-guice"
include "spock-maven"
include 'spock-specs'
include 'spock-spring'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,28 @@ class EmbeddedSpecCompiler {

String imports = ""

void addImport(String pkg) {
imports += "import $pkg.*;"
}

void addImport(Package pkg) {
imports += "import ${pkg.name}.*;"
addImport(pkg.name)
}

void addClassImport(String className) {
imports += "import $className"
}

void addClassImport(Class<?> clazz) {
addClassImport(clazz.name)
}

void addClassMemberImport(String className) {
imports += "import static $className.*;"
}

void addClassMemberImport(Class<?> clazz) {
addClassMemberImport(clazz.name)
}

/**
Expand Down
20 changes: 20 additions & 0 deletions spock-core/src/main/groovy/spock/util/EmbeddedSpecRunner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,30 @@ class EmbeddedSpecRunner {
List<Class> extensionClasses = []
boolean inheritParentExtensions = true

void addImport(String pkg) {
compiler.addImport(pkg)
}

void addImport(Package pkg) {
compiler.addImport(pkg)
}

void addClassImport(String className) {
compiler.addClassImport(className)
}

void addClassImport(Class<?> clazz) {
compiler.addClassImport(clazz)
}

void addClassMemberImport(String className) {
compiler.addClassMemberImport(className)
}

void addClassMemberImport(Class<?> clazz) {
compiler.addClassMemberImport(clazz)
}

Result runRequest(Request request) {
withNewContext {
doRunRequest(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.spockframework.runtime;

import org.junit.ComparisonFailure;
import org.junit.internal.AssumptionViolatedException;
import org.junit.internal.runners.model.MultipleFailureException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
Expand Down Expand Up @@ -81,13 +82,23 @@ public int error(ErrorInfo error) {
if (exception instanceof MultipleFailureException)
return handleMultipleFailures(error);

if (isCausedByFailedEqualityComparison(exception))
if (isFailedEqualityComparison(exception))
exception = convertToComparisonFailure(exception);

filter.filter(exception);

masterListener.error(error);
notifier.fireTestFailure(new Failure(getCurrentDescription(), exception));
Failure failure = new Failure(getCurrentDescription(), exception);

if (exception instanceof AssumptionViolatedException) {
// Spock has no concept of "violated assumption", so we don't notify Spock listeners
// do notify JUnit listeners unless it's a data-driven iteration that's reported as one feature
if (currentIteration == null || !currentFeature.isParameterized() || currentFeature.isReportIterations()) {
notifier.fireTestAssumptionFailed(failure);
}
} else {
masterListener.error(error);
notifier.fireTestFailure(failure);
}

errorSinceLastReset = true;
return statusFor(error);
Expand All @@ -102,7 +113,7 @@ private int handleMultipleFailures(ErrorInfo error) {
return runStatus;
}

private boolean isCausedByFailedEqualityComparison(Throwable exception) {
private boolean isFailedEqualityComparison(Throwable exception) {
if (!(exception instanceof ConditionNotSatisfiedError)) return false;

Condition condition = ((ConditionNotSatisfiedError) exception).getCondition();
Expand All @@ -112,7 +123,7 @@ private boolean isCausedByFailedEqualityComparison(Throwable exception) {

// enables IDE support (diff dialog)
private Throwable convertToComparisonFailure(Throwable exception) {
assert isCausedByFailedEqualityComparison(exception);
assert isFailedEqualityComparison(exception);

Condition condition = ((ConditionNotSatisfiedError) exception).getCondition();
ExpressionInfo expr = condition.getExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.spockframework.runtime.extension.*;
import org.spockframework.runtime.model.*;
import org.spockframework.util.ReflectionUtil;
import org.spockframework.util.UnreachableCodeError;

/**
Expand Down Expand Up @@ -139,9 +140,8 @@ public FixtureMethodInterceptor(Collection<Method> methods) {
public void intercept(IMethodInvocation invocation) throws Throwable {
if (!executeBeforeSpecMethod) invocation.proceed();

// TODO - handle invocation errors in a more user friendly way?
for (Method method : methods) {
method.invoke(invocation.getTarget());
ReflectionUtil.invokeMethod(invocation.getTarget(), method);
}

if (executeBeforeSpecMethod) invocation.proceed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,43 @@ public void remove() {
public static <T> Set<T> asSet(T[] values) {
return new HashSet<T>(Arrays.asList(values));
}

public static <T> Iterable<T> concat(Iterable<? extends T>... iterables) {
return concat(Arrays.asList(iterables));
}

public static <T> Iterable<T> concat(final List<Iterable<? extends T>> iterables) {
return new Iterable<T>() {
public Iterator<T> iterator() {
return new Iterator<T>() {
Iterator<? extends T> iter;
int pos = 0;

public boolean hasNext() {
while (pos < iterables.size()) {
if (iter == null) iter = iterables.get(pos).iterator();
if (iter.hasNext()) return true;
iter = null;
pos++;
}
return false;
}

public T next() {
while (pos < iterables.size()) {
if (iter == null) iter = iterables.get(pos).iterator();
if (iter.hasNext()) return iter.next();
iter = null;
pos++;
}
throw new NoSuchElementException();
}

public void remove() {
throw new UnsupportedOperationException("remove");
}
};
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.spockframework.smoke.extension
import spock.lang.*

@IgnoreIf({ 1 < 2 })
class ConditionallyIgnoreSpec extends Specification {
class IgnoreIfExtension extends Specification {
def "should be ignored"() {
expect: false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.spockframework.smoke.junit

import org.spockframework.EmbeddedSpecification
import org.junit.runner.notification.RunListener
import org.junit.Assume

class HandlingOfAssumptionViolatedException extends EmbeddedSpecification {
RunListener listener = Mock()

def setup() {
runner.listeners << listener
runner.addClassMemberImport(Assume)
}

def "reported in regular feature method"() {
when:
runner.runSpecBody """
def foo() {
setup:
assumeTrue(false)
}
"""

then:
1 * listener.testStarted(_)

then:
1 * listener.testAssumptionFailure(_)

then:
1 * listener.testFinished(_)

0 * listener.testFailure(_)
}

def "reported in data-driven unrolled feature method"() {
when:
runner.runSpecBody """
@Unroll
def foo() {
setup:
assumeTrue(false)
where:
i << (1..2)
}
"""

then:
2 * listener.testStarted(_)
2 * listener.testAssumptionFailure(_)
2 * listener.testFinished(_)
0 * listener.testFailure(_)
}

def "ignored in data-driven feature method that isn't unrolled"() {
when:
runner.runSpecBody """
def foo() {
setup:
assumeTrue(false)
where:
i << (1..2)
}
"""

then:
1 * listener.testStarted(_)
0 * listener.testAssumptionFailure(_)
1 * listener.testFinished(_)
0 * listener.testFailure(_)
}

def "reported in setup"() {
when:
runner.runSpecBody """
def setup() {
assumeTrue(false)
}
def foo() {
expect: true
}
def bar() {
expect: false
}
"""

then:
2 * listener.testStarted(_)
2 * listener.testAssumptionFailure(_)
2 * listener.testFinished(_)
0 * listener.testFailure(_)
}

def "reported in @Before"() {
when:
runner.runSpecBody """
@org.junit.Before
void before() {
assumeTrue(false)
}
def foo() {
expect: true
}
def bar() {
expect: true
}
"""

then:
2 * listener.testStarted(_)
2 * listener.testAssumptionFailure(_)
2 * listener.testFinished(_)
0 * listener.testFailure(_)
}
}
Loading

0 comments on commit 9d7f527

Please sign in to comment.