runner
runner copied to clipboard
Add Zig
Please complete the following information about the language:
- Name: Zig
- Website: https://ziglang.org/
- Language Version: 0.9.1
The following are optional, but will help us add the language:
- Test Frameworks: zig test
- How to install: Available as packages or build from source
- How to compile/run: 'zig test' (for using zig test framework above) or 'zig run' (to build and run an executable)
- Probably need https://github.com/ziglang/zig/issues/6621 to control output
- Any comments: (e.g., what's interesting about this language): Zig is a simple and clean language which aims to provide the performance and safety of languages like Rust and the interoperability and predictability of C.
:+1: reaction might help to get this request prioritized.
Is Zig pretty stable now? It'll be a pain to keep up if it makes breaking changes frequently.
Is the output of zig test customizable? Or does it support machine-readable output like JSON? If not, we'll need to parse the raw output.
It's now 0.9.1
https://github.com/ziglang/zig/issues/6621 was added recently. It should allow us to run zig test with a custom runner, and get the output we need. Is anyone interested to experiment?
- Get Zig 0.11.0-dev (master) that supports
zig test --test-runner runner.zigoption. - Implement a custom test runner that outputs Codewars messages. I'd start from studying the default
test_runner.zig. - Try the custom test runner with
zig test --test-runner codewars_runner.zig example_tests.zig.
Tested on 0.11.0-dev.1026+4172c2916.
Working almost fine, but there is one big issue with std.testing: on error it outputs everything in stderr with std.debug.print (for example std.testing.expectEqual).
Reading from stderr doesn't help.
The only other way I can think of - directly compare values in test { ... } section and return error if they are not equal, but it seems weird to me. Plus, returning error much less verbose than assertion messages.
@k0tran Thanks for trying.
Maybe I'm misunderstanding something, but can't we redirect stderr to stdout (2>&1)?
Can you post the code somewhere (gist or repo)?
@kazk the main problem with current test runner implementation (repo) is that std.testing lib writes to stderr whenever it needs. Thus, there is no way (as I can see it) to print out actial error messages. But as I stated in repo's README we can print error kind. So technically we can deploy zig already and fix error messages later.
Also I've opened issue ziglang/zig#14245 related to this problem.
FIY: #14152 makes using non-standard pipes okayish to use, which enables to refactor the test runner for the desired properties (using stdout, stderr for whatever you want). Before that it was extremely clunky.
Would love to see Zig getting added to the list of coding languages in Code Wars, really looking forward to learning it.
And it's pretty stable now, come on, the bun runtime is written in it.
More personal opinion: Due to fundamental platform limitations of Unix (clone leaks file descriptor if done in parallel), the unit test runner and build design is unlikely to be changed or Zig would need a full mutex on every clone opting into slowness instead of performance.
@kazk What is needed besides the message output?
DESCRIBE::GROUP_NAME IT::TEST_NAME
- Test name can be taken from the test block, but what is "group_name" supposed to be?
- Tests can reference another for execution and there are utilities to reference all tests to be run, which could be used for cheating.
LOG:MODE?:LABEL?MESSAGE
Explicit HTML: Prefix the message with LOG:HTML: to render it as HTML. Custom Labeling: Prefix the message with <LOG::Custom Label> to set the label used by the log container. Collapsed Logs: Prefix the message with a label starting with - (e.g., LOG::-Example) to collapse the output by default. Adding Tabs: Prefix the message with TAB::Label to attach to the previous log container in a tab. This can be repeated to attach multiple tabs.
What is the log stuff supposed to be used for? Are writes to stdout or stderr supposed to be logged or all file descriptors?
I can write a test_runner, if I have more concrete instructions for adding language support. However, I'm not interested in adding the docker parts.
@matu3ba I've updated my prototype version (k0tran/codewars_zrunner) to zig 0.11.0. You can use it as starting template or suggest changes.
Here's few things about my implementation:
- There are no test groups. I considered them optional
- There is no protection from cheating. But to be honest I don't understand how could you possibly cheat. Tests and solution are written by different people. Is there any way to change tests from main code?
- Logs, html, custom lables etc. also considered optional
Now I'll explain why test runner is not complete. The main reason is that all testing functions use std.debug.print on error before returning one (ziglang/zig#14245). This way error message printed before test runner knows it's an error.
One of possible solutions is to integrate std.testing with std.log (ziglang/zig#5738) and then overwrite logging function to either store errors or print desired format.
So basically test runner works, but cannot properly output information about test failures.
If there is a problem with std.testing, couldnt we just use the C testing framework used by codewars to call the zig functions and use the zig compiler for building and linking the .zig / .c files together?
I for one would love for getting katasupport in zig. as solving katas is a great way of learning the language
Good idea, this could accelerate the learning process for the new adopters of the language 👍
Very interested in this too, hope Zig can receive some support on Codewars.
Considering only Exercism supports it and Zig has an ever growing community, being among the first websites to support exercises for zig is beneficial for codewars too.