jdk/test/java/lang/Runtime/Version/Basic.java
author prappo
Fri, 21 Apr 2017 19:13:47 +0100
changeset 44785 62a18e20f5c1
parent 44272 4d16899cb312
permissions -rw-r--r--
8177738: Runtime.Version must be a value-based class 8148822: (spec) Regex in Runtime.Version and JEP 223 should match 8160954: (spec) Runtime.Version regex and $PRE/$OPT issues 8148877: (spec) Specify when an empty '+' is required in a version string Reviewed-by: psandoz, rriggs Contributed-by: Iris Clark <iris.clark@oracle.com>, Pavel Rappo <pavel.rappo@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
     1
/*
44265
ac63ae089927 8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents: 39766
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
     4
 *
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
     8
 *
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    13
 * accompanied this code).
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    14
 *
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    18
 *
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    21
 * questions.
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    22
 */
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    23
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    24
/*
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    25
 * @test
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
    26
 * @summary Unit test for java.lang.Runtime.Version
44265
ac63ae089927 8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents: 39766
diff changeset
    27
 * @bug 8072379 8144062 8161236 8160956
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    28
 */
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    29
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
    30
import java.lang.Runtime.Version;
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    31
import java.math.BigInteger;
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
    32
import java.util.ArrayList;
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    33
import java.util.Arrays;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    34
import java.util.List;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    35
import java.util.Optional;
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
    36
import java.util.stream.Collectors;
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    37
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    38
import static java.lang.System.out;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    39
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    40
public class Basic {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    41
    private static final Class<? extends Throwable> IAE
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    42
        = IllegalArgumentException.class;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    43
    private static final Class<? extends Throwable> NPE
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    44
        = NullPointerException.class;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    45
    private static final Class<? extends Throwable> NFE
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    46
        = NumberFormatException.class;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    47
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    48
    private static final BigInteger TOO_BIG
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    49
        = (BigInteger.valueOf(Integer.MAX_VALUE)).add(BigInteger.ONE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    50
    private static final String TOO_BIG_STR = TOO_BIG.toString();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    51
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    52
    public static void main(String ... args) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    53
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    54
        //// Tests for parse(), major(), minor(), security(), pre(),
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 38432
diff changeset
    55
        //// build(), optional(), version(), toString()
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    56
        //   v                          M     m sec pre bld opt
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    57
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    58
        // $VNUM
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    59
        test("9",                       9,    0, 0, "", 0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    60
        test("9.1",                     9,    1, 0, "", 0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    61
        test("9.0.1",                   9,    0, 1, "", 0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    62
        test("404.1.2",                 404,  1, 2, "", 0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    63
        test("9.1.2.3",                 9,    1, 2, "", 0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    64
        test("1000.0.0.0.0.0.99999999", 1000, 0, 0, "", 0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    65
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    66
        tryCatch(null,    NPE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    67
        tryCatch("",      IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    68
        tryCatch("foo",   IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    69
        tryCatch("7a",    IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    70
        tryCatch("0",     IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    71
        tryCatch("09",    IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    72
        tryCatch("9.0",   IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    73
        tryCatch("9.0.",  IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    74
        tryCatch("1.9,1", IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    75
        tryCatch(TOO_BIG_STR, NFE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    76
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    77
        // $PRE
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    78
        test("9-ea",       9, 0, 0, "ea",       0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    79
        test("9-internal", 9, 0, 0, "internal", 0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    80
        test("9-0",        9, 0, 0, "0",        0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    81
        test("9.2.7-8",    9, 2, 7, "8",        0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    82
        test("1-ALL",      1, 0, 0, "ALL",      0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    83
        test("2.3.4.5-1a", 2, 3, 4, "1a",       0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    84
        test("1-" + TOO_BIG_STR, 1, 0, 0, TOO_BIG_STR, 0, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    85
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    86
        tryCatch("9:-ea",     IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    87
        tryCatch("3.14159-",  IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    88
        tryCatch("3.14159-%", IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    89
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    90
        // $BUILD
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    91
        test("9+0",            9, 0,  0,  "",      0,       "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    92
        test("3.14+9999900",   3, 14, 0,  "",      9999900, "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    93
        test("9-pre+105",      9, 0,  0,  "pre",   105,     "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    94
        test("6.0.42-8beta+4", 6, 0,  42, "8beta", 4,       "");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    95
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    96
        tryCatch("9+",     IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    97
        tryCatch("7+a",    IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    98
        tryCatch("9+00",   IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
    99
        tryCatch("4.2+01", IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   100
        tryCatch("4.2+1a", IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   101
        tryCatch("1+" + TOO_BIG_STR, NFE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   102
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   103
        // $OPT
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   104
        test("9+-foo",          9,   0, 0, "",       0,  "foo");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   105
        test("9-pre-opt",       9,   0, 0, "pre",    0,  "opt");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   106
        test("42+---bar",       42,  0, 0, "",       0,  "--bar");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   107
        test("2.91+-8061493-",  2,  91, 0, "",       0,  "8061493-");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   108
        test("24+-foo.bar",     24,  0, 0, "",       0,  "foo.bar");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   109
        test("9-ribbit+17-...", 9,   0, 0, "ribbit", 17, "...");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   110
        test("7+1-" + TOO_BIG_STR, 7,0, 0, "",       1,  TOO_BIG_STR);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   111
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   112
        tryCatch("9-pre+-opt", IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   113
        tryCatch("1.4142+-",   IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   114
        tryCatch("2.9979+-%",  IAE);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   115
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   116
        //// Test for Runtime.version()
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   117
        testVersion();
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   118
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 38432
diff changeset
   119
        //// Test for equals{IgnoreOptional}?(), hashCode(),
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 38432
diff changeset
   120
        //// compareTo{IgnoreOptional}?()
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   121
        // compare: after "<" == -1, equal == 0, before ">" == 1
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   122
        //      v0            v1                  eq     eqNO  cmp  cmpNO
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   123
        testEHC("9",          "9",                true,  true,   0,    0);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   124
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   125
        testEHC("8",          "9",                false, false, -1,   -1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   126
        testEHC("9",          "10",               false, false, -1,   -1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   127
        testEHC("9",          "8",                false, false,  1,    1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   128
44272
4d16899cb312 8176882: Incorrect integer comparison in version numbers
prappo
parents: 44265
diff changeset
   129
        testEHC("10.512.1",   "10.512.2",         false, false, -1,   -1);
4d16899cb312 8176882: Incorrect integer comparison in version numbers
prappo
parents: 44265
diff changeset
   130
        testEHC("512.10.1",   "512.11.1",         false, false, -1,   -1);
4d16899cb312 8176882: Incorrect integer comparison in version numbers
prappo
parents: 44265
diff changeset
   131
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   132
        // $OPT comparison
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   133
        testEHC("9",          "9+-oink",          false, true,  -1,    0);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   134
        testEHC("9+-ribbit",  "9+-moo",           false, true,   1,    0);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   135
        testEHC("9-quack+3-ribbit",
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   136
                              "9-quack+3-moo",    false, true,   1,    0);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   137
        testEHC("9.1+7",      "9.1+7-moo-baa-la", false, true,  -1,    0);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   138
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   139
        // numeric vs. non-numeric $PRE
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   140
        testEHC("9.1.1.2-2a", "9.1.1.2-12",       false, false,  1,    1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   141
        testEHC("9.1.1.2-12", "9.1.1.2-4",        false, false,  1,    1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   142
44265
ac63ae089927 8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents: 39766
diff changeset
   143
        testEHC("27.16",      "27.16+120",        false, false, -1,   -1);
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   144
        testEHC("10",         "10-ea",            false, false,  1,    1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   145
        testEHC("10.1+1",     "10.1-ea+1",        false, false,  1,    1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   146
        testEHC("10.0.1+22",  "10.0.1+21",        false, false,  1,    1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   147
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   148
        // numeric vs. non-numeric $PRE
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   149
        testEHC("9.1.1.2-12", "9.1.1.2-a2",       false, false, -1,   -1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   150
        testEHC("9.1.1.2-1",  "9.1.1.2-4",        false, false, -1,   -1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   151
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   152
        testEHC("9-internal", "9",                false, false, -1,   -1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   153
        testEHC("9-ea+120",   "9+120",            false, false, -1,   -1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   154
        testEHC("9-ea+120",   "9+120",            false, false, -1,   -1);
44265
ac63ae089927 8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents: 39766
diff changeset
   155
        testEHC("9+101",      "9",                false, false,  1,    1);
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   156
        testEHC("9+101",      "9+102",            false, false, -1,   -1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   157
        testEHC("1.9-ea",     "9-ea",             false, false, -1,   -1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   158
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   159
        if (fail != 0)
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   160
            throw new RuntimeException((fail + pass) + " tests: "
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   161
                                       + fail + " failure(s), first", first);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   162
        else
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   163
            out.println("all " + (fail + pass) + " tests passed");
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   164
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   165
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   166
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   167
    private static void test(String s, Integer major, Integer minor,
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   168
                             Integer sec, String pre, Integer build,
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   169
                             String opt)
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   170
    {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   171
        Version v = testParse(s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   172
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   173
        testStr(v.toString(), s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   174
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   175
        testInt(v.major(), major);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   176
        testInt(v.minor(), minor);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   177
        testInt(v.security(), sec);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   178
        testStr((v.pre().isPresent() ? v.pre().get() : ""), pre);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   179
        testInt((v.build().isPresent() ? v.build().get() : 0), build);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   180
        testStr((v.optional().isPresent() ? v.optional().get() : ""), opt);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   181
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   182
        testVersion(v.version(), s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   183
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   184
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   185
    private static Version testParse(String s) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   186
        Version v = Version.parse(s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   187
        pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   188
        return v;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   189
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   190
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   191
    private static void testInt(int got, int exp) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   192
        if (got != exp) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   193
            fail("testInt()", Integer.toString(exp), Integer.toString(got));
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   194
        } else {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   195
            pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   196
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   197
     }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   198
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   199
    private static void testStr(String got, String exp) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   200
        if (!got.equals(exp)) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   201
            fail("testStr()", exp, got);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   202
        } else {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   203
            pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   204
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   205
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   206
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   207
    private static void tryCatch(String s, Class<? extends Throwable> ex) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   208
        Throwable t = null;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   209
        try {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   210
            Version.parse(s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   211
        } catch (Throwable x) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   212
            if (ex.isAssignableFrom(x.getClass())) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   213
                t = x;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   214
            } else
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   215
                x.printStackTrace();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   216
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   217
        if ((t == null) && (ex != null))
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   218
            fail(s, ex);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   219
        else
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   220
            pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   221
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   222
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   223
    private static void testVersion() {
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   224
        Version current = Runtime.version();
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   225
        String javaVer = System.getProperty("java.runtime.version");
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   226
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   227
        // java.runtime.version == $VNUM(\-$PRE)?(\+$BUILD)?(-$OPT)?
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   228
        String [] jv  = javaVer.split("\\+");
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   229
        String [] ver = jv[0].split("-");
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   230
        List<Integer> javaVerVNum
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   231
            = Arrays.stream(ver[0].split("\\."))
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   232
            .map(Integer::parseInt)
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   233
            .collect(Collectors.toList());
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   234
        if (!javaVerVNum.equals(current.version())) {
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 35701
diff changeset
   235
            fail("Runtime.version()", javaVerVNum.toString(),
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   236
                 current.version().toString());
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   237
        } else {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   238
            pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   239
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   240
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   241
        Optional<String> javaVerPre
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   242
            = (ver.length == 2)
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   243
            ? Optional.ofNullable(ver[1])
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   244
            : Optional.empty();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   245
        if (!javaVerPre.equals(current.pre())) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   246
            fail("testCurrent() pre()", javaVerPre.toString(),
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   247
                 current.pre().toString());
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   248
        } else {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   249
            pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   250
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   251
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   252
        testEHC(current.toString(), javaVer, true, true, 0, 0);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   253
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   254
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   255
    private static void testVersion(List<Integer> vnum, String s) {
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   256
        List<Integer> svnum = new ArrayList<>();
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   257
        StringBuilder sb = new StringBuilder();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   258
        for (int i = 0; i < s.length(); i++) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   259
            Character c = s.charAt(i);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   260
            if (Character.isDigit(c)) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   261
                sb.append(c);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   262
            } else {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   263
                svnum.add(Integer.parseInt(sb.toString()));
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   264
                sb = new StringBuilder();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   265
                if (c == '+' || c == '-') {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   266
                    break;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   267
                }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   268
            }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   269
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   270
        if (sb.length() > 0) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   271
            svnum.add(Integer.parseInt(sb.toString()));
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   272
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   273
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   274
        if (!svnum.equals(vnum)) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   275
            fail("testVersion() equals()", svnum.toString(), vnum.toString());
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   276
        } else {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   277
            pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   278
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   279
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   280
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   281
    private static void testEHC(String s0, String s1, boolean eq, boolean eqNO,
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   282
                                int cmp, int cmpNO)
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   283
    {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   284
        Version v0 = Version.parse(s0);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   285
        Version v1 = Version.parse(s1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   286
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   287
        testEquals(v0, v1, eq);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   288
        testEqualsNO(v0, v1, eqNO);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   289
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   290
        testHashCode(v0, v1, eq);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   291
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   292
        testCompare(v0, v1, cmp);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   293
        testCompareNO(v0, v1, cmpNO);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   294
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   295
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   296
    private static void testEqualsNO(Version v0, Version v1, boolean eq) {
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   297
        if (eq == v0.equalsIgnoreOptional(v1)) {
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   298
            pass();
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   299
        } else {
39766
745f165bedee 8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents: 38432
diff changeset
   300
            fail("equalsIgnoreOptional() " + Boolean.toString(eq),
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   301
                 v0.toString(), v1.toString());
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   302
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   303
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   304
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   305
    private static void testEquals(Version v0, Version v1, boolean eq) {
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   306
        if (eq == v0.equals(v1)) {
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   307
            pass();
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   308
        } else {
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   309
            fail("equals() " + Boolean.toString(eq),
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   310
                 v0.toString(), v1.toString());
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   311
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   312
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   313
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   314
    private static void testHashCode(Version v0, Version v1, boolean eq) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   315
        int h0 = v0.hashCode();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   316
        int h1 = v1.hashCode();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   317
        if (eq) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   318
            testInt(h0, h1);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   319
        } else if (h0 == h1) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   320
            fail(String.format("hashCode() %s", h0),
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   321
                 Integer.toString(h0),
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   322
                 Integer.toString(h1));
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   323
        } else { // !eq && (h0 != h1)
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   324
            pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   325
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   326
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   327
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   328
    private static void testCompareNO(Version v0, Version v1, int compare) {
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   329
        int cmp = v0.compareToIgnoreOptional(v1);
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   330
        checkCompare(v0, v1, compare, cmp);
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   331
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   332
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   333
    private static void testCompare(Version v0, Version v1, int compare) {
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   334
        int cmp = v0.compareTo(v1);
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   335
        checkCompare(v0, v1, compare, cmp);
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   336
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   337
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   338
    private static void checkCompare(Version v0, Version v1,
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   339
                                     int expected, int actual)
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   340
    {
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   341
        if (Integer.signum(expected) == Integer.signum(actual)) {
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   342
            pass();
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   343
        } else {
44785
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   344
            fail(String.format("compare() (actual = %s) (expected = %s)",
62a18e20f5c1 8177738: Runtime.Version must be a value-based class
prappo
parents: 44272
diff changeset
   345
                               actual, expected),
35701
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   346
                 v0.toString(), v1.toString());
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   347
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   348
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   349
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   350
    private static int fail = 0;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   351
    private static int pass = 0;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   352
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   353
    private static Throwable first;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   354
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   355
    static void pass() {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   356
        pass++;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   357
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   358
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   359
    static void fail(String fs, Class ex) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   360
        String s = "'" + fs + "'";
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   361
        if (ex != null)
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   362
            s += ": " + ex.getName() + " not thrown";
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   363
        if (first == null)
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   364
            setFirst(s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   365
        System.err.println("FAILED: " + s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   366
        fail++;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   367
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   368
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   369
    static void fail(String t, String exp, String got) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   370
        String s = t + ": Expected '" + exp + "', got '" + got + "'";
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   371
        if (first == null)
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   372
            setFirst(s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   373
        System.err.println("FAILED: " + s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   374
        fail++;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   375
     }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   376
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   377
    private static void setFirst(String s) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   378
        try {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   379
            throw new RuntimeException(s);
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   380
        } catch (RuntimeException x) {
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   381
            first = x;
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   382
        }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   383
    }
d5a24d2b0494 8072379: Implement jdk.Version
iris
parents:
diff changeset
   384
}