langtools/test/tools/javac/options/modes/SourceTargetTest.java
author jjg
Fri, 22 Aug 2014 16:28:16 -0700
changeset 26264 a09fedde76be
child 30730 d3ce7619db2c
permissions -rw-r--r--
8044859: javac duplicates option processing when using Compiler API Reviewed-by: mcimadamore, vromero, jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     1
/*
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     4
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     8
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    13
 * accompanied this code).
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    14
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    18
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    21
 * questions.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    22
 */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    23
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    24
/*
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    25
 * @test
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    26
 * @bug 8044859
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    27
 * @summary test support for -source and -target checks
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    28
 * @build Tester
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    29
 * @run main SourceTargetTest
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    30
 */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    31
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    32
import com.sun.tools.javac.main.Main;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    33
import java.io.IOException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    34
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    35
public class SourceTargetTest extends Tester {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    36
    public static void main(String... args) throws Exception {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    37
        SourceTargetTest t = new SourceTargetTest();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    38
        t.runTests();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    39
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    40
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    41
    @Test
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    42
    void testSourceTarget() throws IOException {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    43
        String v = System.getProperty("java.specification.version");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    44
        String latest = v.substring(v.lastIndexOf(".") + 1);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    45
        String prev = String.valueOf(Integer.valueOf(latest) - 1);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    46
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    47
        writeFile("C.java", "class C { }");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    48
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    49
        String[] opts = { "-source", latest, "-target", prev };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    50
        String[] files = { "C.java" };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    51
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    52
        runMain(opts, files)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    53
                .checkResult(Main.Result.CMDERR.exitCode);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    54
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    55
        runCall(opts, files)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    56
                .checkIllegalStateException();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    57
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    58
        runParse(opts, files)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    59
                .checkIllegalStateException();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    60
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    61
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    62
    @Test
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    63
    void testObsoleteSourceTarget() throws IOException {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    64
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    65
        writeFile("C.java", "class C { }");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    66
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    67
        String[] opts = { "-source", "1.6", "-target", "1.6" };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    68
        String[] files = { "C.java" };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    69
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    70
        runMain(opts, files)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    71
                .checkOK()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    72
                .checkLog("obsolete");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    73
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    74
        runCall(opts, files)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    75
                .checkOK()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    76
                .checkLog("obsolete");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    77
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    78
        runParse(opts, files)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    79
                .checkOK()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    80
                .checkLog("obsolete");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    81
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    82
}