test/jdk/tools/launcher/ArgFileSyntax.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 51958 53a4760e9fcc
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     1
/*
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     4
 *
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     8
 *
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    13
 * accompanied this code).
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    14
 *
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    18
 *
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    21
 * questions.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    22
 */
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    23
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    24
/**
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    25
 * @test
51958
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
    26
 * @bug 8027634 8210810
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    27
 * @summary Verify syntax of argument file
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    28
 * @build TestHelper
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    29
 * @run main ArgFileSyntax
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    30
 */
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    31
import java.io.File;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    32
import java.io.IOException;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    33
import java.util.ArrayList;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    34
import java.util.Arrays;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    35
import java.util.Collections;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    36
import java.util.HashMap;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    37
import java.util.List;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    38
import java.util.Map;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    39
import java.util.regex.Matcher;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    40
import java.util.regex.Pattern;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    41
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    42
public class ArgFileSyntax extends TestHelper {
51958
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
    43
    // Buffer size in args.c readArgFile() method
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
    44
    private static final int ARG_FILE_PARSER_BUF_SIZE = 4096;
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
    45
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    46
    private File createArgFile(List<String> lines) throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    47
        File argFile = new File("argfile");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    48
        argFile.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    49
        createAFile(argFile, lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    50
        return argFile;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    51
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    52
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    53
    private void verifyOutput(List<String> args, TestResult tr) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    54
        if (args.isEmpty()) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    55
            return;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    56
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    57
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    58
        int i = 1;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    59
        for (String x : args) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    60
            tr.matches(".*argv\\[" + i + "\\] = " + Pattern.quote(x) + ".*");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    61
            i++;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    62
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    63
        if (! tr.testStatus) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    64
            System.out.println(tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    65
            throw new RuntimeException("test fails");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    66
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    67
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    68
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    69
    // arg file content,  expected options
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    70
    static String[] testCases[][] = {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    71
        { // empty file
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    72
            {}, {}
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    73
        },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    74
        { // comments and # inside quote
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    75
            { "# a couple of -X flags",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    76
              "-Xmx32m",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    77
              "-XshowSettings #inline comment",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    78
              "-Dpound.in.quote=\"This property contains #.\"",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    79
              "# add -version",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    80
              "-version",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    81
              "# trail comment"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    82
            },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    83
            { "-Xmx32m",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    84
              "-XshowSettings",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    85
              "-Dpound.in.quote=This property contains #.",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    86
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    87
            }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    88
        },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    89
        { // open quote with continuation directive
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    90
          // multiple options in a line
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    91
            { "-cp \"c:\\\\java lib\\\\all;\\",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    92
              "     c:\\\\lib\"",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    93
              "-Xmx32m -XshowSettings",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    94
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    95
            },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    96
            { "-cp",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    97
              "c:\\java lib\\all;c:\\lib",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    98
              "-Xmx32m",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    99
              "-XshowSettings",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   100
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   101
            }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   102
        },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   103
        { // no continuation on open quote
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   104
          // multiple lines in a property
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   105
            { "-cp \"c:\\\\open quote\\\\all;",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   106
              "     # c:\\\\lib\"",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   107
              "-Dmultiple.lines=\"line 1\\nline 2\\n\\rline 3\"",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   108
              "-Dopen.quote=\"Open quote to EOL",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   109
              "-Dcontinue.with.leadingWS=\"Continue with\\",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   110
              "  \\ leading WS.",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   111
              "-Dcontinue.without.leadingWS=\"Continue without \\",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   112
              "   leading WS.",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   113
              "-Descape.seq=\"escaped chars: \\\"\\a\\b\\c\\f\\t\\v\\9\\6\\23\\82\\28\\377\\477\\278\\287\\n\"",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   114
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   115
            },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   116
            { "-cp",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   117
              "c:\\open quote\\all;",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   118
              "-Dmultiple.lines=line 1",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   119
              // line 2 and line 3 shoule be in output, but not as arg[x]=
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   120
              "-Dopen.quote=Open quote to EOL",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   121
              "-Dcontinue.with.leadingWS=Continue with leading WS.",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   122
              "-Dcontinue.without.leadingWS=Continue without leading WS.",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   123
              // cannot verify \n and \r as that break output lines
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   124
              "-Descape.seq=escaped chars: \"abc\f\tv96238228377477278287",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   125
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   126
            }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   127
        },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   128
        { // No need to escape if not in quote
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   129
          // also quote part of a token
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   130
            { "-cp c:\\\"partial quote\"\\all",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   131
              "-Xmx32m -XshowSettings",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   132
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   133
            },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   134
            { "-cp",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   135
              "c:\\partial quote\\all",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   136
              "-Xmx32m",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   137
              "-XshowSettings",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   138
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   139
            }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   140
        },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   141
        { // No recursive expansion
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   142
            { "-Xmx32m",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   143
              "-cp",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   144
              " # @cpfile should remains @cpfile",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   145
              "@cpfile",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   146
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   147
            },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   148
            { "-Xmx32m",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   149
              "-cp",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   150
              "@cpfile",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   151
              "-version"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   152
            }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   153
        },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   154
        { // Mix quotation
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   155
            { "-Dsingle.in.double=\"Mix 'single' in double\"",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   156
              "-Ddouble.in.single='Mix \"double\" in single'",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   157
              "-Dsingle.in.single='Escape \\\'single\\\' in single'",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   158
              "-Ddouble.in.double=\"Escape \\\"double\\\" in double\""
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   159
            },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   160
            { "-Dsingle.in.double=Mix 'single' in double",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   161
              "-Ddouble.in.single=Mix \"double\" in single",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   162
              "-Dsingle.in.single=Escape 'single' in single",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   163
              "-Ddouble.in.double=Escape \"double\" in double"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   164
            },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   165
        },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   166
        { // \t\f as whitespace and in escape
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   167
            { "-Xmx32m\t-Xint\f-version",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   168
              "-Dcontinue.with.leadingws=\"Line1\\",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   169
              " \t\fcontinue with \\f<ff> and \\t<tab>"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   170
            },
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   171
            { "-Xmx32m",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   172
              "-Xint",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   173
              "-version",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   174
              "-Dcontinue.with.leadingws=Line1continue with \f<ff> and \t<tab>"
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   175
            }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   176
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   177
    };
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   178
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   179
    public List<List<List<String>>> loadCases() {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   180
        List<List<List<String>>> rv = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   181
        for (String[][] testCaseArray: testCases) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   182
            List<List<String>> testCase = new ArrayList<>(2);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   183
            testCase.add(Arrays.asList(testCaseArray[0]));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   184
            testCase.add(Arrays.asList(testCaseArray[1]));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   185
            rv.add(testCase);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   186
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   187
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   188
        // long lines
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   189
        String bag = "-Dgarbage=";
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   190
        String ver = "-version";
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   191
        // a token 8192 long
51958
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   192
        char[] data = new char[2*ARG_FILE_PARSER_BUF_SIZE - bag.length()];
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   193
        Arrays.fill(data, 'O');
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   194
        List<String> scratch = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   195
        scratch.add("-Xmx32m");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   196
        scratch.add(bag + String.valueOf(data));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   197
        scratch.add(ver);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   198
        rv.add(Collections.nCopies(2, scratch));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   199
51958
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   200
        data = new char[2*ARG_FILE_PARSER_BUF_SIZE + 1024];
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   201
        Arrays.fill(data, 'O');
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   202
        scratch = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   203
        scratch.add(bag + String.valueOf(data));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   204
        scratch.add(ver);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   205
        rv.add(Collections.nCopies(2, scratch));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   206
51958
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   207
        // 8210810: position escaping character at boundary
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   208
        // reserve space for quote and backslash
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   209
        data = new char[ARG_FILE_PARSER_BUF_SIZE - bag.length() - 2];
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   210
        Arrays.fill(data, 'O');
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   211
        scratch = new ArrayList<>();
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   212
        String filling = String.valueOf(data);
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   213
        scratch.add(bag + "'" + filling + "\\\\aaa\\\\'");
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   214
        scratch.add(ver);
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   215
        rv.add(List.of(scratch, List.of(bag + filling + "\\aaa\\", ver)));
53a4760e9fcc 8210810: Escaped character at specific position in argument file is not handled properly
henryjen
parents: 47216
diff changeset
   216
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   217
        return rv;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   218
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   219
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   220
    // ensure the arguments in the file are read in correctly
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   221
    private void verifyParsing(List<String> lines, List<String> args) throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   222
        File argFile = createArgFile(lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   223
        String fname = "@" + argFile.getName();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   224
        Map<String, String> env = new HashMap<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   225
        env.put(JLDEBUG_KEY, "true");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   226
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   227
        TestResult tr;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   228
        if (args.contains("-version")) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   229
            tr = doExec(env, javaCmd, fname);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   230
        } else {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   231
            tr = doExec(env, javaCmd, fname, "-version");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   232
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   233
        tr.checkPositive();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   234
        verifyOutput(args, tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   235
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   236
        String lastArg = args.contains("-version") ? "-Dlast.arg" : "-version";
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   237
        tr = doExec(env, javaCmd, "-Xint", fname, lastArg);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   238
        List<String> scratch = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   239
        scratch.add("-Xint");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   240
        scratch.addAll(args);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   241
        scratch.add(lastArg);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   242
        verifyOutput(scratch, tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   243
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   244
        argFile.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   245
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   246
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   247
    @Test
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   248
    public void testSyntax() throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   249
        List<List<List<String>>> allcases = loadCases();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   250
        for (List<List<String>> test: allcases) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   251
            verifyParsing(test.get(0), test.get(1));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   252
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   253
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   254
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   255
    @Test
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   256
    public void badCases() throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   257
        List<String> lines = Arrays.asList(
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   258
            "-Dno.escape=\"Forgot to escape backslash\\\" -version");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   259
        File argFile = createArgFile(lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   260
        String fname = "@" + argFile.getName();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   261
        Map<String, String> env = new HashMap<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   262
        env.put(JLDEBUG_KEY, "true");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   263
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   264
        TestResult tr = doExec(env, javaCmd, fname);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   265
        tr.contains("argv[1] = -Dno.escape=Forgot to escape backslash\" -version");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   266
        tr.checkNegative();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   267
        if (!tr.testStatus) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   268
            System.out.println(tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   269
            throw new RuntimeException("test fails");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   270
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   271
        argFile.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   272
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   273
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   274
    public static void main(String... args) throws Exception {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   275
        ArgFileSyntax a = new ArgFileSyntax();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   276
        a.run(args);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   277
        if (testExitValue > 0) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   278
            System.out.println("Total of " + testExitValue + " failed");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   279
            System.exit(1);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   280
        } else {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   281
            System.out.println("All tests pass");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   282
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   283
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   284
}