Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zig test frameworks #35

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions AnyTest.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
],
"java": [
"junit"
],
"zig": [
"zigtest"
]
},
// Available log levels: DEBUG, INFO, WARNING, ERROR, CRITICAL
Expand Down Expand Up @@ -285,4 +288,15 @@
],
// "swift.xctest.args": ["--do-smth"],
// "swift.xctest.env": { "ENV2": "value" }, // will be merged with the ENV variable defined on the language level
//
// --- Zig ---
// "zig.runner": "command", // a runner for all Zig test frameworks
// "zig.env": { "ENV1": "value" }, // will be merged with the ENV variable defined on the test framework level
//
// "zig.cargotest.runner": "command", // a runner for the Zig test framework
"zig.zigtest.executable": [
"zig",
],
// "zig.zigtest.args": ["--do-smth"],
// "zig.zigtest.env": { "ENV2": "value" }, // will be merged with the ENV variable defined on the language level
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Currently, the following test frameworks are supported (more test frameworks are
| **Ruby** | Cucumber, M, Minitest, Rails, RSpec, Test Bench | `cucumber`, `m` ,`minitest`, `rails`, `rspec`, `test_bench` |
| **Rust** | Cargo | `cargotest` |
| **Switft** | XCTest | `xctest` |
| **Zig** | Zigtest | `zigtest` |

Feel free to [open an issue](https://github.com/timfjord/AnyTest/issues/new) with a test framework request as those test frameworks will be added first.

Expand Down
5 changes: 5 additions & 0 deletions plugin/test_frameworks/zig/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .. import TestFramework as BaseTestFramework


class TestFramework(BaseTestFramework):
language = "zig" # type: str
28 changes: 28 additions & 0 deletions plugin/test_frameworks/zig/zigtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import shlex

from .. import zig


class TestFramework(zig.TestFramework):
framework = "zigtest" # type: str
pattern = r".zig$" # type: str

test_patterns = (r'^\s*test\s+"(.+)"',)

def build_suite_position_args(self):
return ["build", "test"]

def build_file_position_args(self):
return ["test", self.context.file.relpath]

def build_line_position_args(self):
args = self.build_file_position_args()
nearest = self.find_nearest()

if not bool(nearest.tests):
return args

return args + [
"--test-filter",
shlex.quote(nearest.join("", escape_regex=True)),
]
49 changes: 49 additions & 0 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
"junit"
]
},
"ZigFrameworks": {
"type": "string",
"enum": [
"zigtest"
]
},
"PackageConfig": {
"properties": {
"subprojects": {
Expand Down Expand Up @@ -209,6 +215,19 @@
}
}
]
},
"zig": {
"anyOf": [
{
"$ref": "sublime://settings/AnyTest#/definitions/ZigFrameworks"
},
{
"type": "array",
"items": {
"$ref": "sublime://settings/AnyTest#/definitions/ZigFrameworks"
}
}
]
}
}
},
Expand Down Expand Up @@ -951,6 +970,36 @@
"type": "object",
"default": {},
"description": "XCTest tests specific ENV variables (will be merged with the ENV variables defined on the language level)"
},
"zig.runner": {
"$ref": "sublime://settings/AnyTest#/definitions/Runner",
"description": "A runner to run Zig tests with"
},
"zig.env": {
"type": "object",
"default": {},
"description": "Zig specific ENV variables (will be merged with the ENV variables defined on the test framework level)"
},
"zig.zigtest.runner": {
"$ref": "sublime://settings/AnyTest#/definitions/Runner",
"description": "A runner to run zig tests with"
},
"zig.zigtest.executable": {
"type": "array",
"default": [
"zig"
],
"description": "Zig test framework executable (e.g. [\"bin/tests\"])"
},
"zig.zigtest.args": {
"type": "array",
"default": [],
"description": "Zig test cli args (e.g. [\"--do-smth\"])"
},
"zig.zigtest.env": {
"type": "object",
"default": {},
"description": "Zig tests specific ENV variables (will be merged with the ENV variables defined on the language level)"
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/zigtest/normal.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const std = @import("std");
const testing = std.testing;

test "numbers" {
try testing.expect(1 == 1);
}

test "numbers 2" {
try testing.expect(1 == 1);
}

test addOne {
try testing.expect(addOne(1) == 2);
}

fn addOne(number: i32) i32 {
return number + 1;
}
Empty file.
17 changes: 17 additions & 0 deletions tests/test_frameworks/zig/test_zigtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from AnyTest.tests import SublimeProjectTestCase


class ZigtestTestCase(SublimeProjectTestCase):
folder = "zigtest"

def test_line(self):
yield from self._testFile("normal.zig", 9)
self.assertLastCommand("zig test normal.zig --test-filter 'numbers 2'")

def test_file(self):
yield from self._testFile("normal.zig")
self.assertLastCommand("zig test normal.zig")

def test_suite(self):
yield from self._testSuite("normal.zig")
self.assertLastCommand("zig build test")
Loading