test/com/sun/javadoc/lib/JavadocTester.java

changeset 2036
8df12c315ea3
parent 1052
409b104f8b86
child 2525
2eb010b6cb22
     1.1 --- a/test/com/sun/javadoc/lib/JavadocTester.java	Wed Sep 18 17:13:26 2013 -0700
     1.2 +++ b/test/com/sun/javadoc/lib/JavadocTester.java	Wed Sep 18 22:47:06 2013 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -57,6 +57,7 @@
    1.11      protected static final String SRC_DIR = System.getProperty("test.src", ".");
    1.12      protected static final String JAVA_VERSION = System.getProperty("java.version");
    1.13      protected static final String[][] NO_TEST = new String[][] {};
    1.14 +    protected static final String[] NO_FILE_TEST = new String[] {};
    1.15  
    1.16      /**
    1.17       * Use this as the file name in the test array when you want to search
    1.18 @@ -166,6 +167,26 @@
    1.19      }
    1.20  
    1.21      /**
    1.22 +     * Execute the tests.
    1.23 +     *
    1.24 +     * @param tester               the tester to execute
    1.25 +     * @param args                 the arguments to pass to Javadoc
    1.26 +     * @param testArray            the array of tests
    1.27 +     * @param negatedTestArray     the array of negated tests
    1.28 +     * @param fileTestArray        the array of file tests
    1.29 +     * @param negatedFileTestArray the array of negated file tests
    1.30 +     * @return                     the return code for the execution of Javadoc
    1.31 +     */
    1.32 +    public static int run(JavadocTester tester, String[] args,
    1.33 +            String[][] testArray, String[][] negatedTestArray, String[] fileTestArray,
    1.34 +            String[] negatedFileTestArray) {
    1.35 +        int returnCode = tester.runJavadoc(args);
    1.36 +        tester.runTestsOnHTML(testArray, negatedTestArray);
    1.37 +        tester.runTestsOnFile(fileTestArray, negatedFileTestArray);
    1.38 +        return returnCode;
    1.39 +    }
    1.40 +
    1.41 +    /**
    1.42       * Execute Javadoc using the default doclet.
    1.43       *
    1.44       * @param args  the arguments to pass to Javadoc
    1.45 @@ -244,6 +265,19 @@
    1.46      }
    1.47  
    1.48      /**
    1.49 +     * Run array of tests on the generated files.
    1.50 +     * This method accepts a fileTestArray for testing if a file is generated
    1.51 +     * and a negatedFileTestArray for testing if a file is not found.
    1.52 +     *
    1.53 +     * @param testArray         the array of file tests
    1.54 +     * @param negatedTestArray  the array of negated file tests
    1.55 +     */
    1.56 +    public void runTestsOnFile(String[] fileTestArray, String[] negatedFileTestArray) {
    1.57 +        runTestsOnFile(fileTestArray, false);
    1.58 +        runTestsOnFile(negatedFileTestArray, true);
    1.59 +    }
    1.60 +
    1.61 +    /**
    1.62       * Run the array of tests on the resulting HTML.
    1.63       *
    1.64       * @param testArray the array of tests
    1.65 @@ -265,9 +299,11 @@
    1.66                  fileString = readFileToString(testArray[i][0]);
    1.67              } catch (Error e) {
    1.68                  if (isNegated) {
    1.69 -                  numTestsPassed += 1;
    1.70 -                  System.out.println("Passed\n not found:\n"
    1.71 -                    + stringToFind + " in non-existent " + testArray[i][0] + "\n");
    1.72 +                  System.out.println( "FAILED" + "\n"
    1.73 +                                    + "for bug " + getBugId()
    1.74 +                                    + " (" + getBugName() + ") "
    1.75 +                                    + "due to "
    1.76 +                                    + e + "\n");
    1.77                    continue;
    1.78                  }
    1.79                  throw e;
    1.80 @@ -291,6 +327,39 @@
    1.81      }
    1.82  
    1.83      /**
    1.84 +     * Run the array of file tests on the generated files.
    1.85 +     *
    1.86 +     * @param testArray the array of file tests
    1.87 +     * @param isNegated true if test is negated; false otherwise
    1.88 +     */
    1.89 +    private void runTestsOnFile(String[] testArray, boolean isNegated) {
    1.90 +        String fileName;
    1.91 +        String failedString;
    1.92 +        String passedString;
    1.93 +        for (int i = 0; i < testArray.length; i++) {
    1.94 +            numTestsRun++;
    1.95 +            fileName = testArray[i];
    1.96 +            failedString = "FAILED" + "\n"
    1.97 +                    + "for bug " + getBugId() + " (" + getBugName() + ") "
    1.98 +                    + "file (" + fileName + ") found" + "\n";
    1.99 +            passedString = "Passed" + "\n" +
   1.100 +                        "file (" + fileName + ") not found" + "\n";
   1.101 +            System.out.print("Running subtest #" + numTestsRun + "... ");
   1.102 +            try {
   1.103 +                File file = new File(fileName);
   1.104 +                if ((file.exists() && !isNegated) || (!file.exists() && isNegated)) {
   1.105 +                    numTestsPassed += 1;
   1.106 +                    System.out.println(passedString);
   1.107 +                } else {
   1.108 +                    System.out.println(failedString);
   1.109 +                }
   1.110 +            } catch (Error e) {
   1.111 +                System.err.println(e);
   1.112 +            }
   1.113 +        }
   1.114 +    }
   1.115 +
   1.116 +    /**
   1.117       * Iterate through the list of given file pairs and diff each file.
   1.118       *
   1.119       * @param filePairs the pairs of files to diff.

mercurial