Example #1
0
  @Override
  protected void runChild(TestCase testCase, RunNotifier notifier) {
    notifier.fireTestStarted(testCase.name);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
      PolyglotEngine vm =
          PolyglotEngine.newBuilder()
              .setIn(
                  new ByteArrayInputStream(repeat(testCase.testInput, repeats).getBytes("UTF-8")))
              .setOut(out)
              .build();

      String script = readAllLines(testCase.path);

      PrintWriter printer = new PrintWriter(out);
      SLLanguage.run(vm, testCase.path, null, printer, repeats, builtins);
      printer.flush();

      String actualOutput = new String(out.toByteArray());
      Assert.assertEquals(script, repeat(testCase.expectedOutput, repeats), actualOutput);
    } catch (Throwable ex) {
      notifier.fireTestFailure(
          new Failure(
              testCase.name, new IllegalStateException("Cannot run " + testCase.sourceName, ex)));
    } finally {
      notifier.fireTestFinished(testCase.name);
    }
  }
 @Override
 public void testStarted(WikiTestPage test) {
   firstFailure = null;
   if (test.isTestPage()) {
     notifier.fireTestStarted(descriptionFor(test));
   }
 }
Example #3
0
  @Override
  protected void runChild(Interaction interaction, RunNotifier notifier) {
    final Description description = describeChild(interaction);
    notifier.fireTestStarted(description);

    if (interaction.providerState().isDefined()) {
      final Optional<FrameworkMethod> initializationMethod =
          findProvderStateInitializationMethod(interaction.providerState().get());
      if (initializationMethod.isPresent()) {
        try {
          invokeMethod(initializationMethod.get());
          testPact(interaction);
          notifier.fireTestFinished(description);
          return;
        } catch (Exception ex) {
          notifier.fireTestFailure(new Failure(description, ex));
          return;
        }
      } else {
        notifier.fireTestIgnored(description);
        return;
      }
    }
    notifier.fireTestIgnored(description);
  }
  void runTestMethod(Statement methodInvoker, RunNotifier notifier) {
    Description methodDescription = describeMethod();
    Description methodWithParams = findChildForParams(methodInvoker, methodDescription);

    notifier.fireTestStarted(methodWithParams);
    runMethodInvoker(notifier, methodDescription, methodInvoker, methodWithParams);
    notifier.fireTestFinished(methodWithParams);
  }
  /** {@inheritDoc} */
  private void notifyTestStarted(final Description junitDescription) {

    if (junitRunNotifier != null && junitDescription != null) {
      log.debug(junitDescription.getDisplayName() + " notifyTestStarted");

      junitRunNotifier.fireTestStarted(junitDescription);
    }
  }
 @Override
 public void fireTestStarted(Description description) throws StoppedByUserException {
   int progress = ++this.progress;
   if (progress > total) {
     total = progress;
   }
   console.indicateProgress(progress, total);
   super.fireTestStarted(description);
 }
  @Override
  public void fireTestStarted(Description description) throws StoppedByUserException {
    log.debug("Test started: " + description);
    if (!testStartAlreadyFired) {
      super.fireTestStarted(description);
    }

    testStartAlreadyFired = true;

    retryAwareRunNotifier.fireTestStarted(description);
  }
  @Override
  protected void runChild(FrameworkMethod method, RunNotifier notifier) {
    Description description = describeChild(method);
    if (method.getAnnotation(Ignore.class) != null) {
      notifier.fireTestIgnored(description);
      return;
    }

    String methodName = method.getName();
    String allowedMethodName = methodNames.get(description);
    if (methodName != null && !methodName.equals(allowedMethodName)) {
      //			notifier.fireTestIgnored(description);
      return;
    }

    try {
      notifier.fireTestStarted(description);
      HttpURLConnection connection = getUrl(methodName, "POST");
      handleError(connection);

      String enc = connection.getContentEncoding();
      if (enc == null) {
        enc = "ISO-8859-1";
      }
      InputStream is = connection.getInputStream();
      BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(enc)));
      String line = null;
      while ((line = reader.readLine()) != null) {
        if (line.startsWith("E")) {
          System.err.println(line.substring(1).trim());
        } else if (line.startsWith("O")) {
          System.out.println(line.substring(1).trim());
        } else if (line.startsWith("RSUCCESS")) {
          break;
        } else if (line.startsWith("RERROR")) {
          StringBuilder error = new StringBuilder(line.substring(6));
          while ((line = reader.readLine()) != null) {
            error.append(line).append("\n");
          }
          throw new AssertionFailedError(error.toString());
        } else {
          log.error("Protocol error in response: {}", line);
        }
      }
      is.close();
      connection.disconnect();
    } catch (Throwable e) {
      e.printStackTrace();
      notifier.fireTestFailure(new Failure(description, e));
    } finally {
      notifier.fireTestFinished(description);
    }
  }
  @Override
  public void run(RunNotifier notifier) {
    filteredTests.foreachDoEffect(
        p -> {
          Description desc = p._3();
          notifier.fireTestStarted(desc);
          CheckResult result = checkProperty(p._1(), p._2());

          try {
            CheckResult.summaryEx.showS(result);
          } catch (Throwable t) {
            notifier.fireTestFailure(new Failure(desc, t));
          }

          notifier.fireTestFinished(desc);
        });
  }
  /**
   * Executes the passed in test case. Instrumentation is added according to the name of the file as
   * explained in {@link #createTests(Class)}. Note that this code is not generalizable.
   */
  @Override
  protected void runChild(InstrumentTestCase testCase, RunNotifier notifier) {
    // TODO Current tests are hard-coded, automate this eventually
    notifier.fireTestStarted(testCase.name);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(out);

    PolyglotEngine vm = null;
    try {
      // We use the name of the file to determine what visitor to attach to it.
      if (testCase.baseName.endsWith(ASSIGNMENT_VALUE_SUFFIX)) {
        // Set up the execution context for Simple and register our two listeners
        vm =
            PolyglotEngine.newBuilder()
                .setIn(new ByteArrayInputStream(testCase.testInput.getBytes("UTF-8")))
                .setOut(out)
                .build();

        final String src = readAllLines(testCase.path);
        vm.eval(Source.fromText(src, testCase.path.toString()).withMimeType("application/x-sl"));

        PolyglotEngine.Value main = vm.findGlobalSymbol("main");
        main.execute();
      } else {
        notifier.fireTestFailure(
            new Failure(
                testCase.name, new UnsupportedOperationException("No instrumentation found.")));
      }
      ps.flush();
      String actualOutput = new String(out.toByteArray());
      Assert.assertEquals(testCase.expectedOutput, actualOutput);
    } catch (Throwable ex) {
      notifier.fireTestFailure(new Failure(testCase.name, ex));
    } finally {
      if (vm != null) {
        vm.dispose();
      }
      notifier.fireTestFinished(testCase.name);
    }
  }
 public void beforeStory(StoryDefinition story, boolean embeddedStory) {
   notifier.fireTestStarted(storyDescription);
 }
 public void beforeScenario(String title) {
   notifier.fireTestStarted(currentScenario);
 }
 @Override
 public void run(RunNotifier notifier) {
   notifier.fireTestStarted(createTestDescription(testClass, "doesNotExist"));
 }
Example #14
0
 @Override
 public void run(RunNotifier notifier) {
   notifier.fireTestStarted(getDescription());
   notifier.fireTestFinished(getDescription());
 }
  @Override
  public void evaluate() throws Throwable {
    ProcessBuilder builder = new ProcessBuilder();

    builder.command(buildCommand());
    builder.redirectErrorStream(true);
    builder.directory(testCase.getWorkingDirectory());

    System.out.println("Working directory: " + SystemProperty.INSTANCE.getProperty("user.dir"));
    System.out.println("Command: " + builder.command());

    Description parentDescription = runner.getDescription();

    final Process process = builder.start();

    try {
      Scanner scanner = testCase.startTest(process);

      while (scanner.hasNextLine()) {
        String line = scanner.nextLine();

        if (line.startsWith(JUNIT_OUTPUT_DELIMITER)) {
          System.out.println(line);
          String[] tokens = line.split(JUNIT_OUTPUT_DELIMITER_REGEXP);
          String event = tokens[1];

          if ("testRunStarted".equals(event)) {
            notifier.fireTestRunStarted(parentDescription);
          } else if ("testRunFinished".equals(event)) {
            notifier.fireTestRunFinished(result);
          } else if ("testStarted".equals(event)) {
            Description ofTest = findDescription(parentDescription, tokens[2]);
            notifier.fireTestStarted(ofTest);
          } else if ("testFinished".equals(event)) {
            Description ofTest = findDescription(parentDescription, tokens[2]);
            notifier.fireTestFinished(ofTest);
          } else if ("testFailure".equals(event)) {
            List<String> stackTrace =
                tokens.length > 5
                    ? Arrays.asList(tokens).subList(5, tokens.length - 1)
                    : Collections.<String>emptyList();
            Failure failure =
                toFailure(parentDescription, tokens[2], tokens[3], tokens[4], stackTrace);
            notifier.fireTestFailure(failure);
          } else if ("testAssumptionFailure".equals(event)) {
            List<String> stackTrace =
                tokens.length > 5
                    ? Arrays.asList(tokens).subList(5, tokens.length - 1)
                    : Collections.<String>emptyList();
            Failure failure =
                toFailure(parentDescription, tokens[2], tokens[3], tokens[4], stackTrace);
            notifier.fireTestAssumptionFailed(failure);
          } else if ("testIgnored".equals(event)) {
            Description ofTest = findDescription(parentDescription, tokens[2]);
            notifier.fireTestIgnored(ofTest);
          }
        } else {
          System.out.println(line);
        }
      }
    } catch (Throwable t) {
      System.err.println("Failed to execute test");
      t.printStackTrace();

      throw t;
    } finally {
      try {
        testCase.endTest(process);
      } finally {

        Timer timer = new Timer();
        timer.schedule(
            new TimerTask() {

              @Override
              public void run() {
                process.destroy();
              }
            },
            10 * 1000);

        try {
          process.waitFor();
        } catch (InterruptedException e) {
          // ignore
        }

        timer.cancel();
      }
    }
  }
Example #16
0
 public void startTest(Test test) {
   fNotifier.fireTestStarted(asDescription(test));
 }
 public void failed(String step, Throwable e) {
   currentStep = getStepDescription(step);
   notifier.fireTestStarted(currentStep);
   notifier.fireTestFailure(new Failure(currentStep, e));
   finishedDescriptions.add(currentStep);
 }
 public void successful(String step) {
   currentStep = getStepDescription(step);
   notifier.fireTestStarted(currentStep);
   notifier.fireTestFinished(currentStep);
   finishedDescriptions.add(currentStep);
 }
Example #19
0
 private void ignoreRequest(RunNotifier notifier, Exception e) {
   notifier.fireTestStarted(getDescription());
   notifier.fireTestAssumptionFailed(new Failure(getDescription(), e));
   notifier.fireTestFinished(getDescription());
 }
 private void runCause(Throwable child, RunNotifier notifier) {
   Description description = describeCause(child);
   notifier.fireTestStarted(description);
   notifier.fireTestFailure(new Failure(description, child));
   notifier.fireTestFinished(description);
 }
Example #21
0
 private void runFailure(Description failDesc, Throwable cause, RunNotifier notifier) {
   notifier.fireTestStarted(failDesc);
   notifier.fireTestFailure(new Failure(failDesc, cause));
   notifier.fireTestFinished(failDesc);
 }