langtools/test/tools/javadoc/doclint/DocLintTest.java
changeset 27319 030080f03e4f
parent 15713 55f55d4f5f9f
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   119     }
   119     }
   120 
   120 
   121     void run() throws Exception {
   121     void run() throws Exception {
   122         javadoc = ToolProvider.getSystemDocumentationTool();
   122         javadoc = ToolProvider.getSystemDocumentationTool();
   123         fm = javadoc.getStandardFileManager(null, null, null);
   123         fm = javadoc.getStandardFileManager(null, null, null);
   124         fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
   124         try {
   125         file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
   125             fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
   126             @Override
   126             file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
   127             public CharSequence getCharContent(boolean ignoreEncoding) {
   127                 @Override
   128                 return code;
   128                 public CharSequence getCharContent(boolean ignoreEncoding) {
   129             }
   129                     return code;
   130         };
   130                 }
   131 
   131             };
   132         test(Collections.<String>emptyList(),
   132 
   133                 Main.Result.ERROR,
   133             test(Collections.<String>emptyList(),
   134                 EnumSet.of(Message.DL_ERR9A, Message.DL_WRN12A));
   134                     Main.Result.ERROR,
   135 
   135                     EnumSet.of(Message.DL_ERR9A, Message.DL_WRN12A));
   136         test(Arrays.asList(rawDiags),
   136 
   137                 Main.Result.ERROR,
   137             test(Arrays.asList(rawDiags),
   138                 EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
   138                     Main.Result.ERROR,
   139 
   139                     EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
   140         test(Arrays.asList("-Xdoclint:none"),
   140 
   141                 Main.Result.OK,
   141             test(Arrays.asList("-Xdoclint:none"),
   142                 EnumSet.of(Message.JD_WRN10, Message.JD_WRN13));
   142                     Main.Result.OK,
   143 
   143                     EnumSet.of(Message.JD_WRN10, Message.JD_WRN13));
   144         test(Arrays.asList(rawDiags, "-Xdoclint"),
   144 
   145                 Main.Result.ERROR,
   145             test(Arrays.asList(rawDiags, "-Xdoclint"),
   146                 EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
   146                     Main.Result.ERROR,
   147 
   147                     EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
   148         test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
   148 
   149                 Main.Result.ERROR,
   149             test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
   150                 EnumSet.of(Message.OPT_BADQUAL));
   150                     Main.Result.ERROR,
   151 
   151                     EnumSet.of(Message.OPT_BADQUAL));
   152         test(Arrays.asList(rawDiags, "-Xdoclint:all", "-public"),
   152 
   153                 Main.Result.OK,
   153             test(Arrays.asList(rawDiags, "-Xdoclint:all", "-public"),
   154                 EnumSet.of(Message.DL_WRN12));
   154                     Main.Result.OK,
   155 
   155                     EnumSet.of(Message.DL_WRN12));
   156         test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
   156 
   157                 Main.Result.OK,
   157             test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
   158                 EnumSet.of(Message.DL_WRN12));
   158                     Main.Result.OK,
   159 
   159                     EnumSet.of(Message.DL_WRN12));
   160         test(Arrays.asList(rawDiags, "-private"),
   160 
   161                 Main.Result.ERROR,
   161             test(Arrays.asList(rawDiags, "-private"),
   162                 EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
   162                     Main.Result.ERROR,
   163 
   163                     EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
   164         test(Arrays.asList(rawDiags, "-Xdoclint:syntax", "-private"),
   164 
   165                 Main.Result.ERROR,
   165             test(Arrays.asList(rawDiags, "-Xdoclint:syntax", "-private"),
   166                 EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
   166                     Main.Result.ERROR,
   167 
   167                     EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
   168         test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
   168 
   169                 Main.Result.ERROR,
   169             test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
   170                 EnumSet.of(Message.DL_ERR9));
   170                     Main.Result.ERROR,
   171 
   171                     EnumSet.of(Message.DL_ERR9));
   172         test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
   172 
   173                 Main.Result.ERROR,
   173             test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
   174                 EnumSet.of(Message.OPT_BADARG));
   174                     Main.Result.ERROR,
   175 
   175                     EnumSet.of(Message.OPT_BADARG));
   176         if (errors > 0)
   176 
   177             throw new Exception(errors + " errors occurred");
   177             if (errors > 0)
       
   178                 throw new Exception(errors + " errors occurred");
       
   179         } finally {
       
   180             fm.close();
       
   181         }
   178     }
   182     }
   179 
   183 
   180     void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
   184     void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
   181         System.err.println("test: " + opts);
   185         System.err.println("test: " + opts);
   182         StringWriter sw = new StringWriter();
   186         StringWriter sw = new StringWriter();