< prev index next >

test/langtools/jdk/javadoc/tool/ToolProviderTest.java

Print this page
rev 48243 : 8189102: All tools should support -?, -h and --help
Reviewed-by: kvn, jjg, weijun, alanb, rfield, ksrini
   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  52         javadoc = ToolProvider.findFirst("javadoc").get();
  53     }
  54 
  55     @Test
  56     public void testProviders() throws Exception {
  57         Map<String, ToolProvider> providers = new LinkedHashMap<>();
  58         for (ToolProvider tp : ServiceLoader.load(ToolProvider.class,
  59                 ClassLoader.getSystemClassLoader())) {
  60             System.out.println("Provider: " + tp.name() + ": " + tp.getClass().getName());
  61             providers.put(tp.name(), tp);
  62         }
  63         if (!providers.containsKey("javadoc")) {
  64             error("javadoc ToolProvider not found");
  65         }
  66     }
  67 
  68     @Test
  69     public void testOneStream() throws Exception {
  70         StringWriter sw = new StringWriter();
  71         try (PrintWriter pw = new PrintWriter(sw)) {
  72             int rc = javadoc.run(pw, pw, "-help");
  73             if (rc != 0) {
  74                 error("unexpected exit code: " + rc);
  75             }
  76         }
  77         String out = sw.toString();
  78         if (!out.contains("Usage:")) {
  79             error("expected output not found");
  80         }
  81     }
  82 
  83     @Test
  84     public void testTwoStreamsOut() throws Exception {
  85         StringWriter swOut = new StringWriter();
  86         StringWriter swErr = new StringWriter();
  87         try (PrintWriter pwOut = new PrintWriter(swOut);
  88                 PrintWriter pwErr = new PrintWriter(swErr)) {
  89             int rc = javadoc.run(pwOut, pwErr, "-help");
  90             if (rc != 0) {
  91                 error("unexpected exit code: " + rc);
  92             }
  93         }
  94         String out = swOut.toString();
  95         String err = swErr.toString();
  96         if (!out.contains("Usage:")) {
  97             error("stdout: expected output not found");
  98         }
  99         if (!err.isEmpty()) {
 100             error("stderr: unexpected output");
 101         }
 102     }
 103 
 104     @Test
 105     public void testTwoStreamsErr() throws Exception {
 106         Path src = Paths.get("src");
 107         Path classes = Paths.get("classes");
 108         tb.writeJavaFiles(src,
 109             "import java.util.*; class C { # }");


   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  52         javadoc = ToolProvider.findFirst("javadoc").get();
  53     }
  54 
  55     @Test
  56     public void testProviders() throws Exception {
  57         Map<String, ToolProvider> providers = new LinkedHashMap<>();
  58         for (ToolProvider tp : ServiceLoader.load(ToolProvider.class,
  59                 ClassLoader.getSystemClassLoader())) {
  60             System.out.println("Provider: " + tp.name() + ": " + tp.getClass().getName());
  61             providers.put(tp.name(), tp);
  62         }
  63         if (!providers.containsKey("javadoc")) {
  64             error("javadoc ToolProvider not found");
  65         }
  66     }
  67 
  68     @Test
  69     public void testOneStream() throws Exception {
  70         StringWriter sw = new StringWriter();
  71         try (PrintWriter pw = new PrintWriter(sw)) {
  72             int rc = javadoc.run(pw, pw, "--help");
  73             if (rc != 0) {
  74                 error("unexpected exit code: " + rc);
  75             }
  76         }
  77         String out = sw.toString();
  78         if (!out.contains("Usage:")) {
  79             error("expected output not found");
  80         }
  81     }
  82 
  83     @Test
  84     public void testTwoStreamsOut() throws Exception {
  85         StringWriter swOut = new StringWriter();
  86         StringWriter swErr = new StringWriter();
  87         try (PrintWriter pwOut = new PrintWriter(swOut);
  88                 PrintWriter pwErr = new PrintWriter(swErr)) {
  89             int rc = javadoc.run(pwOut, pwErr, "--help");
  90             if (rc != 0) {
  91                 error("unexpected exit code: " + rc);
  92             }
  93         }
  94         String out = swOut.toString();
  95         String err = swErr.toString();
  96         if (!out.contains("Usage:")) {
  97             error("stdout: expected output not found");
  98         }
  99         if (!err.isEmpty()) {
 100             error("stderr: unexpected output");
 101         }
 102     }
 103 
 104     @Test
 105     public void testTwoStreamsErr() throws Exception {
 106         Path src = Paths.get("src");
 107         Path classes = Paths.get("classes");
 108         tb.writeJavaFiles(src,
 109             "import java.util.*; class C { # }");


< prev index next >