diff --git a/AnyTest.sublime-settings b/AnyTest.sublime-settings index ab72870..a7abba1 100644 --- a/AnyTest.sublime-settings +++ b/AnyTest.sublime-settings @@ -41,6 +41,9 @@ ], "java": [ "junit" + ], + "zig": [ + "zigtest" ] }, // Available log levels: DEBUG, INFO, WARNING, ERROR, CRITICAL @@ -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 } diff --git a/README.md b/README.md index b6d985e..cd85e92 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/plugin/test_frameworks/zig/__init__.py b/plugin/test_frameworks/zig/__init__.py new file mode 100644 index 0000000..d26960b --- /dev/null +++ b/plugin/test_frameworks/zig/__init__.py @@ -0,0 +1,5 @@ +from .. import TestFramework as BaseTestFramework + + +class TestFramework(BaseTestFramework): + language = "zig" # type: str diff --git a/plugin/test_frameworks/zig/zigtest.py b/plugin/test_frameworks/zig/zigtest.py new file mode 100644 index 0000000..b8a749e --- /dev/null +++ b/plugin/test_frameworks/zig/zigtest.py @@ -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)), + ] diff --git a/sublime-package.json b/sublime-package.json index 38a9b6f..b547cb0 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -82,6 +82,12 @@ "junit" ] }, + "ZigFrameworks": { + "type": "string", + "enum": [ + "zigtest" + ] + }, "PackageConfig": { "properties": { "subprojects": { @@ -209,6 +215,19 @@ } } ] + }, + "zig": { + "anyOf": [ + { + "$ref": "sublime://settings/AnyTest#/definitions/ZigFrameworks" + }, + { + "type": "array", + "items": { + "$ref": "sublime://settings/AnyTest#/definitions/ZigFrameworks" + } + } + ] } } }, @@ -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)" } } } diff --git a/tests/fixtures/zigtest/normal.zig b/tests/fixtures/zigtest/normal.zig new file mode 100644 index 0000000..82f5e36 --- /dev/null +++ b/tests/fixtures/zigtest/normal.zig @@ -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; +} diff --git a/tests/test_frameworks/zig/__init__.py b/tests/test_frameworks/zig/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_frameworks/zig/test_zigtest.py b/tests/test_frameworks/zig/test_zigtest.py new file mode 100644 index 0000000..cae65de --- /dev/null +++ b/tests/test_frameworks/zig/test_zigtest.py @@ -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")