author | herrick |
Fri, 08 Nov 2019 14:53:03 -0500 | |
branch | JDK-8200758-branch |
changeset 58994 | b09ba68c6a19 |
parent 58993 | b5e1baa9d2c3 |
permissions | -rw-r--r-- |
57314 | 1 |
/* |
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @summary jpackage create app image error test |
|
27 |
* @library ../helpers |
|
28 |
* @build JPackageHelper |
|
29 |
* @build JPackagePath |
|
57446 | 30 |
* @build Base |
58994
b09ba68c6a19
8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents:
58993
diff
changeset
|
31 |
* @modules jdk.incubator.jpackage |
57446 | 32 |
* @run main/othervm -Xmx512m ErrorTest |
57314 | 33 |
*/ |
34 |
import java.util.*; |
|
35 |
import java.io.*; |
|
36 |
import java.nio.*; |
|
37 |
import java.nio.file.*; |
|
38 |
import java.nio.file.attribute.*; |
|
39 |
||
57446 | 40 |
public class ErrorTest { |
57314 | 41 |
|
42 |
private static final String OUTPUT = "output"; |
|
43 |
||
44 |
private static final String ARG1 = "--no-such-argument"; |
|
45 |
private static final String EXPECTED1 = |
|
46 |
"Invalid Option: [--no-such-argument]"; |
|
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58114
diff
changeset
|
47 |
private static final String ARG2 = "--dest"; |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
48 |
private static final String EXPECTED2 = "--main-jar or --module"; |
57314 | 49 |
|
50 |
private static final String [] CMD1 = { |
|
58993
b5e1baa9d2c3
8233592: change --package-type option name to --type and allow -t short form
herrick
parents:
58359
diff
changeset
|
51 |
"--type", "app-image", |
57314 | 52 |
"--input", "input", |
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58114
diff
changeset
|
53 |
"--dest", OUTPUT, |
57314 | 54 |
"--name", "test", |
55 |
"--main-jar", "non-existant.jar", |
|
56 |
}; |
|
57 |
private static final String EXP1 = "main jar does not exist"; |
|
58 |
||
59 |
private static final String [] CMD2 = { |
|
58993
b5e1baa9d2c3
8233592: change --package-type option name to --type and allow -t short form
herrick
parents:
58359
diff
changeset
|
60 |
"--type", "app-image", |
57314 | 61 |
"--input", "input", |
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58114
diff
changeset
|
62 |
"--dest", OUTPUT, |
57314 | 63 |
"--name", "test", |
64 |
"--main-jar", "hello.jar", |
|
65 |
}; |
|
66 |
private static final String EXP2 = "class was not specified nor was"; |
|
67 |
||
68 |
private static void validate(String output, String expected, boolean single) |
|
69 |
throws Exception { |
|
58359
e065fd274bc1
8230649 : Make jpackage tool an experimental feature
herrick
parents:
58147
diff
changeset
|
70 |
String[] result = JPackageHelper.splitAndFilter(output); |
57314 | 71 |
if (single && result.length != 1) { |
72 |
System.err.println(output); |
|
73 |
throw new AssertionError("Unexpected multiple lines of output: " |
|
74 |
+ output); |
|
75 |
} |
|
76 |
||
77 |
if (!result[0].trim().contains(expected)) { |
|
78 |
throw new AssertionError("Unexpected output: " + result[0] |
|
79 |
+ " - expected output to contain: " + expected); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
||
84 |
public static void main(String[] args) throws Exception { |
|
85 |
JPackageHelper.createHelloImageJar(); |
|
86 |
||
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57446
diff
changeset
|
87 |
validate(JPackageHelper.executeToolProvider(false, |
58993
b5e1baa9d2c3
8233592: change --package-type option name to --type and allow -t short form
herrick
parents:
58359
diff
changeset
|
88 |
"--type", "app-image", ARG1), EXPECTED1, true); |
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58114
diff
changeset
|
89 |
validate(JPackageHelper.executeToolProvider(false, |
58993
b5e1baa9d2c3
8233592: change --package-type option name to --type and allow -t short form
herrick
parents:
58359
diff
changeset
|
90 |
"--type", "app-image", ARG2), EXPECTED2, true); |
57314 | 91 |
|
92 |
JPackageHelper.deleteOutputFolder(OUTPUT); |
|
93 |
validate(JPackageHelper.executeToolProvider(false, CMD1), EXP1, false); |
|
94 |
||
95 |
JPackageHelper.deleteOutputFolder(OUTPUT); |
|
96 |
validate(JPackageHelper.executeToolProvider(false, CMD2), EXP2, false); |
|
97 |
||
98 |
} |
|
99 |
||
100 |
} |