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 #136

Open
zrax opened this issue Jul 28, 2021 · 11 comments
Open

Add Zig #136

zrax opened this issue Jul 28, 2021 · 11 comments
Labels
help wanted Extra attention is needed request/language

Comments

@zrax
Copy link

zrax commented Jul 28, 2021

Please complete the following information about the language:

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)
  • 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.

👍 reaction might help to get this request prioritized.

@kazk
Copy link
Member

kazk commented Jul 29, 2021

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.

@kazk kazk changed the title Add zig Add Zig Aug 2, 2021
@kazk kazk added the help wanted Extra attention is needed label Oct 10, 2021
@ice1000

This comment was marked as resolved.

@kazk kazk moved this to Planned Languages in Code Runner Jul 15, 2022
@kazk kazk added this to Code Runner Jul 15, 2022
@kazk kazk moved this from Planned Languages to To Do in Code Runner Jul 15, 2022
@kazk
Copy link
Member

kazk commented Nov 23, 2022

ziglang/zig#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?

  1. Get Zig 0.11.0-dev (master) that supports zig test --test-runner runner.zig option.
  2. Implement a custom test runner that outputs Codewars messages. I'd start from studying the default test_runner.zig.
  3. Try the custom test runner with zig test --test-runner codewars_runner.zig example_tests.zig.

@k0tran
Copy link

k0tran commented Jan 8, 2023

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.

@kazk
Copy link
Member

kazk commented Jan 17, 2023

@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)?

@k0tran
Copy link

k0tran commented Jan 17, 2023

@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.

@matu3ba
Copy link

matu3ba commented Jan 22, 2023

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.

@itse4elhaam
Copy link

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.

@matu3ba
Copy link

matu3ba commented Sep 20, 2023

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

  1. Test name can be taken from the test block, but what is "group_name" supposed to be?
  2. 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.

@k0tran
Copy link

k0tran commented Sep 20, 2023

@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.

@llytaii
Copy link

llytaii commented Dec 6, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed request/language
Projects
Status: To Do
Development

No branches or pull requests

7 participants