Skip to content

Commit

Permalink
Run unit tests in CI (#19)
Browse files Browse the repository at this point in the history
* Add unit tests to CI.
* Pin to zig version 0.13.0.
  • Loading branch information
wmedrano authored Sep 11, 2024
1 parent 6ed1638 commit 74505c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: publish_site

on:
push:
branches: ["main"]
tags: ['v*.*.*']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -23,8 +23,7 @@ concurrency:
cancel-in-progress: false

jobs:
# Build job
build:
build-site:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -49,9 +48,7 @@ jobs:
uses: actions/upload-pages-artifact@v3
with:
path: ./site/_site

# Deployment job
deploy:
deploy-site:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0
- name: test
run: zig build test
- name: lint
run: zig fmt --check .
if: always()
3 changes: 3 additions & 0 deletions site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ nav_order: 0
Fizz is a **simple** interpretted programming language meant for **embedding in
Zig**.

{: .warning}
> Requires Zig 0.13.0
{: .warning}
> Fizz is not yet in a stable state. If you have a use case that you would like
> handled, file an [🪲 issue](https://github.com/wmedrano/fizz/issues).
Expand Down
2 changes: 0 additions & 2 deletions src/Vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ pub fn evalNoReset(self: *Vm, func: Val, args: []const Val) Error!Val {
self.env.stack.items = self.env.stack.items[0..stack_start];
return ret;
} else {
@setCold(true);
return .none;
}
},
Expand Down Expand Up @@ -406,7 +405,6 @@ fn executeDefine(self: *Vm, symbol: Symbol) Error!void {
}

fn errSymbolNotFound(self: *Vm, sym: Symbol) Error {
@setCold(true);
const name = self.env.memory_manager.symbols.getName(sym) orelse "*unknown-symbol*";
try self.env.errors.addError(
"Symbol {s} (id={d}) not found in global values",
Expand Down
6 changes: 0 additions & 6 deletions src/datastructures/ErrorCollector.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,33 @@ const std = @import("std");
errors: std.ArrayList([]const u8),

pub fn init(alloc: std.mem.Allocator) ErrorCollector {
@setCold(true);
return .{
.errors = std.ArrayList([]const u8).init(alloc),
};
}

pub fn deinit(self: *ErrorCollector) void {
@setCold(true);
self.clear();
self.errors.deinit();
}

pub fn allocator(self: *ErrorCollector) std.mem.Allocator {
@setCold(true);
return self.errors.allocator;
}

pub fn clear(self: *ErrorCollector) void {
@setCold(true);
for (self.errors.items) |msg| {
self.errors.allocator.free(msg);
}
self.errors.clearRetainingCapacity();
}

pub fn addError(self: *ErrorCollector, comptime fmt: []const u8, args: anytype) !void {
@setCold(true);
const msg = try std.fmt.allocPrint(self.allocator(), fmt, args);
try self.errors.append(msg);
}

pub fn format(self: *const ErrorCollector, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
@setCold(true);
for (self.errors.items) |err| {
try writer.print("{s}\n", .{err});
}
Expand Down

0 comments on commit 74505c9

Please sign in to comment.