Skip to content

Commit 8bc3ea2

Browse files
authored
[IN] Support for mocking interfaces (#1)
1 parent ea06e26 commit 8bc3ea2

10 files changed

Lines changed: 891 additions & 15 deletions

File tree

.github/workflows/unit_tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: oop.zig Unit Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
execute_unit_tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
submodules: 'recursive'
16+
- name: Execute tests
17+
shell: bash
18+
run: |
19+
curl https://raw.githubusercontent.com/tristanisham/zvm/master/install.sh | bash
20+
export PATH="$HOME/.zvm/bin:$HOME/.zvm/self:$PATH"
21+
./install_zig_with_zvm.sh
22+
zig build test --summary all

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug Tests",
9+
"type": "lldb",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/zig-out/bin/test",
12+
"cwd": "${workspaceRoot}",
13+
}
14+
]
15+
}

build.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn build(b: *std.Build) !void {
2020

2121
const exe_tests = b.addTest(.{
2222
.root_module = mod_tests,
23+
.use_llvm = true,
2324
});
2425
exe_tests.root_module.addImport("interface", mod);
2526

@@ -28,6 +29,8 @@ pub fn build(b: *std.Build) !void {
2829
const test_step = b.step("test", "Run tests");
2930
test_step.dependOn(&run_exe_tests.step);
3031

32+
b.installArtifact(exe_tests);
33+
3134
if (enable_examples) {
3235
var iterable_dir = try std.fs.cwd().openDir("examples", .{ .iterate = true });
3336
defer iterable_dir.close();

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name = .oop_zig,
33
.version = "0.0.1",
44
.fingerprint = 0x4d0368551b1ab249, // Changing this has security and trust implications.
5-
.minimum_zig_version = "0.16.0-dev.233+a0ec4e270",
5+
.minimum_zig_version = "0.15.2",
66
.dependencies = .{},
77
.paths = .{
88
"build.zig",

install_zig_with_zvm.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
version=$(awk -F'"' '/\.minimum_zig_version/ { print $2 }' build.zig.zon)
4+
echo "Installing Zig version $version using zvm..."
5+
6+
zvm install $version
7+
zvm use $version

src/interface.zig

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,6 @@ pub fn DeriveFromBase(comptime BaseType: anytype, comptime Derived: type) type {
298298
if (!@hasField(Derived, "base") or !(@FieldType(Derived, "base") == BaseType)) {
299299
@compileError("Deriving from a base instead of an interface requires a 'base' field in the derived type.");
300300
}
301-
// // disallow fields override
302-
// var base: ?type = BaseType;
303-
// while (base != null) {
304-
// for (std.meta.fields(Derived)) |field| {
305-
// if (@hasField(base.?, field.name) and !std.mem.eql(u8, field.name, "base")) {
306-
// @compileError("Field already exists in the base: " ++ field.name);
307-
// }
308-
// }
309-
// base = base.?.Base;
310-
// }
311301
};
312302

313303
return struct {
@@ -331,10 +321,6 @@ pub fn DeriveFromBase(comptime BaseType: anytype, comptime Derived: type) type {
331321
pub fn data(self: *Self) *Derived {
332322
return &self.__data;
333323
}
334-
335-
// pub fn __destructor(self: *Self) void {
336-
// self.interface.__destructor(self.interface);
337-
// }
338324
};
339325
}
340326

0 commit comments

Comments
 (0)