Skip to content

Commit

Permalink
add test for Quark hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
capital-G authored and telephon committed Dec 23, 2022
1 parent e653b40 commit 8740269
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
64 changes: 64 additions & 0 deletions testsuite/classlibrary/TestQuark.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
TestQuark : UnitTest {
*testQuarkPath {
^PathName(thisMethod.filenameSymbol.asString).pathOnly +/+ "assets" +/+ "TestQuark";
}

*tempDir {
^Platform.defaultTempDir +/+ 'testTempDir' +/+ 'testQuark';
}

*clearTempDir {
File.delete(TestQuark.tempDir);
}

*hookNames {
^[
\preInstall,
\postInstall,
\preUpdate,
\postUpdate,
\preUninstall,
\postUninstall,
];
}

test_parseQuarkFileHooksAsFunction {
var quark = Quark.fromLocalPath(TestQuark.testQuarkPath);
TestQuark.hookNames.do({|hookName|
this.assert(
quark.data[hookName].class == Function,
"Hook '%' should be parsed as function".format(hookName),
);
});
}

test_runQuarkInstallHooks {
TestQuark.clearTempDir;
// as the quark to be installed is empty we can not update or
// uninstall it.
// Making it non empty does not fix this as it is already
// in a subdir of the testsuite, therefore every class file
// will be already available and a proper Quark install
// is omitted.
Quarks.install(TestQuark.testQuarkPath);
[\preInstall, \postInstall].do({|hookName|
this.assert(
File.exists(TestQuark.tempDir +/+ hookName),
"Check if hook '%' was called".format(hookName);
);
});
TestQuark.clearTempDir;
}

test_parseQuarkFileData {
var quark = Quark.fromLocalPath(TestQuark.testQuarkPath);
this.assert(
quark.data[\name] == "DemonWidgets",
"Quark name should be parsed from quark file",
);
this.assert(
quark.data[\version] == "1.0.0",
"Quark version should be parsed from quark file"
);
}
}
15 changes: 15 additions & 0 deletions testsuite/classlibrary/assets/TestQuark/TestQuark.quark
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(
name: "DemonWidgets",
summary: "Widgets, gadgets and arcane devices for summoning demons.",
version: "1.0.0",
schelp: "DemonWidgets",
dependencies: [],
license: "GPL",
copyright: "Frank Furter, Dr.-Ing. 2015",
preInstall: {File.new(Platform.defaultTempDir +/+ 'testTempDir' +/+ 'testQuark' +/+ 'preInstall', "w").close},
postInstall: {File.new(Platform.defaultTempDir +/+ 'testTempDir' +/+ 'testQuark' +/+ 'postInstall', "w").close},
preUpdate: {File.new(Platform.defaultTempDir +/+ 'testTempDir' +/+ 'testQuark' +/+ 'preUpdate', "w").close},
postUpdate: {File.new(Platform.defaultTempDir +/+ 'testTempDir' +/+ 'testQuark' +/+ 'postUpdate', "w").close},
preUninstall: {File.new(Platform.defaultTempDir +/+ 'testTempDir' +/+ 'testQuark' +/+ 'preUninstall', "w").close},
postUninstall: {File.new(Platform.defaultTempDir +/+ 'testTempDir' +/+ 'testQuark' +/+ 'postUninstall', "w").close},
)

0 comments on commit 8740269

Please sign in to comment.