View test.zig
const mem = @import("std").mem;
const assert = @import("std").debug.assert;
const AllocState = struct {
some_mem: [100 * 1024]u8,
index: usize,
fn alloc(a: &mem.Allocator, n: usize) -> %[]u8 {
const self = @ptrCast(&AllocState, a.context);
const result = self.some_mem[self.index ... self.index + n];
View output.txt
[nix-shell:~/dev/zig/build]$ ./zig test ../std/os/path.zig --test-filter resolve
Test 1/1 os.path.resolve...OK
[nix-shell:~/dev/zig/build]$ ./zig test ../std/os/path.zig 
/home/andy/dev/zig/std/buffer.zig:105:24: error: container 'Buffer' has no member called 'initFromBuffer'
    var buf2 = %%Buffer.initFromBuffer(&buf);
                       ^
/home/andy/dev/zig/std/buffer.zig:106:15: error: no member named 'eqlBuffer' in 'Buffer'
    assert(buf.eqlBuffer(&buf2));
              ^
View output.txt
[nix-shell:~/dev/zig/build]$ ./zig build --build-file ../build.zig --help
Usage: ./zig build [steps] [options]
Steps:
default Build the project
test Run all the tests
test-behavior Run the behavior tests
test-std Run the standard library tests
test-compare-output Run the compare output tests
test-build-examples Build the examples
View test.zig
pub fn panic(msg: []const u8) -> noreturn { @breakpoint(); while (true) {} }
comptime {
if (@sizeOf(@typeOf(foo)) == 0) unreachable;
}
// now you can have foo be any function you'd like to play with
fn foo() {
}
// build with:
View hello_att.s
.text
.globl _start
_start:
mov $1, %rax
mov $1, %rdi
mov $msg, %rsi
mov $14, %rdx
syscall
View list.zig
const debug = @import("debug.zig");
const assert = debug.assert;
const mem = @import("mem.zig");
const Allocator = mem.Allocator;
pub fn List(comptime T: type, comptime ct_allocator: ?&Allocator) -> type {
struct {
const Self = this;
const RuntimeAllocatorType = if (ct_allocator == null) &Allocator else void;
View output.ll
; ModuleID = 'test.ll'
source_filename = "./test.zig"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%MultibootHeader = type <{ i64, i64, i64 }>
!llvm.module.flags = !{!0}
!llvm.dbg.cu = !{!1}
View output.txt
./test.zig:2:7: error: incompatible types: 'i32' and 'f64'
a + b
^
./test.zig:6:8: note: called from here
add(a, b)
^
./test.zig:10:8: note: called from here
foo(a, b)
^
./test.zig:14:8: note: called from here
View bug.ll
; ModuleID = '../example/hello_world/hello.zig'
source_filename = "../example/hello_world/hello.zig"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%OutStream = type { i32, [4096 x i8], i64 }
%"[]u8" = type { i8*, i64 }
%"[][]u8" = type { %"[]u8"*, i64 }
@0 = internal unnamed_addr constant i1 true