blob: ceb10449d21447a13a0dd20e0a786e873b4a1f63 [file] [log] [blame]
String[] getFileLines(File file) {
BufferedReader reader = new BufferedReader(new FileReader(file));
List result = new ArrayList();
String line;
while ((line = reader.readLine()) != null){
line=line.replaceAll("\\u001b[^m]*m","");
result.add(line);
}
reader.close();
return result.toArray(new String[0]);
}
String[] getBuildLogLines() {
return getFileLines(new File(basedir, "build.log"));
}
String[] buildLog = getBuildLogLines();
void assertFileContains(String relativePath, String content) {
File file = new File(basedir, relativePath);
if (!file.exists()) {
throw new Exception("File was not found: " + relativePath);
}
String[] lines = getFileLines(file);
int lineNumber = findLineThatContains(lines, content);
if (lineNumber < 0) {
throw new Exception("Expected file " + relativePath + " to contain: \"" + content + "\"");
}
}
void assertBuildLogHasLine(String expectedLine) {
for (int i = 0; i < buildLog.length; i++) {
String line = buildLog[i];
if (line.equals(expectedLine)) {
print("Expected line was found at line " + i + " of build log: " + "\"" + expectedLine + "\"");
return;
}
}
throw new Exception("Expected build log to contain line: \"" + expectedLine + "\"");
}
void assertBuildLogHasLineThatContains(String content) {
int line = findBuildLogLineThatContains(content);
if (line >= 0)
print("Expected content " + "\"" + content + "\"" + " was found at line " + (line+1) + " of build log: " + "\"" + buildLog[line] + "\"");
else
throw new Exception("Expected build log to contain: \"" + content + "\"");
}
void assertBuildLogHasNoLineThatContains(String content) {
int line = findBuildLogLineThatContains(content);
if (line >= 0)
throw new Exception("Expected build log not to contain content " + "\"" + content + "\"" + ", but was found at line " + (line+1) + ": " + "\"" + buildLog[line] + "\"");
}
int findBuildLogLineThatContains(String content) {
return findLineThatContains(buildLog, content);
}
int findLineThatContains(String[] lines, String content) {
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (line.contains(content)) {
return i;
}
}
return -1;
}