File: GenCompileTests.java

package info (click to toggle)
jtreg 5.1-b01-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 5,432 kB
  • sloc: java: 29,218; xml: 729; sh: 665; makefile: 245
file content (61 lines) | stat: -rw-r--r-- 2,104 bytes parent folder | download | duplicates (10)
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

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class GenCompileTests {
    public static void main(String... args) throws IOException {
        GenCompileTests g = new GenCompileTests();
        g.run(new File(args[0]), Integer.parseInt(args[1]));
    }

    void run(File dir, int count) throws IOException {
        writeFile(dir, "TEST.ROOT", "TestNG.dirs=testng");
        genBuildTests(new File(dir, "build"), count);
        genCompileTests(new File(dir, "compile"), count);
        genTestNGTests(new File(dir, "testng"), count);
    }

    void genBuildTests(File dir, int count) throws IOException {
        StringBuilder sb = new StringBuilder();
        sb.append("/* @test\n");
        sb.append(" * @build");
        for (int i = 0; i < count; i++) {
            writeFile(dir, "C" + i + ".java", "class C" + i + " { }");
            sb.append(" C").append(i);
        }
        sb.append("\n"
                + "@run main C"
                + "*/\n"
                + "public class C { public static void main(String... args) { } }");
        writeFile(dir, "C.java", sb.toString());
    }

    void genCompileTests(File dir, int count) throws IOException {
        StringBuilder sb = new StringBuilder();
        sb.append("/* @test\n");
        sb.append(" * @compile");
        for (int i = 0; i < count; i++) {
            writeFile(dir, "C" + i + ".java", "class C" + i + " { }");
            sb.append(" C").append(i).append(".java");
        }
        sb.append("\n"
                + "*/\n");
        writeFile(dir, "C.java", sb.toString());
    }

    void genTestNGTests(File dir, int count) throws IOException {
        for (int i = 0; i < count; i++) {
            writeFile(dir, "C" + i + ".java",
                    "import org.testng.annotations.*;\n"
                    + "@Test class C" + i + " { }");
        }
    }

    void writeFile(File dir, String name, String body) throws IOException {
        dir.mkdirs();
        FileWriter out = new FileWriter(new File(dir, name));
        out.write(body);
        out.close();
    }
}