cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
changeset 1041 b03a880d538e
parent 1037 55c0650c5969
child 1042 06b3af1708ef
     1.1 --- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java	Sun Jan 08 20:11:44 2017 +0100
     1.2 +++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java	Sun Feb 12 10:11:52 2017 +0100
     1.3 @@ -536,12 +536,120 @@
     1.4                        "--apply");
     1.5      }
     1.6  
     1.7 +    public void testAutomaticTestRun() throws Exception {
     1.8 +        class Config {
     1.9 +            private final String commandLineOption;
    1.10 +            private final int result;
    1.11 +            private final Validator validator;
    1.12 +
    1.13 +            public Config(String commandLineOption, int result, Validator validator) {
    1.14 +                this.commandLineOption = commandLineOption;
    1.15 +                this.result = result;
    1.16 +                this.validator = validator;
    1.17 +            }
    1.18 +
    1.19 +        }
    1.20 +        Validator testValidator =
    1.21 +                equivalentValidator("${workdir}/src/META-INF/upgrade/test.test:15: error: [test_failure] Actual results did not match the expected test results. Actual results: []\n" +
    1.22 +                                    "%%TestCase pos-neg\n" +
    1.23 +                                    "^\n" +
    1.24 +                                    "${workdir}/src/META-INF/upgrade/test.test:29: error: [test_failure] Actual results did not match the expected test results. Actual results: [package test;\n" +
    1.25 +                                    "public class Test {{\n" +
    1.26 +                                    "    private void test(java.util.Collection c) {\n" +
    1.27 +                                    "        boolean b1 = c.isEmpty();\n" +
    1.28 +                                    "    }\n" +
    1.29 +                                    "}}\n" +
    1.30 +                                    "]\n" +
    1.31 +                                    "%%TestCase neg-neg\n" +
    1.32 +                                    "^\n" +
    1.33 +                                    "${workdir}/src/test/Test.java:4: warning: [test] test\n" +
    1.34 +                                    "        boolean b1 = c.size() == 0;\n" +
    1.35 +                                    "                     ^\n");
    1.36 +        List<? extends Config> options =
    1.37 +                Arrays.asList(new Config("--run-tests", 1, testValidator),
    1.38 +                              new Config(IGNORE, 0, equivalentValidator("${workdir}/src/test/Test.java:4: warning: [test] test\n" +
    1.39 +                                                                        "        boolean b1 = c.size() == 0;\n" +
    1.40 +                                                                        "                     ^\n")));
    1.41 +        for (Config testConfig : options) {
    1.42 +            doRunCompiler(equivalentValidator("package test;\n" +
    1.43 +                                              "public class Test {\n" +
    1.44 +                                              "    private void test(java.util.Collection c) {\n" +
    1.45 +                                              "        boolean b1 = c.size() == 0;\n" +
    1.46 +                                              "        boolean b2 = c.size() != 0;\n" +
    1.47 +                                              "    }\n" +
    1.48 +                                              "}\n"),
    1.49 +                          testConfig.validator,
    1.50 +                          equivalentValidator(""),
    1.51 +                          testConfig.result,
    1.52 +                          "src/META-INF/upgrade/test.hint",
    1.53 +                          "$coll.size() == 0 :: $coll instanceof java.util.Collection\n" +
    1.54 +                          "=>\n" +
    1.55 +                          "$coll.isEmpty()\n" +
    1.56 +                          ";;",
    1.57 +                          "src/META-INF/upgrade/test.test",
    1.58 +                          "%%TestCase pos-pos\n" +
    1.59 +                          "package test;\n" +
    1.60 +                          "public class Test {{\n" +
    1.61 +                          "    private void test(java.util.Collection c) {\n" +
    1.62 +                          "        boolean b1 = c.size() == 0;\n" +
    1.63 +                          "    }\n" +
    1.64 +                          "}}\n" +
    1.65 +                          "%%=>\n" +
    1.66 +                          "package test;\n" +
    1.67 +                          "public class Test {{\n" +
    1.68 +                          "    private void test(java.util.Collection c) {\n" +
    1.69 +                          "        boolean b1 = c.isEmpty();\n" +
    1.70 +                          "    }\n" +
    1.71 +                          "}}\n" +
    1.72 +                          "%%TestCase pos-neg\n" +
    1.73 +                          "package test;\n" +
    1.74 +                          "public class Test {{\n" +
    1.75 +                          "    private void test(java.util.Collection c) {\n" +
    1.76 +                          "        boolean b1 = c.size() == 0;\n" +
    1.77 +                          "    }\n" +
    1.78 +                          "}}\n" +
    1.79 +                          "%%TestCase neg-pos\n" +
    1.80 +                          "package test;\n" +
    1.81 +                          "public class Test {{\n" +
    1.82 +                          "    private void test(java.util.Collection c) {\n" +
    1.83 +                          "        boolean b1 = c.size() != 0;\n" +
    1.84 +                          "    }\n" +
    1.85 +                          "}}\n" +
    1.86 +                          "%%TestCase neg-neg\n" +
    1.87 +                          "package test;\n" +
    1.88 +                          "public class Test {{\n" +
    1.89 +                          "    private void test(java.util.Collection c) {\n" +
    1.90 +                          "        boolean b1 = c.size() != 0;\n" +
    1.91 +                          "    }\n" +
    1.92 +                          "}}\n" +
    1.93 +                          "%%=>\n" +
    1.94 +                          "package test;\n" +
    1.95 +                          "public class Test {{\n" +
    1.96 +                          "    private void test(java.util.Collection c) {\n" +
    1.97 +                          "        boolean b1 = c.isEmpty();\n" +
    1.98 +                          "    }\n" +
    1.99 +                          "}}\n",
   1.100 +                          "src/test/Test.java",
   1.101 +                          "package test;\n" +
   1.102 +                          "public class Test {\n" +
   1.103 +                          "    private void test(java.util.Collection c) {\n" +
   1.104 +                          "        boolean b1 = c.size() == 0;\n" +
   1.105 +                          "        boolean b2 = c.size() != 0;\n" +
   1.106 +                          "    }\n" +
   1.107 +                          "}\n",
   1.108 +                          null,
   1.109 +                          testConfig.commandLineOption,
   1.110 +                          "--sourcepath", "${workdir}/src");
   1.111 +        }
   1.112 +    }
   1.113 +
   1.114      public void testGroupsParamEscape() throws Exception {
   1.115          assertEquals(Arrays.asList("a b", "a\\b"),
   1.116                       Arrays.asList(Main.splitGroupArg("a\\ b a\\\\b")));
   1.117      }
   1.118  
   1.119      private static final String DONT_APPEND_PATH = new String("DONT_APPEND_PATH");
   1.120 +    private static final String IGNORE = new String("IGNORE");
   1.121  
   1.122      private void doRunCompiler(String golden, String stdOut, String stdErr, String... fileContentAndExtraOptions) throws Exception {
   1.123          doRunCompiler(equivalentValidator(golden), equivalentValidator(stdOut), equivalentValidator(stdErr), fileContentAndExtraOptions);
   1.124 @@ -590,6 +698,9 @@
   1.125                  appendPath = false;
   1.126                  continue;
   1.127              }
   1.128 +            if (extraOption == IGNORE) {
   1.129 +                continue;
   1.130 +            }
   1.131              options.add(extraOption.replace("${workdir}", wd.getAbsolutePath()));
   1.132          }
   1.133