Search in sources :

Example 1 with TaskFailureHandler

use of org.gradle.execution.TaskFailureHandler in project gradle by gradle.

the class DefaultTaskGraphExecuterTest method testStopsExecutionOnFailureWhenFailureHandlerIndicatesThatExecutionShouldStop.

@Test
public void testStopsExecutionOnFailureWhenFailureHandlerIndicatesThatExecutionShouldStop() {
    final TaskFailureHandler handler = context.mock(TaskFailureHandler.class);
    final RuntimeException failure = new RuntimeException();
    final RuntimeException wrappedFailure = new RuntimeException();
    final Task a = brokenTask("a", failure);
    final Task b = task("b");
    taskExecuter.useFailureHandler(handler);
    taskExecuter.addTasks(toList(a, b));
    context.checking(new Expectations() {

        {
            one(handler).onTaskFailure(a);
            will(throwException(wrappedFailure));
        }
    });
    try {
        taskExecuter.execute();
        fail();
    } catch (RuntimeException e) {
        assertThat(e, sameInstance(wrappedFailure));
    }
    assertThat(executedTasks, equalTo(toList(a)));
}
Also used : Expectations(org.jmock.Expectations) Task(org.gradle.api.Task) TaskFailureHandler(org.gradle.execution.TaskFailureHandler) Test(org.junit.Test)

Example 2 with TaskFailureHandler

use of org.gradle.execution.TaskFailureHandler in project gradle by gradle.

the class DefaultTaskGraphExecuterTest method willExecuteATaskWhoseDependenciesHaveBeenFilteredOnFailure.

@Test
public void willExecuteATaskWhoseDependenciesHaveBeenFilteredOnFailure() {
    final TaskFailureHandler handler = context.mock(TaskFailureHandler.class);
    final RuntimeException failure = new RuntimeException();
    final Task a = brokenTask("a", failure);
    final Task b = task("b");
    final Task c = task("c", b);
    taskExecuter.useFailureHandler(handler);
    taskExecuter.useFilter(new Spec<Task>() {

        public boolean isSatisfiedBy(Task element) {
            return element != b;
        }
    });
    taskExecuter.addTasks(toList(a, c));
    context.checking(new Expectations() {

        {
            ignoring(handler);
        }
    });
    try {
        taskExecuter.execute();
        fail();
    } catch (RuntimeException e) {
        assertThat(e, sameInstance(failure));
    }
    assertThat(executedTasks, equalTo(toList(a, c)));
}
Also used : Expectations(org.jmock.Expectations) Task(org.gradle.api.Task) TaskFailureHandler(org.gradle.execution.TaskFailureHandler) Test(org.junit.Test)

Aggregations

Task (org.gradle.api.Task)2 TaskFailureHandler (org.gradle.execution.TaskFailureHandler)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2