Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdline_options_tester/src/SaveOutput.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2004, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
/**
24
* Saveoutput matches and stores desired output from test suite in a variable
25
*
26
* Example:
27
* <saveoutput regex="no" type="success" saveName="moduleAddr" splitIndex="1" splitBy="!j9module ">!j9module 0x</saveoutput>
28
* This matches output containing "!j9module 0x" and split the line by "!j9module " then take the second substring (Indexed "1").
29
*/
30
class SaveOutput extends Output {
31
private String _saveName;
32
private String _splitIndex;
33
private String _splitBy;
34
35
/**
36
* Pass the arguments to local variables.
37
* @param saveName Name of the variable the output is put into
38
* @param splitIndex Index of the substring after split
39
* @param splitBy The string that the matching line is split by
40
*/
41
public SaveOutput( String matchRegex, String matchJavaUtilPattern, String showRegexMatch, String matchCase, String type, String saveName, String splitIndex, String splitBy ) {
42
super(matchRegex, matchJavaUtilPattern, showRegexMatch, matchCase, type);
43
_saveName = saveName;
44
_splitIndex = splitIndex;
45
_splitBy = splitBy;
46
}
47
48
@Override
49
boolean match( Object o ) {
50
boolean result = super.match(o);
51
if (result && (getType() == TestCondition.REQUIRED || getType() == TestCondition.SUCCESS)) {
52
String line = (String) o;
53
if (_splitBy == null || _splitBy.equals("")) {
54
System.err.println("String split failure: splitBy cannot be empty");
55
result = false;
56
} else if (!line.contains(_splitBy)) {
57
System.err.printf(
58
"String split failure: String does not contain splitBy %n" + "String: %s%n" + "splitBy: %s%n",
59
line, _splitBy);
60
result = false;
61
} else {
62
String[] splitArray = line.split(_splitBy);
63
int arraySize = splitArray.length;
64
try {
65
int splitIndexInt = Integer.parseInt(_splitIndex);
66
if (splitIndexInt >= arraySize || splitIndexInt < 0) {
67
System.err.printf("String split failure: splitIndex out of bound %n"
68
+ "Size of splitArray: %s%n" + "splitIndex: %d%n", arraySize, splitIndexInt);
69
result = false;
70
} else {
71
TestSuite.putVariable(_saveName, splitArray[splitIndexInt]);
72
}
73
} catch (NumberFormatException e) {
74
System.err.println("String split failure: splitIndex is not a number");
75
result = false;
76
}
77
}
78
}
79
return result;
80
}
81
82
}
83
84
85