Ejemplo n.º 1
0
  public PhpUnitResultWriter(
      File dir,
      PhpBuildInfo build_info,
      AHost host,
      ScenarioSetSetup scenario_set_setup,
      PhpUnitSourceTestPack test_pack)
      throws FileNotFoundException, IOException {
    this.build_info = build_info;
    this.host = host;
    this.scenario_set_setup = scenario_set_setup;
    this.test_pack_name_and_version = test_pack.getNameAndVersionString().intern();

    this.dir = dir;
    dir.mkdirs();

    all_csv_pw = new PrintWriter(new FileWriter(new File(dir, "ALL.csv")));
    started_pw = new PrintWriter(new FileWriter(new File(dir, "STARTED.txt")));

    output_by_name = new HashMap<String, String>(800);

    // include scenario-set in file name to make it easier to view a bunch of them in Notepad++ or
    // other MDIs
    File file =
        new File(
            dir
                + "/"
                + StringUtil.max(
                    "phpunit_"
                        + test_pack.getName()
                        + "_"
                        + scenario_set_setup.getNameWithVersionInfo(),
                    40)
                + ".xml");

    // XXX write host, scenario_set and build to file (do in #writeTally or #close)
    main_serial = new KXmlSerializer();
    extra_serial = new KXmlSerializer();

    main_serial.setOutput(out = new BufferedOutputStream(new FileOutputStream(file)), "utf-8");

    // setup serializer to indent XML (pretty print) so its easy for people to read
    main_serial.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    extra_serial.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

    status_list_map = new HashMap<EPhpUnitTestStatus, StatusListEntry>();
    for (EPhpUnitTestStatus status : EPhpUnitTestStatus.values()) {
      status_list_map.put(status, new StatusListEntry(status));
    }
  }
Ejemplo n.º 2
0
 private void writeTestSuiteStart(String test_suite_name)
     throws IllegalArgumentException, IllegalStateException, IOException {
   main_serial.startTag(null, "testsuite");
   if (StringUtil.isNotEmpty(test_suite_name))
     main_serial.attribute(null, "name", test_suite_name);
 }
Ejemplo n.º 3
0
  // @see PHPUnit/Util/Log/JUnit.php#startTestSuite
  public void writeResult(boolean store_output, PhpUnitTestResult result)
      throws IllegalArgumentException, IllegalStateException, IOException {
    if (closed)
      throw new IllegalStateException("can not write to closed PhpUnitResultWriter. it is closed.");

    if (result.ini != null && (this.ini == null || !this.ini.equals(result.ini)))
      this.ini = result.ini;
    test_count++;

    final String test_name = result.getName();
    status_list_map.get(result.status).write(test_name, result);

    if ((store_output
            || (result.status == EPhpUnitTestStatus.FAILURE
                || result.status == EPhpUnitTestStatus.ERROR
                || result.status == EPhpUnitTestStatus.CRASH))
        && StringUtil.isNotEmpty(result.output)) {
      // store crash output too: for exit code and status
      output_by_name.put(test_name, result.output);
    }

    // write file header
    String test_suite_name =
        result.test_case.getPhpUnitDist() != null
                && result.test_case.getPhpUnitDist().getPath() != null
            ? result.test_case.getPhpUnitDist().getPath().getPath()
            : null;
    if (is_first_result) {
      main_serial.startDocument("utf-8", null);
      main_serial.setPrefix("pftt", "pftt");
      main_serial.startTag(null, "testsuites");
      writeTestSuiteStart(test_suite_name);

      is_first_result = false;
    } else if (test_suite_name != null
        && last_test_suite_name != null
        && !test_suite_name.equals(last_test_suite_name)) {
      writeTestSuiteEnd();
      writeTestSuiteStart(test_suite_name);
    }
    last_test_suite_name = test_suite_name;
    //

    // write result itself
    result.serial(main_serial);

    //
    if ((result.code_coverage != null || result.extra != null)
        && PhpUnitTestResult.shouldStoreAllInfo(result.status)) {
      // store this data in a separate file
      File f =
          new File(
              dir,
              result
                      .getName()
                      .replace("::", "_")
                      .replace("(", "_")
                      .replace(")", "")
                      .replace(".php", "")
                  + ".xml");
      f.getParentFile().mkdirs(); // ensure directory exists
      FileWriter fw = new FileWriter(f);
      extra_serial.setOutput(fw);
      extra_serial.startDocument("utf-8", Boolean.TRUE);
      extra_serial.startTag("pftt", "phpUnitTestResult");
      if (result.extra != null) result.extra.serial(extra_serial);
      if (result.code_coverage != null) result.code_coverage.serial(extra_serial);
      extra_serial.endTag("pftt", "phpUnitTestResult");
      extra_serial.endDocument();
      extra_serial.flush();
      fw.close();
    }
    //

    // store name, status and run-time in CSV format
    all_csv_pw.print("'");
    all_csv_pw.print(test_name);
    all_csv_pw.print("','");
    all_csv_pw.print(result.status);
    all_csv_pw.print("',");
    all_csv_pw.print(result.run_time_micros);
    all_csv_pw.println();
  } // end public void writeResult