File: verify-common.bsh

package info (click to toggle)
kotlin 1.3.31%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 109,524 kB
  • sloc: java: 454,753; xml: 18,599; javascript: 10,452; sh: 513; python: 97; makefile: 54; ansic: 4
file content (69 lines) | stat: -rw-r--r-- 2,348 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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;
}