Live data from Hacker News

Using Zig to Unit Test a C Application

mtlynch.io

1–10 of 54 posts

Re: Using Zig to Unit Test a C Application

#2
I've done this where I use python's ctypes library to write tests for a c codebase. This feels very similar in that it can be tricky to get the type interop correct the first time around. What other strategies/solutions do people like to use for testing their c projects?

Re: Using Zig to Unit Test a C Application

#3
It would be nice if something in Zig could auto-magically generate the zig to c interop call and type declarations.

I see there's "translate-c" to help migrate C to Zig, and maybe that's enough.

Generally I fall on the side of if a compiler can toss out a type warning, it could certainly give a reasonable solution also. Best-guess with a "// Warning type was guessed" is better than an opaque "RTFM" in most every case.

Re: Using Zig to Unit Test a C Application

#5

It would be nice if something in Zig could auto-magically generate the zig to c interop call and type declarations. I see there's "translate-c" to help migrate C to Zig, and maybe that's enough. Generally I fall on the side of if a compiler can toss out a type warning, it could certainly give a reasonable solution also. Best-guess with a "// Warning type was guessed" is better than an opaque "RTFM" in most every case…

> It would be nice if something in Zig could auto-magically generate the zig to c interop call and type declarations.

Do you mean building a .h file from zig code?

The other direction is just @cImport.

Re: Using Zig to Unit Test a C Application

#6
This is going to get really good when zlibc is done, you'll be able to for example, override the c stdlib "free" function in the c code and add features, for example (runtime) UAF/DF detection with metadata tracking (like stacktraces of where the memory was created and freed)

Re: Using Zig to Unit Test a C Application

#9
post #8
post #4

zig , ocaml, odin many system languages are making the headlines lately its very hard to pick one to learn not sure how to deal with this, learn them all, bet on one, what should we do

Is ocaml a system language?

Yes believe it or not ocaml is a systems language.

Re: Using Zig to Unit Test a C Application

#10
post #8
post #4

zig , ocaml, odin many system languages are making the headlines lately its very hard to pick one to learn not sure how to deal with this, learn them all, bet on one, what should we do

Is ocaml a system language?

yes it can be used to create systems and backend tools

   - it is used to create an OS https://github.com/mirage
   - it is used to create a transpiler https://melange.re/v2.2.0/
   - it was used to create Rust first compiler
ocaml is surely a systems language
Post reply on HN