diff options
author | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-06-02 16:32:26 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-06-02 14:58:40 +0000 |
commit | a90ad9128c188dc590ef5586b6f0d7f8a32b4c4f (patch) | |
tree | 231d064f9d5c8ebc80d777e2c64a293ab69987b5 | |
parent | e7fb9493051ca111a12380e3040f3a914e61ccfb (diff) |
Refactor the JSExtensions tests.
Use a proper Transformer instead of putting all the code in the "type"
property.
Change-Id: I6d74a749dc701e96ed9ff56a977eedc48d3fbb57
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-file/file.qbs | 43 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs | 42 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-process/process.qbs | 55 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-propertylist/propertylist.qbs (renamed from tests/auto/blackbox/testdata/jsextensions/propertylist.qbs) | 0 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-textfile/textfile.qbs | 35 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions/file.qbs | 28 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions/fileinfo.qbs | 30 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions/process.qbs | 42 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions/textfile.qbs | 24 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 18 |
10 files changed, 184 insertions, 133 deletions
diff --git a/tests/auto/blackbox/testdata/jsextensions-file/file.qbs b/tests/auto/blackbox/testdata/jsextensions-file/file.qbs new file mode 100644 index 000000000..83a5bfae5 --- /dev/null +++ b/tests/auto/blackbox/testdata/jsextensions-file/file.qbs @@ -0,0 +1,43 @@ +import qbs +import qbs.File +import qbs.FileInfo +import qbs.TextFile + +Product { + type: ["dummy"] + Transformer { + Artifact { + filePath: "dummy.txt" + fileTags: ["dummy"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.silent = true; + cmd.sourceCode = function() { + var origPath = FileInfo.joinPaths(product.sourceDirectory, "original.txt"); + var copyPath = FileInfo.joinPaths(product.sourceDirectory, "copy.txt"); + print("copy path: "+copyPath); + var original = new TextFile(origPath, TextFile.WriteOnly); + original.close(); + File.copy(origPath, copyPath); + var origTimestamp = File.lastModified(origPath); + var copyTimestamp = File.lastModified(copyPath); + if (origTimestamp > copyTimestamp) + throw new Error("Older file has newer timestamp."); + File.remove(origPath); + var copy = new TextFile(copyPath, TextFile.WriteOnly); + copy.writeLine(File.exists(origPath)); + copy.writeLine(File.exists(copyPath)); + copy.close(); + var zePath = FileInfo.joinPaths(product.sourceDirectory, "zePath"); + if (File.exists(zePath)) + throw new Error(zePath + " already exists."); + var created = File.makePath(zePath); + if (!created || !File.exists(zePath)) + throw new Error("zePath was not created."); + + }; + return [cmd]; + } + } +} diff --git a/tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs b/tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs new file mode 100644 index 000000000..c063c12aa --- /dev/null +++ b/tests/auto/blackbox/testdata/jsextensions-fileinfo/fileinfo.qbs @@ -0,0 +1,42 @@ +import qbs +import qbs.FileInfo +import qbs.TextFile + +Product { + type: ["dummy"] + Transformer { + Artifact { + filePath: "dummy.txt" + fileTags: ["dummy"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.silent = true; + cmd.sourceCode = function() { + var output = new TextFile(FileInfo.joinPaths(product.sourceDirectory, "output.txt"), + TextFile.WriteOnly); + output.writeLine(FileInfo.baseName("/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.completeBaseName("/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.fileName("/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.fromWindowsSeparators("/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.fromWindowsSeparators("c:\\tmp\\blubb.tar.gz")); + output.writeLine(FileInfo.isAbsolutePath("/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.isAbsolutePath("c:\\tmp\\blubb.tar.gz")); + output.writeLine(FileInfo.isAbsolutePath("blubb.tar.gz")); + output.writeLine(FileInfo.isAbsolutePath("../blubb.tar.gz")); + output.writeLine(FileInfo.joinPaths("/", "tmp", "blubb.tar.gz")); + output.writeLine(FileInfo.path("/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.path("/tmp/")); + output.writeLine(FileInfo.path("/")); + output.writeLine(FileInfo.path("d:/")); + output.writeLine(FileInfo.relativePath("/tmp", "/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.relativePath("/", "/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.relativePath("/tmp", "/blubb.tar.gz")); + output.writeLine(FileInfo.toWindowsSeparators("/tmp/blubb.tar.gz")); + output.writeLine(FileInfo.toWindowsSeparators("c:\\tmp\\blubb.tar.gz")); + output.close(); + }; + return [cmd]; + } + } +} diff --git a/tests/auto/blackbox/testdata/jsextensions-process/process.qbs b/tests/auto/blackbox/testdata/jsextensions-process/process.qbs new file mode 100644 index 000000000..ff8fb96f1 --- /dev/null +++ b/tests/auto/blackbox/testdata/jsextensions-process/process.qbs @@ -0,0 +1,55 @@ +import qbs +import qbs.FileInfo +import qbs.Process +import qbs.TextFile + +Project { + property path qbsFilePath + Product { + Depends { name: "Qt.core" } + type: ["dummy"] + Transformer { + Artifact { + filePath: "dummy.txt" + fileTags: ["dummy"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.silent = true; + cmd.sourceCode = function() { + // Synchronous run, successful. + var process = new Process(); + process.setEnv("PATH", [qbs.getEnv("PATH"), + product.moduleProperty("Qt.core", "binPath")] + .join(qbs.pathListSeparator)); + process.exec(project.qbsFilePath, ["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("PATH", [qbs.getEnv("PATH"), + product.moduleProperty("Qt.core", "binPath")] + .join(qbs.pathListSeparator)); + output.writeLine(process.start(project.qbsFilePath, ["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(); + + // TODO: Test all the other Process methods as well. + + output.close(); + }; + return [cmd]; + } + } + } +} diff --git a/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs b/tests/auto/blackbox/testdata/jsextensions-propertylist/propertylist.qbs index a2898f69f..a2898f69f 100644 --- a/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs +++ b/tests/auto/blackbox/testdata/jsextensions-propertylist/propertylist.qbs diff --git a/tests/auto/blackbox/testdata/jsextensions-textfile/textfile.qbs b/tests/auto/blackbox/testdata/jsextensions-textfile/textfile.qbs new file mode 100644 index 000000000..6f24d19eb --- /dev/null +++ b/tests/auto/blackbox/testdata/jsextensions-textfile/textfile.qbs @@ -0,0 +1,35 @@ +import qbs +import qbs.TextFile + +Product { + type: ["dummy"] + Transformer { + Artifact { + filePath: "dummy.txt" + fileTags: ["dummy"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.silent = true; + cmd.sourceCode = function() { + var file1 = new TextFile("file1.txt", TextFile.WriteOnly); + file1.write("First line.\nSecond line.\nThird line."); + file1.close(); + file1 = new TextFile("file1.txt", TextFile.ReadWrite); + var file2 = new TextFile("file2.txt", TextFile.WriteOnly); + file2.writeLine(file1.atEof()); + while (true) { + var line = file1.readLine(); + if (!line || line.length == 0) + break; + file2.writeLine(line); + } + file1.truncate(); + file2.writeLine(file1.atEof()); + file1.close(); + file2.close(); + }; + return [cmd]; + } + } +} diff --git a/tests/auto/blackbox/testdata/jsextensions/file.qbs b/tests/auto/blackbox/testdata/jsextensions/file.qbs deleted file mode 100644 index 28e138bfd..000000000 --- a/tests/auto/blackbox/testdata/jsextensions/file.qbs +++ /dev/null @@ -1,28 +0,0 @@ -import qbs -import qbs.File -import qbs.FileInfo -import qbs.TextFile - -Product { - type: { - var original = new TextFile("original.txt", TextFile.WriteOnly); - original.close(); - File.copy("original.txt", "copy.txt"); - var origTimestamp = File.lastModified("original.txt"); - var copyTimestamp = File.lastModified("copy.txt"); - if (origTimestamp > copyTimestamp) - throw new Error("Older file has newer timestamp."); - File.remove("original.txt"); - var copy = new TextFile("copy.txt", TextFile.WriteOnly); - copy.writeLine(File.exists("original.txt")); - copy.writeLine(File.exists("copy.txt")); - copy.close(); - var zePath = FileInfo.joinPaths(path, "zePath"); - if (File.exists(zePath)) - throw new Error("zePath already exists."); - var created = File.makePath(zePath); - if (!created || !File.exists(zePath)) - throw new Error("zePath was not created."); - return "palim-palim"; - } -} diff --git a/tests/auto/blackbox/testdata/jsextensions/fileinfo.qbs b/tests/auto/blackbox/testdata/jsextensions/fileinfo.qbs deleted file mode 100644 index 3a47450e6..000000000 --- a/tests/auto/blackbox/testdata/jsextensions/fileinfo.qbs +++ /dev/null @@ -1,30 +0,0 @@ -import qbs -import qbs.FileInfo -import qbs.TextFile - -Product { - type: { - var output = new TextFile("output.txt", TextFile.WriteOnly); - output.writeLine(FileInfo.baseName("/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.completeBaseName("/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.fileName("/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.fromWindowsSeparators("/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.fromWindowsSeparators("c:\\tmp\\blubb.tar.gz")); - output.writeLine(FileInfo.isAbsolutePath("/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.isAbsolutePath("c:\\tmp\\blubb.tar.gz")); - output.writeLine(FileInfo.isAbsolutePath("blubb.tar.gz")); - output.writeLine(FileInfo.isAbsolutePath("../blubb.tar.gz")); - output.writeLine(FileInfo.joinPaths("/", "tmp", "blubb.tar.gz")); - output.writeLine(FileInfo.path("/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.path("/tmp/")); - output.writeLine(FileInfo.path("/")); - output.writeLine(FileInfo.path("d:/")); - output.writeLine(FileInfo.relativePath("/tmp", "/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.relativePath("/", "/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.relativePath("/tmp", "/blubb.tar.gz")); - output.writeLine(FileInfo.toWindowsSeparators("/tmp/blubb.tar.gz")); - output.writeLine(FileInfo.toWindowsSeparators("c:\\tmp\\blubb.tar.gz")); - output.close(); - return "wattweeßick"; - } -} diff --git a/tests/auto/blackbox/testdata/jsextensions/process.qbs b/tests/auto/blackbox/testdata/jsextensions/process.qbs deleted file mode 100644 index b811f4446..000000000 --- a/tests/auto/blackbox/testdata/jsextensions/process.qbs +++ /dev/null @@ -1,42 +0,0 @@ -import qbs -import qbs.FileInfo -import qbs.Process -import qbs.TextFile - -Project { - property path qbsFilePath - Product { - Depends { name: "Qt.core" } - type: { - // Synchronous run, successful. - var process = new Process(); - process.setEnv("PATH", [qbs.getEnv("PATH"), - Qt.core.binPath].join(qbs.pathListSeparator)); - process.exec(qbsFilePath, ["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("PATH", [qbs.getEnv("PATH"), - Qt.core.binPath].join(qbs.pathListSeparator)); - output.writeLine(process.start(qbsFilePath, ["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(); - - // TODO: Test all the other Process methods as well. - - output.close(); - return "My hovercraft is full of eels."; - } - } -} diff --git a/tests/auto/blackbox/testdata/jsextensions/textfile.qbs b/tests/auto/blackbox/testdata/jsextensions/textfile.qbs deleted file mode 100644 index 7756df6d6..000000000 --- a/tests/auto/blackbox/testdata/jsextensions/textfile.qbs +++ /dev/null @@ -1,24 +0,0 @@ -import qbs -import qbs.TextFile - -Product { - type: { - var file1 = new TextFile("file1.txt", TextFile.WriteOnly); - file1.write("First line.\nSecond line.\nThird line."); - file1.close(); - file1 = new TextFile("file1.txt", TextFile.ReadWrite); - var file2 = new TextFile("file2.txt", TextFile.WriteOnly); - file2.writeLine(file1.atEof()); - while (true) { - var line = file1.readLine(); - if (!line || line.length == 0) - break; - file2.writeLine(line); - } - file1.truncate(); - file2.writeLine(file1.atEof()); - file1.close(); - file2.close(); - return "Banana Joe"; - } -} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index d55d36815..110b51ec5 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -1524,8 +1524,8 @@ void TestBlackbox::java() void TestBlackbox::jsExtensionsFile() { - QDir::setCurrent(testDataDir + "/jsextensions"); - QbsRunParameters params(QStringList() << "-nf" << "file.qbs"); + QDir::setCurrent(testDataDir + "/jsextensions-file"); + QbsRunParameters params(QStringList() << "-f" << "file.qbs"); QCOMPARE(runQbs(params), 0); QVERIFY(!QFileInfo("original.txt").exists()); QFile copy("copy.txt"); @@ -1539,8 +1539,8 @@ void TestBlackbox::jsExtensionsFile() void TestBlackbox::jsExtensionsFileInfo() { - QDir::setCurrent(testDataDir + "/jsextensions"); - QbsRunParameters params(QStringList() << "-nf" << "fileinfo.qbs"); + QDir::setCurrent(testDataDir + "/jsextensions-fileinfo"); + QbsRunParameters params(QStringList() << "-f" << "fileinfo.qbs"); QCOMPARE(runQbs(params), 0); QFile output("output.txt"); QVERIFY(output.exists()); @@ -1570,8 +1570,8 @@ void TestBlackbox::jsExtensionsFileInfo() void TestBlackbox::jsExtensionsProcess() { - QDir::setCurrent(testDataDir + "/jsextensions"); - QbsRunParameters params(QStringList() << "-nf" << "process.qbs" << "project.qbsFilePath:" + QDir::setCurrent(testDataDir + "/jsextensions-process"); + QbsRunParameters params(QStringList() << "-f" << "process.qbs" << "project.qbsFilePath:" + qbsExecutableFilePath); QCOMPARE(runQbs(params), 0); QFile output("output.txt"); @@ -1593,7 +1593,7 @@ void TestBlackbox::jsExtensionsPropertyList() if (!HostOsInfo::isOsxHost()) QSKIP("temporarily only applies on OS X"); - QDir::setCurrent(testDataDir + "/jsextensions"); + QDir::setCurrent(testDataDir + "/jsextensions-propertylist"); QbsRunParameters params(QStringList() << "-nf" << "propertylist.qbs"); QCOMPARE(runQbs(params), 0); QFile file1("test.json"); @@ -1624,8 +1624,8 @@ void TestBlackbox::jsExtensionsPropertyList() void TestBlackbox::jsExtensionsTextFile() { - QDir::setCurrent(testDataDir + "/jsextensions"); - QbsRunParameters params(QStringList() << "-nf" << "textfile.qbs"); + QDir::setCurrent(testDataDir + "/jsextensions-textfile"); + QbsRunParameters params(QStringList() << "-f" << "textfile.qbs"); QCOMPARE(runQbs(params), 0); QFile file1("file1.txt"); QVERIFY(file1.exists()); |