Beispiel #1
0
 @org.junit.Test
 public void testExecuteWithTestFailuresAndStopAtFailures() {
   configureTask();
   expectTestsFail();
   try {
     test.executeTests();
     fail();
   } catch (GradleException e) {
     assertThat(e.getMessage(), startsWith("There were failing tests. See the report at"));
   }
 }
 public ExecutionFailure assertThatCause(final Matcher<String> matcher) {
   if (failure instanceof LocationAwareException) {
     LocationAwareException exception = (LocationAwareException) failure;
     assertThat(exception.getReportableCauses(), hasItem(hasMessage(matcher)));
   } else {
     assertThat(failure.getCause(), notNullValue());
     assertThat(failure.getCause().getMessage(), matcher);
   }
   return this;
 }
 public ExecutionFailure assertHasNoCause() {
   if (failure instanceof LocationAwareException) {
     LocationAwareException exception = (LocationAwareException) failure;
     assertThat(exception.getReportableCauses(), isEmpty());
   } else {
     assertThat(failure.getCause(), nullValue());
   }
   outputFailure.assertHasNoCause();
   return this;
 }
    public InProcessExecutionFailure(
        List<String> tasks,
        Set<String> skippedTasks,
        OutputScrapingExecutionFailure outputFailure,
        GradleException failure) {
      super(tasks, skippedTasks, outputFailure);
      this.outputFailure = outputFailure;
      this.failure = failure;

      // Chop up the exception message into its expected parts
      java.util.regex.Matcher matcher = LOCATION_PATTERN.matcher(failure.getMessage());
      if (matcher.find()) {
        fileName = matcher.group(1);
        lineNumber = matcher.group(3);
        description = failure.getMessage().substring(matcher.end()).trim();
      } else {
        fileName = "";
        lineNumber = "";
        description = failure.getMessage().trim();
      }
    }
  @Test
  public void wrapsOnlyIfPredicateFailure() {
    final Throwable failure = new RuntimeException();
    final Collector<Throwable> wrappedFailure = collector();
    context.checking(
        new Expectations() {
          {
            allowing(task).getEnabled();
            will(returnValue(true));
            one(spec).isSatisfiedBy(task);
            will(throwException(failure));
            one(state).executed(with(notNullValue(GradleException.class)));
            will(collectTo(wrappedFailure));
          }
        });

    executer.execute(task, state, executionContext);

    GradleException exception = (GradleException) wrappedFailure.get();
    assertThat(exception.getMessage(), equalTo("Could not evaluate onlyIf predicate for <task>."));
    assertThat(exception.getCause(), sameInstance(failure));
  }
 public ExecutionFailure assertThatDescription(Matcher<String> matcher) {
   assertThat(failure.getMessage(), containsLine(matcher));
   return this;
 }
 public ExecutionFailure assertHasFileName(String filename) {
   assertThat(failure.getMessage(), startsWith(String.format("%s", filename)));
   return this;
 }
 public ExecutionFailure assertHasLineNumber(int lineNumber) {
   assertThat(failure.getMessage(), containsString(String.format(" line: %d", lineNumber)));
   return this;
 }