diff options
| author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2026-02-03 14:59:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-03 14:59:53 -0500 |
| commit | add95b14f74e6dbe04a6efe98ff0f20424930b73 (patch) | |
| tree | 13ce413ee4190a4c8f8743c7740aaa8d04353f14 /willow/unittest | |
| parent | c5b2905c5a64433f8519531a77d3acc42d881f17 (diff) | |
| download | compiler-add95b14f74e6dbe04a6efe98ff0f20424930b73.tar.gz | |
[willow]: initial frontend work, unit tests (#8)dev/stefan
Diffstat (limited to 'willow/unittest')
| -rw-r--r-- | willow/unittest/BUILD.bazel | 6 | ||||
| -rw-r--r-- | willow/unittest/ir/BUILD.bazel | 16 | ||||
| -rw-r--r-- | willow/unittest/ir/VerifierTest.cpp | 51 | ||||
| -rw-r--r-- | willow/unittest/willow_unittest.bzl | 8 |
4 files changed, 81 insertions, 0 deletions
diff --git a/willow/unittest/BUILD.bazel b/willow/unittest/BUILD.bazel new file mode 100644 index 0000000..8f1c55d --- /dev/null +++ b/willow/unittest/BUILD.bazel @@ -0,0 +1,6 @@ +test_suite( + name = "unittest", + tests = [ + "//willow/unittest/ir:ir_tests", + ] +) diff --git a/willow/unittest/ir/BUILD.bazel b/willow/unittest/ir/BUILD.bazel new file mode 100644 index 0000000..b41dfcd --- /dev/null +++ b/willow/unittest/ir/BUILD.bazel @@ -0,0 +1,16 @@ +cc_test( + name = "verifier", + srcs = ["VerifierTest.cpp"], + deps = [ + "//willow", + "@catch2//:catch2_main" + ], + tags = ["ir"] +) + +test_suite( + name = "ir_tests", + tests = [ + ":verifier" + ], +) diff --git a/willow/unittest/ir/VerifierTest.cpp b/willow/unittest/ir/VerifierTest.cpp new file mode 100644 index 0000000..959d72a --- /dev/null +++ b/willow/unittest/ir/VerifierTest.cpp @@ -0,0 +1,51 @@ +#include <catch2/catch_test_macros.hpp> + +#include <willow/IR/Context.h> +#include <willow/IR/Module.h> +#include <willow/IR/Verifier.h> +#include <willow/IR/Diagnostic.h> +#include <willow/IR/DiagnosticEngine.h> +#include <willow/IR/Function.h> + +using namespace willow; + +TEST_CASE("valid modules", "[verifier]") { + WillowContext ctx; + std::vector<Diagnostic> diags; + DiagnosticEngine eng( + [&](Diagnostic d) { diags.push_back(std::move(d)); }); + + auto &m = *ctx.addModule("test"); + SECTION("empty module") { + REQUIRE(succeeded(verifyModule(ctx, m, eng))); + REQUIRE(diags.empty()); + } +} + +TEST_CASE("valid function", "[verifier]") { + WillowContext ctx; + std::vector<Diagnostic> diags; + DiagnosticEngine eng( + [&](Diagnostic d) { diags.push_back(std::move(d)); }); + + auto &m = *ctx.addModule("test"); + + Type fty = ctx.types().FunctionType(ctx.types().VoidType(), {}); + auto &fn = *m.emplaceFunction("fn", &m, fty); + + REQUIRE(succeeded(verifyFunction(ctx, fn, eng))); + REQUIRE(diags.empty()); +} + +TEST_CASE("invalid basic block", "[verifier]") { + WillowContext ctx; + std::vector<Diagnostic> diags; + DiagnosticEngine eng( + [&](Diagnostic d) { diags.push_back(std::move(d)); }); + + auto &m = *ctx.addModule("test"); + + Type fty = ctx.types().FunctionType(ctx.types().VoidType(), {}); + auto &fn = *m.emplaceFunction("fn", &m, fty); + // TODO +} diff --git a/willow/unittest/willow_unittest.bzl b/willow/unittest/willow_unittest.bzl new file mode 100644 index 0000000..f1bb102 --- /dev/null +++ b/willow/unittest/willow_unittest.bzl @@ -0,0 +1,8 @@ +def willow_unittest(name, srcs, deps = [], tags = [], **kwargs): + native.cc_test( + name = name, + srcs = srcs, + deps = deps + ["@catch2//:catch2_main"], + tags = tags, + **kwargs + ) |