Skip to content

Commit

Permalink
ci: add silly test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
kucaahbe committed Feb 11, 2024
1 parent 89436f2 commit 1afb6b8
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 57 deletions.
4 changes: 4 additions & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ dependency "sdlite" version="~>1.2.0"
configuration "application" {
targetType "executable"
}

configuration "unittest" {
dependency "silly" version="~>1.1.1"
}
1 change: 1 addition & 0 deletions dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"fileVersion": 1,
"versions": {
"sdlite": "1.2.0",
"silly": "1.1.1",
"taggedalgebraic": "0.11.22"
}
}
28 changes: 16 additions & 12 deletions source/config_parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ unittest
import std.exception;
import std.regex;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto config = Config();
auto configFilePath = ".test/app/install.sdl";
auto configFilePath = testDir ~ "/app/install.sdl";
auto configFileContent = q"CFG
install {
# parse error here:
Expand All @@ -117,13 +118,14 @@ unittest
{
import std.file;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

immutable auto cwd = getcwd();
auto config = Config();
auto configFilePath = ".test/app/install.sdl";
auto configFilePath = testDir ~ "/app/install.sdl";
auto configFileContent = q"CFG
install {
ln `a` `b`
Expand All @@ -142,12 +144,13 @@ unittest
{
import std.file;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto config = Config();
auto configFilePath = ".test/app/install.sdl";
auto configFilePath = testDir ~ "/app/install.sdl";
auto configFileContent = q"CFG
install {
ln "too" "many" "params"
Expand Down Expand Up @@ -187,12 +190,13 @@ unittest
import std.exception;
import std.regex;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto config = Config();
auto path = Path(".test/app/install.sdl");
auto path = Path(testDir ~ "/app/install.sdl");
ubyte[] not_utf_data = [207, 250, 237];
TestFile(path.absolute, not_utf_data).create;

Expand Down
21 changes: 12 additions & 9 deletions source/path.d
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ struct Path
import std.file;
import std.process;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

immutable auto file_path = ".test/app/source";
immutable auto file_path = testDir ~ "/app/source";

const auto path = Path(file_path);
assert(!path.exists);
Expand Down Expand Up @@ -99,11 +100,12 @@ struct Path
import std.file;
import std.process;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

immutable auto dir_path = ".test/app";
immutable auto dir_path = testDir ~ "/app";

const auto path = Path(dir_path);
assert(!path.isDir);
Expand All @@ -125,11 +127,12 @@ struct Path
import std.file;
import std.process;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

immutable auto dir_path = ".test/app";
immutable auto dir_path = testDir ~ "/app";

const auto path = Path(dir_path);
assert(!path.isSymlink);
Expand Down
83 changes: 47 additions & 36 deletions source/symlink.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ struct Symlink {
unittest
{
import std.file;
import test_dir;

immutable auto srcPath = ".test/app/source";
immutable auto destPath = ".test/home/destination";
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

immutable auto srcPath = testDir ~ "/app/source";
immutable auto destPath = testDir ~ "/home/destination";
immutable auto cwd = getcwd();

const auto link = Symlink(srcPath, destPath);
Expand All @@ -56,12 +60,13 @@ struct Symlink {
{
import std.file;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto srcPath = ".test/app/source";
auto destPath = ".test/home/destination";
auto srcPath = testDir ~ "/app/source";
auto destPath = testDir ~ "/home/destination";
TestFile(srcPath, "content").create;
TestFile(destPath).create;

Expand Down Expand Up @@ -105,12 +110,13 @@ struct Symlink {
import std.file;
import std.path;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto srcPath = ".test/app/source";
auto destPath = ".test/home/destination";
auto srcPath = testDir ~ "/app/source";
auto destPath = testDir ~ "/home/destination";

TestFile(srcPath, "content").create;
TestFile(destPath).create;
Expand All @@ -131,12 +137,13 @@ struct Symlink {
import std.path;
import std.regex;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto srcPath = ".test/app/source";
auto destPath = ".test/home/destination";
auto srcPath = testDir ~ "/app/source";
auto destPath = testDir ~ "/home/destination";
immutable auto cwd = getcwd();

TestFile(srcPath, "src content").create;
Expand All @@ -161,25 +168,26 @@ struct Symlink {
{
import std.file;
import std.path;
import test_file;
import std.exception: collectExceptionMsg;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

immutable auto cwd = getcwd();
auto srcPath = ".test/app/source";
auto destPath = ".test/home/destination";
auto srcPath = testDir ~ "/app/source";
auto destPath = testDir ~ "/home/destination";

TestFile(srcPath, "content").create;
// only create .test/
// only create testDir ~ "/home"
TestFile(destPath.dirName).create;
assert(destPath.dirName.dirName.isDir);

auto link = Symlink(srcPath, destPath);

immutable auto exceptionMsg = collectExceptionMsg!FileException(link.link);
immutable auto expectedExceptionMsg = cwd ~ "/.test/home" ~ ": directory does not exist";
immutable auto expectedExceptionMsg = cwd ~ '/' ~ testDir ~ "/home" ~ ": directory does not exist";

assert(exceptionMsg == expectedExceptionMsg, exceptionMsg ~ " != " ~ expectedExceptionMsg);
}
Expand All @@ -191,14 +199,15 @@ struct Symlink {
{
import std.file;
import std.path;
import test_file;
import std.exception: collectExceptionMsg;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto srcPath = ".test/app/source";
auto destPath = ".test/home/destination";
auto srcPath = testDir ~ "/app/source";
auto destPath = testDir ~ "/home/destination";
immutable auto cwd = getcwd();

TestFile(srcPath, "src content").create;
Expand All @@ -220,14 +229,15 @@ struct Symlink {
{
import std.file;
import std.path;
import test_file;
import std.exception: collectExceptionMsg;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto srcPath = ".test/app/source";
auto destPath = ".test/home/destination";
auto srcPath = testDir ~ "/app/source";
auto destPath = testDir ~ "/home/destination";
immutable auto cwd = getcwd();

TestFile(destPath).create;
Expand All @@ -236,7 +246,7 @@ struct Symlink {
auto link = Symlink(srcPath, destPath);

immutable auto exceptionMsg = collectExceptionMsg!FileException(link.link);
immutable auto expectedExceptionMsg = cwd ~ "/.test/app/source" ~ ": file or directory does not exist";
immutable auto expectedExceptionMsg = cwd ~ '/' ~ testDir ~ "/app/source" ~ ": file or directory does not exist";

assert(exceptionMsg == expectedExceptionMsg, exceptionMsg ~ " != " ~ expectedExceptionMsg);
}
Expand All @@ -257,12 +267,13 @@ struct Symlink {
import std.file;
import std.path;
import test_file;
import test_dir;

if (".test".exists) ".test".rmdirRecurse;
scope(exit) if (".test".exists) ".test".rmdirRecurse;
auto testDir = setupTestDir(__FILE__, __LINE__);
scope(exit) removeTestDir(testDir);

auto srcPath = ".test/app/source";
auto destPath = ".test/home/destination";
auto srcPath = testDir ~ "/app/source";
auto destPath = testDir ~ "/home/destination";
immutable auto cwd = getcwd();

TestFile(srcPath, "src content").create;
Expand Down
21 changes: 21 additions & 0 deletions source/test_dir.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version(unittest)
{
import std.file;
import std.path;
import std.string;
import std.conv;

string setupTestDir(string filename, uint line)
{
auto dir = ".test_" ~ filename.replace('/', '_') ~ "_" ~ to!string(line);

if (dir.exists) dir.rmdirRecurse;

return dir;
}

void removeTestDir(string dir)
{
if (dir.exists) dir.rmdirRecurse;
}
}

0 comments on commit 1afb6b8

Please sign in to comment.