예제 #1
0
 static {
   if (Util.checkForWindows()) {
     TMPFILE_NAME = System.getProperty("java.io.tmpdir") + "\\" + "tmp.txt";
   } else {
     TMPFILE_NAME = System.getProperty("java.io.tmpdir") + "/" + "tmp.txt";
   }
 }
예제 #2
0
  protected void setupStreams(ITestResult result, boolean printMethodName) {
    String test_name = result.getTestClass().getName();
    File dir = new File(output_dir + File.separator + test_name);
    if (!dir.exists()) dir.mkdirs();
    File _tests = new File(dir, TESTS),
        _stdout = new File(dir, STDOUT),
        _stderr = new File(dir, STDERR);
    try {
      Class<?> clazz = result.getTestClass().getRealClass();
      if (!tests.containsKey(clazz)) {
        DataOutputStream output = new DataOutputStream(new FileOutputStream(_tests, true));
        DataOutputStream tmp = tests.putIfAbsent(clazz, output);
        if (tmp != null) {
          Util.close(output);
          output = tmp;
        }
      }

      if (stdout.get() == null) stdout.set(new PrintStream(new FileOutputStream(_stdout, true)));
      if (stderr.get() == null) stderr.set(new PrintStream(new FileOutputStream(_stderr, true)));
      if (printMethodName)
        stdout.get().println("\n\n------------- " + getMethodName(result) + " -----------");
    } catch (IOException e) {
      error(e.toString());
    }
  }
예제 #3
0
 /** Invoked after all test classes in this test have been run */
 public void onFinish(ITestContext context) {
   try {
     for (DataOutputStream out : tests.values()) Util.close(out);
     tests.clear();
     generateReports();
   } catch (IOException e) {
     error(e.toString());
   } finally {
     System.setOut(old_stdout);
     System.setErr(old_stderr);
   }
 }
예제 #4
0
  protected static void process(File dir) throws IOException {
    File file = new File(dir, TESTS);
    if (!file.exists()) throw new IOException(file + " not found");
    List<TestCase> test_cases = new ArrayList<>();
    DataInputStream input = new DataInputStream(new FileInputStream(file));
    try {
      for (; ; ) {
        TestCase test_case = new TestCase();
        try {
          test_case.readFrom(input);
          test_cases.add(test_case);
        } catch (Exception e) {
          break;
        }
      }
    } finally {
      Util.close(input);
    }

    if (test_cases.isEmpty()) return;

    Reader stdout_reader = null, stderr_reader = null;
    File tmp = new File(dir, STDOUT);
    if (tmp.exists() && tmp.length() > 0) stdout_reader = new FileReader(tmp);

    tmp = new File(dir, STDERR);
    if (tmp.exists() && tmp.length() > 0) stderr_reader = new FileReader(tmp);
    File parent = dir.getParentFile();
    File xml_file = new File(parent, "TESTS-" + dir.getName() + "-" + parent.getName() + ".xml");
    Writer out = new FileWriter(xml_file);
    String classname = dir.getName();
    String suffix = parent.getName();
    if (suffix != null && !suffix.isEmpty()) classname = classname + "-" + suffix;
    try {
      generateReport(out, classname, test_cases, stdout_reader, stderr_reader);
    } finally {
      out.close();
      if (stdout_reader != null) stdout_reader.close();
      if (stderr_reader != null) stderr_reader.close();
    }
  }
예제 #5
0
 protected static void closeStreams() {
   Util.close(stdout.get());
   stdout.set(null);
   Util.close(stderr.get());
   stderr.set(null);
 }