langtools/test/tools/javac/options/T6986895.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 8623 cc57bd7697a2
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8623
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 8623
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
8623
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
     4
 *
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
     8
 *
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    13
 * accompanied this code).
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    14
 *
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    18
 *
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    21
 * questions.
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    22
 */
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    23
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    24
/*
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    25
 * @test
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    26
 * @bug 6986895
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    27
 * @summary compiler gives misleading message for no input files
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 8623
diff changeset
    28
 * @modules jdk.compiler
8623
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    29
 */
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    30
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    31
import java.io.*;
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    32
import java.util.*;
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    33
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    34
public class T6986895 {
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    35
    public static void main(String... args) throws Exception {
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    36
        new T6986895().run();
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    37
    }
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    38
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    39
    String noSourceFiles = "no source files";
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    40
    String noSourceFilesOrClasses = "no source files or class names";
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    41
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    42
    void run() throws Exception {
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    43
        Locale prev = Locale.getDefault();
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    44
        try {
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    45
            Locale.setDefault(Locale.ENGLISH);
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    46
            test(noSourceFiles,           "-Werror");
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    47
            test(noSourceFilesOrClasses,  "-Werror", "-Xprint");
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    48
        } finally {
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    49
            Locale.setDefault(prev);
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    50
        }
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    51
    }
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    52
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    53
    void test(String expect, String... args) throws Exception {
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    54
        System.err.println("Test " + expect + ": " + Arrays.asList(args));
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    55
        StringWriter sw = new StringWriter();
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    56
        PrintWriter pw = new PrintWriter(sw);
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    57
        int rc = com.sun.tools.javac.Main.compile(args, pw);
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    58
        pw.close();
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    59
        System.err.println("compilation failed; rc=" + rc);
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    60
        String out = sw.toString();
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    61
        if (!out.isEmpty())
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    62
            System.err.println(out);
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    63
        if (!out.contains(expect))
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    64
            throw new Exception("expected text not found: " + expect);
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    65
        System.err.println();
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    66
    }
cc57bd7697a2 6986895: compiler gives misleading message for no input files
jjg
parents:
diff changeset
    67
}