aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/blackbox/testdata/jsextensions-process/process.qbs
blob: dc8c8c66996b46bc09fc8ba91502b6f351ae7871 (plain)
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
70
71
72
73
74
import qbs
import qbs.FileInfo
import qbs.Process
import qbs.TextFile

Project {
    Product {
        Depends { name: "cpp" }
        type: ["dummy"]
        name: "dummy"
        files: ["main.cpp"]
        Rule {
            multiplex: true
            inputs: ["application"]
            Artifact {
                filePath: "dummy.txt"
                fileTags: ["dummy"]
            }
            prepare: {
                var cmd = new JavaScriptCommand();
                cmd.silent = true;
                cmd.sourceCode = function() {
                    var exeFilePath = FileInfo.joinPaths(product.buildDirectory,
                                                         product.cpp.executablePrefix
                                                         + "dummy"
                                                         + product.cpp.executableSuffix);

                    // Synchronous run, successful.
                    var process = new Process();
                    var pathVal = "why, hello!";
                    process.setEnv("SOME_ENV", pathVal);
                    process.exec(exeFilePath, ["help"], true);
                    var output = new TextFile("output.txt", TextFile.WriteOnly);
                    output.writeLine(process.exitCode());
                    output.writeLine(process.readLine());
                    process.close();

                    // Asynchronous run, successful.
                    process = new Process();
                    process.setEnv("SOME_ENV", pathVal);
                    output.writeLine(process.start(exeFilePath, ["help"]));
                    output.writeLine(process.waitForFinished());
                    output.writeLine(process.exitCode());
                    output.writeLine(process.readLine());
                    process.close();

                    // Asynchronous run, unsuccessful.
                    process = new Process();
                    output.writeLine(process.start("blubb", []));
                    process.close();

                    // closeWriteChannel test
                    process = new Process();
                    if (product.qbs.hostOS.contains("windows"))
                        process.start("cmd", ["/C", "c:\\windows\\system32\\sort.exe"]);
                    else
                        process.start("cat", []);
                    process.writeLine("should be");
                    process.closeWriteChannel();
                    process.writeLine("should not be");
                    if (!process.waitForFinished())
                        process.kill();
                    output.write(process.readStdOut());
                    process.close();

                    // TODO: Test all the other Process methods as well.

                    output.close();
                };
                return [cmd];
            }
        }
    }
}