mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
Merge branch 'master' into sema-rounding-casts
This commit is contained in:
@@ -17,6 +17,27 @@ permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
aarch64-freebsd-debug:
|
||||
runs-on: [self-hosted, aarch64-freebsd]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Build and Test
|
||||
run: sh ci/aarch64-freebsd-debug.sh
|
||||
timeout-minutes: 300
|
||||
aarch64-freebsd-release:
|
||||
runs-on: [self-hosted, aarch64-freebsd]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Build and Test
|
||||
run: sh ci/aarch64-freebsd-release.sh
|
||||
timeout-minutes: 240
|
||||
|
||||
aarch64-linux-debug:
|
||||
runs-on: [self-hosted, aarch64-linux]
|
||||
steps:
|
||||
@@ -38,6 +59,27 @@ jobs:
|
||||
run: sh ci/aarch64-linux-release.sh
|
||||
timeout-minutes: 120
|
||||
|
||||
aarch64-netbsd-debug:
|
||||
runs-on: [self-hosted, aarch64-netbsd]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Build and Test
|
||||
run: sh ci/aarch64-netbsd-debug.sh
|
||||
timeout-minutes: 300
|
||||
aarch64-netbsd-release:
|
||||
runs-on: [self-hosted, aarch64-netbsd]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Build and Test
|
||||
run: sh ci/aarch64-netbsd-release.sh
|
||||
timeout-minutes: 240
|
||||
|
||||
aarch64-macos-debug:
|
||||
runs-on: [self-hosted, aarch64-macos]
|
||||
steps:
|
||||
@@ -111,7 +153,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
- name: Build and Test
|
||||
run: sh ci/riscv64-linux-debug.sh
|
||||
timeout-minutes: 600
|
||||
timeout-minutes: 660
|
||||
riscv64-linux-release:
|
||||
if: github.event_name != 'pull_request'
|
||||
runs-on: [self-hosted, riscv64-linux]
|
||||
@@ -197,6 +239,27 @@ jobs:
|
||||
run: sh ci/x86_64-linux-release.sh
|
||||
timeout-minutes: 360
|
||||
|
||||
x86_64-netbsd-debug:
|
||||
runs-on: [self-hosted, x86_64-netbsd]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Build and Test
|
||||
run: sh ci/x86_64-netbsd-debug.sh
|
||||
timeout-minutes: 120
|
||||
x86_64-netbsd-release:
|
||||
runs-on: [self-hosted, x86_64-netbsd]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Build and Test
|
||||
run: sh ci/x86_64-netbsd-release.sh
|
||||
timeout-minutes: 120
|
||||
|
||||
x86_64-openbsd-debug:
|
||||
runs-on: [self-hosted, x86_64-openbsd]
|
||||
steps:
|
||||
|
||||
+14
-184
@@ -205,181 +205,6 @@ set(ZIG_CPP_SOURCES
|
||||
set(ZIG_STAGE2_SOURCES
|
||||
"${ZIG_CONFIG_ZIG_OUT}"
|
||||
lib/compiler_rt.zig
|
||||
lib/compiler_rt/absv.zig
|
||||
lib/compiler_rt/absvdi2.zig
|
||||
lib/compiler_rt/absvsi2.zig
|
||||
lib/compiler_rt/absvti2.zig
|
||||
lib/compiler_rt/adddf3.zig
|
||||
lib/compiler_rt/addf3.zig
|
||||
lib/compiler_rt/addsf3.zig
|
||||
lib/compiler_rt/addtf3.zig
|
||||
lib/compiler_rt/addvsi3.zig
|
||||
lib/compiler_rt/addvdi3.zig
|
||||
lib/compiler_rt/addxf3.zig
|
||||
lib/compiler_rt/arm.zig
|
||||
lib/compiler_rt/atomics.zig
|
||||
lib/compiler_rt/aulldiv.zig
|
||||
lib/compiler_rt/aullrem.zig
|
||||
lib/compiler_rt/bswap.zig
|
||||
lib/compiler_rt/clear_cache.zig
|
||||
lib/compiler_rt/cmp.zig
|
||||
lib/compiler_rt/cmpdf2.zig
|
||||
lib/compiler_rt/cmpsf2.zig
|
||||
lib/compiler_rt/cmptf2.zig
|
||||
lib/compiler_rt/cmpxf2.zig
|
||||
lib/compiler_rt/common.zig
|
||||
lib/compiler_rt/comparef.zig
|
||||
lib/compiler_rt/cos.zig
|
||||
lib/compiler_rt/count0bits.zig
|
||||
lib/compiler_rt/divdf3.zig
|
||||
lib/compiler_rt/divsf3.zig
|
||||
lib/compiler_rt/divtf3.zig
|
||||
lib/compiler_rt/divti3.zig
|
||||
lib/compiler_rt/divxf3.zig
|
||||
lib/compiler_rt/emutls.zig
|
||||
lib/compiler_rt/exp.zig
|
||||
lib/compiler_rt/exp2.zig
|
||||
lib/compiler_rt/extenddftf2.zig
|
||||
lib/compiler_rt/extenddfxf2.zig
|
||||
lib/compiler_rt/extendf.zig
|
||||
lib/compiler_rt/extendhfsf2.zig
|
||||
lib/compiler_rt/extendhftf2.zig
|
||||
lib/compiler_rt/extendhfxf2.zig
|
||||
lib/compiler_rt/extendsfdf2.zig
|
||||
lib/compiler_rt/extendsftf2.zig
|
||||
lib/compiler_rt/extendsfxf2.zig
|
||||
lib/compiler_rt/extendxftf2.zig
|
||||
lib/compiler_rt/fabs.zig
|
||||
lib/compiler_rt/fixdfdi.zig
|
||||
lib/compiler_rt/fixdfsi.zig
|
||||
lib/compiler_rt/fixdfti.zig
|
||||
lib/compiler_rt/fixhfdi.zig
|
||||
lib/compiler_rt/fixhfsi.zig
|
||||
lib/compiler_rt/fixhfti.zig
|
||||
lib/compiler_rt/fixsfdi.zig
|
||||
lib/compiler_rt/fixsfsi.zig
|
||||
lib/compiler_rt/fixsfti.zig
|
||||
lib/compiler_rt/fixtfdi.zig
|
||||
lib/compiler_rt/fixtfsi.zig
|
||||
lib/compiler_rt/fixtfti.zig
|
||||
lib/compiler_rt/fixunsdfdi.zig
|
||||
lib/compiler_rt/fixunsdfsi.zig
|
||||
lib/compiler_rt/fixunsdfti.zig
|
||||
lib/compiler_rt/fixunshfdi.zig
|
||||
lib/compiler_rt/fixunshfsi.zig
|
||||
lib/compiler_rt/fixunshfti.zig
|
||||
lib/compiler_rt/fixunssfdi.zig
|
||||
lib/compiler_rt/fixunssfsi.zig
|
||||
lib/compiler_rt/fixunssfti.zig
|
||||
lib/compiler_rt/fixunstfdi.zig
|
||||
lib/compiler_rt/fixunstfsi.zig
|
||||
lib/compiler_rt/fixunstfti.zig
|
||||
lib/compiler_rt/fixunsxfdi.zig
|
||||
lib/compiler_rt/fixunsxfsi.zig
|
||||
lib/compiler_rt/fixunsxfti.zig
|
||||
lib/compiler_rt/fixxfdi.zig
|
||||
lib/compiler_rt/fixxfsi.zig
|
||||
lib/compiler_rt/fixxfti.zig
|
||||
lib/compiler_rt/float_from_int.zig
|
||||
lib/compiler_rt/floatdidf.zig
|
||||
lib/compiler_rt/floatdihf.zig
|
||||
lib/compiler_rt/floatdisf.zig
|
||||
lib/compiler_rt/floatditf.zig
|
||||
lib/compiler_rt/floatdixf.zig
|
||||
lib/compiler_rt/floatsidf.zig
|
||||
lib/compiler_rt/floatsihf.zig
|
||||
lib/compiler_rt/floatsisf.zig
|
||||
lib/compiler_rt/floatsitf.zig
|
||||
lib/compiler_rt/floatsixf.zig
|
||||
lib/compiler_rt/floattidf.zig
|
||||
lib/compiler_rt/floattihf.zig
|
||||
lib/compiler_rt/floattisf.zig
|
||||
lib/compiler_rt/floattitf.zig
|
||||
lib/compiler_rt/floattixf.zig
|
||||
lib/compiler_rt/floatundidf.zig
|
||||
lib/compiler_rt/floatundihf.zig
|
||||
lib/compiler_rt/floatundisf.zig
|
||||
lib/compiler_rt/floatunditf.zig
|
||||
lib/compiler_rt/floatundixf.zig
|
||||
lib/compiler_rt/floatunsidf.zig
|
||||
lib/compiler_rt/floatunsihf.zig
|
||||
lib/compiler_rt/floatunsisf.zig
|
||||
lib/compiler_rt/floatunsitf.zig
|
||||
lib/compiler_rt/floatunsixf.zig
|
||||
lib/compiler_rt/floatuntidf.zig
|
||||
lib/compiler_rt/floatuntihf.zig
|
||||
lib/compiler_rt/floatuntisf.zig
|
||||
lib/compiler_rt/floatuntitf.zig
|
||||
lib/compiler_rt/floatuntixf.zig
|
||||
lib/compiler_rt/floor_ceil.zig
|
||||
lib/compiler_rt/fma.zig
|
||||
lib/compiler_rt/fmax.zig
|
||||
lib/compiler_rt/fmin.zig
|
||||
lib/compiler_rt/fmod.zig
|
||||
lib/compiler_rt/gedf2.zig
|
||||
lib/compiler_rt/gesf2.zig
|
||||
lib/compiler_rt/getf2.zig
|
||||
lib/compiler_rt/gexf2.zig
|
||||
lib/compiler_rt/int.zig
|
||||
lib/compiler_rt/int_from_float.zig
|
||||
lib/compiler_rt/log.zig
|
||||
lib/compiler_rt/log10.zig
|
||||
lib/compiler_rt/log2.zig
|
||||
lib/compiler_rt/modti3.zig
|
||||
lib/compiler_rt/mulXi3.zig
|
||||
lib/compiler_rt/muldf3.zig
|
||||
lib/compiler_rt/mulf3.zig
|
||||
lib/compiler_rt/mulo.zig
|
||||
lib/compiler_rt/mulsf3.zig
|
||||
lib/compiler_rt/multf3.zig
|
||||
lib/compiler_rt/mulvsi3.zig
|
||||
lib/compiler_rt/mulxf3.zig
|
||||
lib/compiler_rt/negXi2.zig
|
||||
lib/compiler_rt/negdf2.zig
|
||||
lib/compiler_rt/negsf2.zig
|
||||
lib/compiler_rt/negtf2.zig
|
||||
lib/compiler_rt/negv.zig
|
||||
lib/compiler_rt/negxf2.zig
|
||||
lib/compiler_rt/os_version_check.zig
|
||||
lib/compiler_rt/parity.zig
|
||||
lib/compiler_rt/popcount.zig
|
||||
lib/compiler_rt/rem_pio2.zig
|
||||
lib/compiler_rt/rem_pio2_large.zig
|
||||
lib/compiler_rt/rem_pio2f.zig
|
||||
lib/compiler_rt/round.zig
|
||||
lib/compiler_rt/shift.zig
|
||||
lib/compiler_rt/sin.zig
|
||||
lib/compiler_rt/sincos.zig
|
||||
lib/compiler_rt/sqrt.zig
|
||||
lib/compiler_rt/stack_probe.zig
|
||||
lib/compiler_rt/subdf3.zig
|
||||
lib/compiler_rt/subsf3.zig
|
||||
lib/compiler_rt/subtf3.zig
|
||||
lib/compiler_rt/subvdi3.zig
|
||||
lib/compiler_rt/subvsi3.zig
|
||||
lib/compiler_rt/subxf3.zig
|
||||
lib/compiler_rt/tan.zig
|
||||
lib/compiler_rt/trig.zig
|
||||
lib/compiler_rt/trunc.zig
|
||||
lib/compiler_rt/truncdfhf2.zig
|
||||
lib/compiler_rt/truncdfsf2.zig
|
||||
lib/compiler_rt/truncf.zig
|
||||
lib/compiler_rt/truncsfhf2.zig
|
||||
lib/compiler_rt/trunctfdf2.zig
|
||||
lib/compiler_rt/trunctfhf2.zig
|
||||
lib/compiler_rt/trunctfsf2.zig
|
||||
lib/compiler_rt/trunctfxf2.zig
|
||||
lib/compiler_rt/truncxfdf2.zig
|
||||
lib/compiler_rt/truncxfhf2.zig
|
||||
lib/compiler_rt/truncxfsf2.zig
|
||||
lib/compiler_rt/udivmod.zig
|
||||
lib/compiler_rt/udivmodei4.zig
|
||||
lib/compiler_rt/udivmodti4.zig
|
||||
lib/compiler_rt/udivti3.zig
|
||||
lib/compiler_rt/umodti3.zig
|
||||
lib/compiler_rt/unorddf2.zig
|
||||
lib/compiler_rt/unordsf2.zig
|
||||
lib/compiler_rt/unordtf2.zig
|
||||
lib/std/BitStack.zig
|
||||
lib/std/Build.zig
|
||||
lib/std/Build/Cache.zig
|
||||
@@ -408,9 +233,6 @@ set(ZIG_STAGE2_SOURCES
|
||||
lib/std/Target/wasm.zig
|
||||
lib/std/Target/x86.zig
|
||||
lib/std/Thread.zig
|
||||
lib/std/Thread/Futex.zig
|
||||
lib/std/Thread/Mutex.zig
|
||||
lib/std/Thread/WaitGroup.zig
|
||||
lib/std/array_hash_map.zig
|
||||
lib/std/array_list.zig
|
||||
lib/std/ascii.zig
|
||||
@@ -441,7 +263,7 @@ set(ZIG_STAGE2_SOURCES
|
||||
lib/std/hash/wyhash.zig
|
||||
lib/std/hash_map.zig
|
||||
lib/std/heap.zig
|
||||
lib/std/heap/arena_allocator.zig
|
||||
lib/std/heap/ArenaAllocator.zig
|
||||
lib/std/json.zig
|
||||
lib/std/leb128.zig
|
||||
lib/std/log.zig
|
||||
@@ -508,7 +330,6 @@ set(ZIG_STAGE2_SOURCES
|
||||
src/Air/Liveness.zig
|
||||
src/Air/Liveness/Verify.zig
|
||||
src/Air/print.zig
|
||||
src/Air/types_resolved.zig
|
||||
src/Builtin.zig
|
||||
src/Compilation.zig
|
||||
src/Compilation/Config.zig
|
||||
@@ -522,6 +343,7 @@ set(ZIG_STAGE2_SOURCES
|
||||
src/Sema.zig
|
||||
src/Sema/bitcast.zig
|
||||
src/Sema/comptime_ptr_access.zig
|
||||
src/Sema/type_resolution.zig
|
||||
src/Type.zig
|
||||
src/Value.zig
|
||||
src/Zcu.zig
|
||||
@@ -538,7 +360,8 @@ set(ZIG_STAGE2_SOURCES
|
||||
src/codegen/aarch64/Mir.zig
|
||||
src/codegen/aarch64/Select.zig
|
||||
src/codegen/c.zig
|
||||
src/codegen/c/Type.zig
|
||||
src/codegen/c/type.zig
|
||||
src/codegen/c/type/render_defs.zig
|
||||
src/codegen/llvm.zig
|
||||
src/codegen/llvm/bindings.zig
|
||||
src/crash_report.zig
|
||||
@@ -553,6 +376,7 @@ set(ZIG_STAGE2_SOURCES
|
||||
src/libs/libunwind.zig
|
||||
src/link.zig
|
||||
src/link/C.zig
|
||||
src/link/ConstPool.zig
|
||||
src/link/Coff.zig
|
||||
src/link/Dwarf.zig
|
||||
src/link/Elf.zig
|
||||
@@ -784,10 +608,10 @@ if(MSVC)
|
||||
set(ZIG2_LINK_FLAGS "/STACK:16777216 /FORCE:MULTIPLE")
|
||||
else()
|
||||
set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2")
|
||||
set(ZIG1_COMPILE_FLAGS "-std=c99 -Os")
|
||||
set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector")
|
||||
set(ZIG1_COMPILE_FLAGS "-std=c99 -Os -fno-strict-aliasing")
|
||||
set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector -fno-strict-aliasing")
|
||||
# Must match the condition in build.zig.
|
||||
if(ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$")
|
||||
if(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)(eb)?$" OR ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$")
|
||||
set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -ffunction-sections -fdata-sections")
|
||||
set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -ffunction-sections -fdata-sections")
|
||||
endif()
|
||||
@@ -801,6 +625,12 @@ else()
|
||||
else()
|
||||
set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000")
|
||||
endif()
|
||||
# Prevent GCC from miscompiling 'zig2.c'. See also 'workaround_gcc_sra_miscomp' in 'bootstrap.c'.
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
|
||||
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0" AND
|
||||
CMAKE_C_COMPILER_VERSION VERSION_LESS_EQUAL "15.2")
|
||||
set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -fno-tree-sra")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(ZIG1_WASM_MODULE "${PROJECT_SOURCE_DIR}/stage1/zig1.wasm")
|
||||
|
||||
@@ -616,17 +616,17 @@ a few releases old, or may be missing newer targets such as aarch64 and RISC-V.
|
||||
[ziglang/qemu-static](https://codeberg.org/ziglang/qemu-static) offers static
|
||||
binaries of the latest QEMU version.
|
||||
|
||||
##### Testing Non-Native glibc Targets
|
||||
##### Testing Non-Native libc Targets
|
||||
|
||||
Testing foreign architectures with dynamically linked glibc is one step trickier.
|
||||
This requires enabling `--glibc-runtimes /path/to/glibc/multi/install/glibcs`.
|
||||
This path is obtained by building glibc for multiple architectures. This
|
||||
process for me took an entire day to complete and takes up 65 GiB on my hard
|
||||
drive. The CI server does not provide this test coverage.
|
||||
Testing foreign architectures with dynamically linked libc is one step trickier.
|
||||
This requires enabling `--libc-runtimes /path/to/libcs`. This path is obtained
|
||||
by building glibc and musl for multiple architectures. This process for me took
|
||||
an entire day to complete and takes up 65 GiB on my hard drive.
|
||||
|
||||
[Instructions for producing this path](https://codeberg.org/ziglang/infra/src/branch/master/building-libcs.md#linux-glibc) (just the part with `build-many-glibcs.py`).
|
||||
[Instructions for producing this path.](https://codeberg.org/ziglang/infra/src/branch/master/building-libcs.md)
|
||||
|
||||
It is understood that most contributors will not have these tests enabled.
|
||||
It is understood that most contributors will not have these tests enabled. The
|
||||
CI machines provide coverage for these.
|
||||
|
||||
#### Testing Windows from a Linux Machine with Wine
|
||||
|
||||
|
||||
+24
-1
@@ -102,6 +102,26 @@ int main(int argc, char **argv) {
|
||||
const char *cc = get_c_compiler();
|
||||
const char *host_triple = get_host_triple();
|
||||
|
||||
// GCC versions 13.0--14.1 have a miscompilation where some bytes of a union may get clobbered
|
||||
// depending on the union layout and the order in which types are defined. This miscompilation
|
||||
// affects the output of the C backend, and thus can affect the bootstrap process. Specifically,
|
||||
// we observe that using the self-hosted x86_64 backend in 'zig2' will cause all function calls
|
||||
// to be relocated incorrectly, causing immediate crashes on any binary produced by it.
|
||||
//
|
||||
// The only reliable workaround for this bug is to disable the optimization pass containing it,
|
||||
// so here we check for a CLI flag requesting that workaround.
|
||||
//
|
||||
// The upstream bug is fixed in GCC version 15.2 onwards (and was also backported to the 13 and
|
||||
// 14 branches). Once this bug is no longer widespread, we can remove this CLI flag.
|
||||
//
|
||||
// Upstream bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119085
|
||||
bool workaround_gcc_sra_miscomp = false;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (!strcmp(argv[i], "--workaround-gcc-sra-miscomp")) {
|
||||
workaround_gcc_sra_miscomp = true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char *child_argv[] = {
|
||||
cc, "-o", "zig-wasm2c", "stage1/wasm2c.c", "-O2", "-std=c99", NULL,
|
||||
@@ -116,7 +136,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
{
|
||||
const char *child_argv[] = {
|
||||
cc, "-o", "zig1", "zig1.c", "stage1/wasi.c", "-std=c99", "-Os", "-lm", NULL,
|
||||
cc, "-o", "zig1", "zig1.c", "stage1/wasi.c", "-std=c99", "-Os", "-fno-strict-aliasing", "-lm", NULL,
|
||||
};
|
||||
print_and_run(child_argv);
|
||||
}
|
||||
@@ -143,6 +163,7 @@ int main(int argc, char **argv) {
|
||||
"pub const skip_non_native = false;\n"
|
||||
"pub const debug_gpa = false;\n"
|
||||
"pub const dev = .core;\n"
|
||||
"pub const io_mode: enum { threaded, evented } = .threaded;\n"
|
||||
"pub const value_interpret_mode = .direct;\n"
|
||||
, zig_version);
|
||||
if (written < 100)
|
||||
@@ -192,6 +213,8 @@ int main(int argc, char **argv) {
|
||||
#if defined(__GNUC__)
|
||||
"-pthread",
|
||||
#endif
|
||||
"-fno-strict-aliasing",
|
||||
workaround_gcc_sra_miscomp ? "-fno-tree-sra" : NULL,
|
||||
NULL,
|
||||
};
|
||||
print_and_run(child_argv);
|
||||
|
||||
@@ -13,6 +13,7 @@ const DevEnv = @import("src/dev.zig").Env;
|
||||
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 16, .patch = 0 };
|
||||
const stack_size = 46 * 1024 * 1024;
|
||||
|
||||
const IoMode = enum { threaded, evented };
|
||||
const ValueInterpretMode = enum { direct, by_name };
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
@@ -29,7 +30,7 @@ pub fn build(b: *std.Build) !void {
|
||||
const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false;
|
||||
|
||||
const test_step = b.step("test", "Run all the tests");
|
||||
const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse false;
|
||||
const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse only_c;
|
||||
const skip_install_langref = b.option(bool, "no-langref", "skip copying of langref to the installation prefix") orelse skip_install_lib_files;
|
||||
const std_docs = b.option(bool, "std-docs", "include standard library autodocs") orelse false;
|
||||
const no_bin = b.option(bool, "no-bin", "skip emitting compiler binary") orelse false;
|
||||
@@ -84,6 +85,7 @@ pub fn build(b: *std.Build) !void {
|
||||
docs_step.dependOn(std_docs_step);
|
||||
|
||||
const no_matrix = b.option(bool, "no-matrix", "Limit test matrix to exactly one target configuration") orelse false;
|
||||
const fuzz_only = b.option(bool, "fuzz-only", "Limit test matrix to one target suitable for fuzzing") orelse false;
|
||||
const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false;
|
||||
const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse no_matrix;
|
||||
const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
|
||||
@@ -188,6 +190,7 @@ pub fn build(b: *std.Build) !void {
|
||||
const strip = b.option(bool, "strip", "Omit debug information");
|
||||
const valgrind = b.option(bool, "valgrind", "Enable valgrind integration");
|
||||
const pie = b.option(bool, "pie", "Produce a Position Independent Executable");
|
||||
const io_mode = b.option(IoMode, "io-mode", "How the compiler performs IO") orelse .threaded;
|
||||
const value_interpret_mode = b.option(ValueInterpretMode, "value-interpret-mode", "How the compiler translates between 'std.builtin' types and its internal datastructures") orelse .direct;
|
||||
const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;
|
||||
|
||||
@@ -236,6 +239,7 @@ pub fn build(b: *std.Build) !void {
|
||||
exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa);
|
||||
exe_options.addOption(bool, "debug_gpa", debug_gpa);
|
||||
exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full);
|
||||
exe_options.addOption(IoMode, "io_mode", io_mode);
|
||||
exe_options.addOption(ValueInterpretMode, "value_interpret_mode", value_interpret_mode);
|
||||
|
||||
if (link_libc) {
|
||||
@@ -367,14 +371,22 @@ pub fn build(b: *std.Build) !void {
|
||||
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
|
||||
);
|
||||
|
||||
const tracy_c_flags: []const []const u8 = &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
|
||||
const tracy_c_flags: []const []const u8 = &.{
|
||||
"-DTRACY_ENABLE=1",
|
||||
"-fno-sanitize=undefined",
|
||||
"-DTRACY_FIBERS",
|
||||
};
|
||||
|
||||
exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path });
|
||||
exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
|
||||
if (!enable_llvm) {
|
||||
exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no });
|
||||
}
|
||||
exe.root_module.addCSourceFile(.{
|
||||
.file = .{ .cwd_relative = client_cpp },
|
||||
.flags = tracy_c_flags[0..switch (io_mode) {
|
||||
.threaded => 2,
|
||||
.evented => 3,
|
||||
}],
|
||||
});
|
||||
exe.root_module.link_libc = true;
|
||||
exe.root_module.link_libcpp = true;
|
||||
|
||||
if (target.result.os.tag == .windows) {
|
||||
exe.root_module.linkSystemLibrary("dbghelp", .{});
|
||||
@@ -406,6 +418,13 @@ pub fn build(b: *std.Build) !void {
|
||||
}
|
||||
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];
|
||||
|
||||
const test_only: ?tests.ModuleTestOptions.TestOnly = if (no_matrix)
|
||||
.default
|
||||
else if (fuzz_only)
|
||||
.{ .fuzz = optimize }
|
||||
else
|
||||
null;
|
||||
|
||||
const fmt_include_paths = &.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" };
|
||||
const fmt_exclude_paths = &.{ "test/cases", "test/behavior/zon" };
|
||||
const do_fmt = b.addFmt(.{
|
||||
@@ -461,7 +480,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.include_paths = &.{},
|
||||
.skip_single_threaded = skip_single_threaded,
|
||||
.skip_non_native = skip_non_native,
|
||||
.test_default_only = no_matrix,
|
||||
.test_only = test_only,
|
||||
.skip_spirv = skip_spirv,
|
||||
.skip_wasm = skip_wasm,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
@@ -472,27 +491,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.skip_linux = skip_linux,
|
||||
.skip_llvm = skip_llvm,
|
||||
.skip_libc = skip_libc,
|
||||
.max_rss = switch (b.graph.host.result.os.tag) {
|
||||
.freebsd => 2_000_000_000,
|
||||
.linux => switch (b.graph.host.result.cpu.arch) {
|
||||
.aarch64 => 659_809_075,
|
||||
.loongarch64 => 598_902_374,
|
||||
.powerpc64le => 627_431_833,
|
||||
.riscv64 => 827_043_430,
|
||||
.s390x => 580_596_121,
|
||||
.x86_64 => 3_290_894_745,
|
||||
else => 3_300_000_000,
|
||||
},
|
||||
.macos => switch (b.graph.host.result.cpu.arch) {
|
||||
.aarch64 => 767_736_217,
|
||||
else => 800_000_000,
|
||||
},
|
||||
.windows => switch (b.graph.host.result.cpu.arch) {
|
||||
.x86_64 => 603_070_054,
|
||||
else => 700_000_000,
|
||||
},
|
||||
else => 3_300_000_000,
|
||||
},
|
||||
.max_rss = 4_000_000_000,
|
||||
}));
|
||||
|
||||
test_modules_step.dependOn(tests.addModuleTests(b, .{
|
||||
@@ -506,7 +505,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.include_paths = &.{},
|
||||
.skip_single_threaded = true,
|
||||
.skip_non_native = skip_non_native,
|
||||
.test_default_only = no_matrix,
|
||||
.test_only = test_only,
|
||||
.skip_spirv = skip_spirv,
|
||||
.skip_wasm = skip_wasm,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
@@ -518,23 +517,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.skip_llvm = skip_llvm,
|
||||
.skip_libc = true,
|
||||
.no_builtin = true,
|
||||
.max_rss = switch (b.graph.host.result.os.tag) {
|
||||
.freebsd => 800_000_000,
|
||||
.linux => switch (b.graph.host.result.cpu.arch) {
|
||||
.aarch64 => 639_565_414,
|
||||
.loongarch64 => 598_884_352,
|
||||
.powerpc64le => 597_897_625,
|
||||
.riscv64 => 636_429_516,
|
||||
.s390x => 574_166_630,
|
||||
.x86_64 => 978_463_129,
|
||||
else => 900_000_000,
|
||||
},
|
||||
.macos => switch (b.graph.host.result.cpu.arch) {
|
||||
.aarch64 => 701_413_785,
|
||||
else => 800_000_000,
|
||||
},
|
||||
else => 900_000_000,
|
||||
},
|
||||
.max_rss = 4_000_000_000,
|
||||
}));
|
||||
|
||||
test_modules_step.dependOn(tests.addModuleTests(b, .{
|
||||
@@ -543,12 +526,12 @@ pub fn build(b: *std.Build) !void {
|
||||
.test_extra_targets = test_extra_targets,
|
||||
.root_src = "lib/c.zig",
|
||||
.name = "zigc",
|
||||
.desc = "Run the zigc tests",
|
||||
.desc = "Run the zig libc implementation unit tests",
|
||||
.optimize_modes = optimization_modes,
|
||||
.include_paths = &.{},
|
||||
.skip_single_threaded = true,
|
||||
.skip_non_native = skip_non_native,
|
||||
.test_default_only = no_matrix,
|
||||
.test_only = test_only,
|
||||
.skip_spirv = skip_spirv,
|
||||
.skip_wasm = skip_wasm,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
@@ -560,7 +543,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.skip_llvm = skip_llvm,
|
||||
.skip_libc = true,
|
||||
.no_builtin = true,
|
||||
.max_rss = 900_000_000,
|
||||
.max_rss = 4_000_000_000,
|
||||
}));
|
||||
|
||||
test_modules_step.dependOn(tests.addModuleTests(b, .{
|
||||
@@ -574,7 +557,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.include_paths = &.{},
|
||||
.skip_single_threaded = skip_single_threaded,
|
||||
.skip_non_native = skip_non_native,
|
||||
.test_default_only = no_matrix,
|
||||
.test_only = test_only,
|
||||
.skip_spirv = skip_spirv,
|
||||
.skip_wasm = skip_wasm,
|
||||
.skip_freebsd = skip_freebsd,
|
||||
@@ -585,22 +568,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.skip_linux = skip_linux,
|
||||
.skip_llvm = skip_llvm,
|
||||
.skip_libc = skip_libc,
|
||||
.max_rss = switch (b.graph.host.result.os.tag) {
|
||||
.freebsd => switch (b.graph.host.result.cpu.arch) {
|
||||
.x86_64 => 3_756_422_348,
|
||||
else => 3_800_000_000,
|
||||
},
|
||||
.linux => 6_800_000_000,
|
||||
.macos => switch (b.graph.host.result.cpu.arch) {
|
||||
.aarch64 => 8_273_795_481,
|
||||
else => 8_300_000_000,
|
||||
},
|
||||
.windows => switch (b.graph.host.result.cpu.arch) {
|
||||
.x86_64 => 3_750_236_160,
|
||||
else => 3_800_000_000,
|
||||
},
|
||||
else => 8_300_000_000,
|
||||
},
|
||||
.max_rss = 9_300_000_000,
|
||||
}));
|
||||
|
||||
const unit_tests_step = b.step("test-unit", "Run the compiler source unit tests");
|
||||
@@ -616,7 +584,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.use_llvm = use_llvm,
|
||||
.use_lld = use_llvm,
|
||||
.zig_lib_dir = b.path("lib"),
|
||||
.max_rss = 2_500_000_000,
|
||||
.max_rss = 2_700_000_000,
|
||||
});
|
||||
if (link_libc) {
|
||||
unit_tests.root_module.link_libc = true;
|
||||
@@ -643,30 +611,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.skip_linux = skip_linux,
|
||||
.skip_llvm = skip_llvm,
|
||||
.skip_release = skip_release,
|
||||
.max_rss = switch (b.graph.host.result.os.tag) {
|
||||
.freebsd => switch (b.graph.host.result.cpu.arch) {
|
||||
.x86_64 => 727_221_862,
|
||||
else => 800_000_000,
|
||||
},
|
||||
.linux => switch (b.graph.host.result.cpu.arch) {
|
||||
.aarch64 => 1_318_185_369,
|
||||
.loongarch64 => 1_422_904_524,
|
||||
.powerpc64le => 560_870_604,
|
||||
.riscv64 => 449_924_710,
|
||||
.s390x => 1_946_743_603,
|
||||
.x86_64 => 2_389_779_251,
|
||||
else => 2_200_000_000,
|
||||
},
|
||||
.macos => switch (b.graph.host.result.cpu.arch) {
|
||||
.aarch64 => 1_813_612_134,
|
||||
else => 1_900_000_000,
|
||||
},
|
||||
.windows => switch (b.graph.host.result.cpu.arch) {
|
||||
.x86_64 => 386_287_616,
|
||||
else => 400_000_000,
|
||||
},
|
||||
else => 2_200_000_000,
|
||||
},
|
||||
.max_rss = 3_300_000_000,
|
||||
}));
|
||||
test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, enable_symlinks_windows));
|
||||
test_step.dependOn(tests.addStackTraceTests(b, test_filters, skip_non_native));
|
||||
@@ -717,7 +662,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.test_filters = test_filters,
|
||||
.test_target_filters = test_target_filters,
|
||||
.skip_wasm = skip_wasm,
|
||||
.max_rss = 2_496_066_355,
|
||||
.max_rss = 3_500_000_000,
|
||||
})) |test_libc_step| test_step.dependOn(test_libc_step);
|
||||
}
|
||||
|
||||
@@ -751,6 +696,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
|
||||
exe_options.addOption(u32, "tracy_callstack_depth", 0);
|
||||
exe_options.addOption(bool, "value_tracing", false);
|
||||
exe_options.addOption(DevEnv, "dev", .bootstrap);
|
||||
exe_options.addOption(IoMode, "io_mode", .threaded);
|
||||
|
||||
// zig1 chooses to interpret values by name. The tradeoff is as follows:
|
||||
//
|
||||
@@ -821,13 +767,13 @@ fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Modu
|
||||
fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Step.Compile {
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zig",
|
||||
.max_rss = 7_900_000_000,
|
||||
.max_rss = 8_700_000_000,
|
||||
.root_module = addCompilerMod(b, options),
|
||||
});
|
||||
exe.stack_size = stack_size;
|
||||
|
||||
// Must match the condition in CMakeLists.txt.
|
||||
const function_data_sections = options.target.result.cpu.arch.isPowerPC();
|
||||
const function_data_sections = options.target.result.cpu.arch.isArm() or options.target.result.cpu.arch.isPowerPC();
|
||||
|
||||
exe.link_function_sections = function_data_sections;
|
||||
exe.link_data_sections = function_data_sections;
|
||||
@@ -1534,6 +1480,7 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
|
||||
defer dir.close(io);
|
||||
|
||||
var wf = b.addWriteFiles();
|
||||
b.step("test-docs", "Test code snippets from the docs").dependOn(&wf.step);
|
||||
|
||||
var it = dir.iterateAssumeFirstIteration();
|
||||
while (it.next(io) catch @panic("failed to read dir")) |entry| {
|
||||
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
TARGET="aarch64-freebsd-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
|
||||
|
||||
mkdir build-debug
|
||||
cd build-debug
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" \
|
||||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
unset CC
|
||||
unset CXX
|
||||
|
||||
ninja install
|
||||
|
||||
stage3-debug/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-non-native \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$PWD/../lib" \
|
||||
--test-timeout 2m
|
||||
|
||||
stage3-debug/bin/zig build \
|
||||
--prefix stage4-debug \
|
||||
-Denable-llvm \
|
||||
-Dno-lib \
|
||||
-Dtarget=$TARGET \
|
||||
-Duse-zig-libcxx \
|
||||
-Dversion-string="$(stage3-debug/bin/zig version)"
|
||||
|
||||
stage4-debug/bin/zig test ../test/behavior.zig
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
TARGET="aarch64-freebsd-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
|
||||
|
||||
mkdir build-release
|
||||
cd build-release
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" \
|
||||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
unset CC
|
||||
unset CXX
|
||||
|
||||
ninja install
|
||||
|
||||
stage3-release/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-non-native \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$PWD/../lib" \
|
||||
--test-timeout 2m
|
||||
|
||||
# Ensure that stage3 and stage4 are byte-for-byte identical.
|
||||
stage3-release/bin/zig build \
|
||||
--prefix stage4-release \
|
||||
-Denable-llvm \
|
||||
-Dno-lib \
|
||||
-Doptimize=ReleaseFast \
|
||||
-Dstrip \
|
||||
-Dtarget=$TARGET \
|
||||
-Duse-zig-libcxx \
|
||||
-Dversion-string="$(stage3-release/bin/zig version)"
|
||||
|
||||
# diff returns an error code if the files differ.
|
||||
echo "If the following command fails, it means nondeterminism has been"
|
||||
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
|
||||
diff stage3-release/bin/zig stage4-release/bin/zig
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
TARGET="aarch64-netbsd-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
|
||||
|
||||
mkdir build-debug
|
||||
cd build-debug
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" \
|
||||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
unset CC
|
||||
unset CXX
|
||||
|
||||
ninja install
|
||||
|
||||
stage3-debug/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-non-native \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$PWD/../lib" \
|
||||
--test-timeout 4m
|
||||
|
||||
stage3-debug/bin/zig build \
|
||||
--prefix stage4-debug \
|
||||
-Denable-llvm \
|
||||
-Dno-lib \
|
||||
-Dtarget=$TARGET \
|
||||
-Duse-zig-libcxx \
|
||||
-Dversion-string="$(stage3-debug/bin/zig version)"
|
||||
|
||||
stage4-debug/bin/zig test ../test/behavior.zig
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
TARGET="aarch64-netbsd-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
|
||||
|
||||
mkdir build-release
|
||||
cd build-release
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" \
|
||||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
unset CC
|
||||
unset CXX
|
||||
|
||||
ninja install
|
||||
|
||||
stage3-release/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-non-native \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$PWD/../lib" \
|
||||
--test-timeout 4m
|
||||
|
||||
# Ensure that stage3 and stage4 are byte-for-byte identical.
|
||||
stage3-release/bin/zig build \
|
||||
--prefix stage4-release \
|
||||
-Denable-llvm \
|
||||
-Dno-lib \
|
||||
-Doptimize=ReleaseFast \
|
||||
-Dstrip \
|
||||
-Dtarget=$TARGET \
|
||||
-Duse-zig-libcxx \
|
||||
-Dversion-string="$(stage3-release/bin/zig version)"
|
||||
|
||||
# diff returns an error code if the files differ.
|
||||
echo "If the following command fails, it means nondeterminism has been"
|
||||
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
|
||||
diff stage3-release/bin/zig stage4-release/bin/zig
|
||||
@@ -11,7 +11,7 @@ CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.0/bin:$HOME/local/bin:$PATH"
|
||||
export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
@@ -54,7 +54,9 @@ stage3-debug/bin/zig build \
|
||||
stage3-debug/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
|
||||
-Dlibc-test-path=$HOME/deps/libc-test-f2bac77 \
|
||||
-fqemu \
|
||||
--libc-runtimes $HOME/deps/glibc-2.43-musl-1.2.5 \
|
||||
-fwasmtime \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-freebsd \
|
||||
|
||||
@@ -11,7 +11,7 @@ CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.0/bin:$HOME/local/bin:$PATH"
|
||||
export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
@@ -54,6 +54,7 @@ stage3-debug/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
|
||||
-fqemu \
|
||||
--libc-runtimes $HOME/deps/glibc-2.43-musl-1.2.5 \
|
||||
-fwasmtime \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-freebsd \
|
||||
|
||||
@@ -11,7 +11,7 @@ CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.0/bin:$HOME/local/bin:$PATH"
|
||||
export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
@@ -21,7 +21,8 @@ export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
|
||||
|
||||
# Test building from source without LLVM.
|
||||
cc -o bootstrap bootstrap.c
|
||||
./bootstrap
|
||||
# See comments in bootstrap.c for an explanation of the flag given here.
|
||||
./bootstrap --workaround-gcc-sra-miscomp
|
||||
./zig2 build -Dno-lib
|
||||
./zig-out/bin/zig test test/behavior.zig
|
||||
|
||||
@@ -59,7 +60,9 @@ stage3-release/bin/zig build \
|
||||
stage3-release/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dlldb=$HOME/deps/lldb-zig/Release-e0a42bb34/bin/lldb \
|
||||
-Dlibc-test-path=$HOME/deps/libc-test-f2bac77 \
|
||||
-fqemu \
|
||||
--libc-runtimes $HOME/deps/glibc-2.43-musl-1.2.5 \
|
||||
-fwasmtime \
|
||||
-Dstatic-llvm \
|
||||
-Dtarget=native-native-musl \
|
||||
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
TARGET="x86_64-netbsd-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
|
||||
|
||||
mkdir build-debug
|
||||
cd build-debug
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" \
|
||||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
unset CC
|
||||
unset CXX
|
||||
|
||||
ninja install
|
||||
|
||||
stage3-debug/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-non-native \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$PWD/../lib" \
|
||||
--test-timeout 2m
|
||||
|
||||
stage3-debug/bin/zig build \
|
||||
--prefix stage4-debug \
|
||||
-Denable-llvm \
|
||||
-Dno-lib \
|
||||
-Dtarget=$TARGET \
|
||||
-Duse-zig-libcxx \
|
||||
-Dversion-string="$(stage3-debug/bin/zig version)"
|
||||
|
||||
stage4-debug/bin/zig test ../test/behavior.zig
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
TARGET="x86_64-netbsd-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
|
||||
|
||||
mkdir build-release
|
||||
cd build-release
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" \
|
||||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
unset CC
|
||||
unset CXX
|
||||
|
||||
ninja install
|
||||
|
||||
stage3-release/bin/zig build test docs \
|
||||
--maxrss ${ZSF_MAX_RSS:-0} \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-non-native \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$PWD/../lib" \
|
||||
--test-timeout 2m
|
||||
|
||||
# Ensure that stage3 and stage4 are byte-for-byte identical.
|
||||
stage3-release/bin/zig build \
|
||||
--prefix stage4-release \
|
||||
-Denable-llvm \
|
||||
-Dno-lib \
|
||||
-Doptimize=ReleaseFast \
|
||||
-Dstrip \
|
||||
-Dtarget=$TARGET \
|
||||
-Duse-zig-libcxx \
|
||||
-Dversion-string="$(stage3-release/bin/zig version)"
|
||||
|
||||
# diff returns an error code if the files differ.
|
||||
echo "If the following command fails, it means nondeterminism has been"
|
||||
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
|
||||
diff stage3-release/bin/zig stage4-release/bin/zig
|
||||
+20
-32
@@ -1,21 +1,10 @@
|
||||
$TARGET = "x86_64-windows-gnu"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
|
||||
$MCPU = "baseline"
|
||||
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
|
||||
$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME"
|
||||
$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
|
||||
$ZIG = "$PREFIX_PATH\bin\zig.exe"
|
||||
$ZIG_LIB_DIR = "$(Get-Location)\lib"
|
||||
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
|
||||
|
||||
if (!(Test-Path "$PREFIX_PATH.zip")) {
|
||||
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
|
||||
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip"
|
||||
|
||||
Write-Output "Extracting..."
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..")
|
||||
}
|
||||
|
||||
function CheckLastExitCode {
|
||||
if (!$?) {
|
||||
exit 1
|
||||
@@ -35,7 +24,7 @@ Set-Location -Path 'build-debug'
|
||||
|
||||
# CMake gives a syntax error when file paths with backward slashes are used.
|
||||
# Here, we use forward slashes only to work around this.
|
||||
& cmake .. `
|
||||
cmake .. `
|
||||
-GNinja `
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-debug" `
|
||||
-DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
|
||||
@@ -54,7 +43,7 @@ ninja install
|
||||
CheckLastExitCode
|
||||
|
||||
Write-Output "Main test suite..."
|
||||
& "stage3-debug\bin\zig.exe" build test docs `
|
||||
stage3-debug\bin\zig build test docs `
|
||||
--maxrss $ZSF_MAX_RSS `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
--search-prefix "$PREFIX_PATH" `
|
||||
@@ -66,39 +55,38 @@ Write-Output "Main test suite..."
|
||||
CheckLastExitCode
|
||||
|
||||
Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
|
||||
& "stage3-debug\bin\zig.exe" test `
|
||||
..\test\behavior.zig `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
-ofmt=c `
|
||||
-femit-bin="test-x86_64-windows-msvc.c" `
|
||||
--test-no-exec `
|
||||
-target x86_64-windows-msvc `
|
||||
-lc
|
||||
CheckLastExitCode
|
||||
|
||||
& "stage3-debug\bin\zig.exe" build-obj `
|
||||
stage3-debug\bin\zig build-obj `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
-ofmt=c `
|
||||
-OReleaseSmall `
|
||||
--name compiler_rt `
|
||||
-femit-bin="compiler_rt-x86_64-windows-msvc.c" `
|
||||
--dep build_options `
|
||||
-target x86_64-windows-msvc `
|
||||
-Mroot="..\lib\compiler_rt.zig" `
|
||||
-Mbuild_options="config.zig"
|
||||
-lc `
|
||||
..\lib\compiler_rt.zig
|
||||
CheckLastExitCode
|
||||
|
||||
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
|
||||
stage3-debug\bin\zig test `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
-ofmt=c `
|
||||
-femit-bin="behavior-x86_64-windows-msvc.c" `
|
||||
--test-no-exec `
|
||||
-target x86_64-windows-msvc `
|
||||
-lc `
|
||||
..\test\behavior.zig
|
||||
CheckLastExitCode
|
||||
|
||||
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" `
|
||||
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
|
||||
CheckLastExitCode
|
||||
|
||||
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" `
|
||||
-DevCmdArguments '-arch=x64 -no_logo' `
|
||||
-StartInPath $(Get-Location)
|
||||
CheckLastExitCode
|
||||
|
||||
Write-Output "Build and run behavior tests with msvc..."
|
||||
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
|
||||
cl /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
|
||||
CheckLastExitCode
|
||||
|
||||
& .\test-x86_64-windows-msvc.exe
|
||||
.\behavior-x86_64-windows-msvc
|
||||
CheckLastExitCode
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
$TARGET = "x86_64-windows-gnu"
|
||||
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
|
||||
$MCPU = "baseline"
|
||||
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
|
||||
$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME"
|
||||
$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
|
||||
$ZIG = "$PREFIX_PATH\bin\zig.exe"
|
||||
$ZIG_LIB_DIR = "$(Get-Location)\lib"
|
||||
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
|
||||
|
||||
if (!(Test-Path "$PREFIX_PATH.zip")) {
|
||||
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
|
||||
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip"
|
||||
|
||||
Write-Output "Extracting..."
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..")
|
||||
}
|
||||
|
||||
function CheckLastExitCode {
|
||||
if (!$?) {
|
||||
exit 1
|
||||
@@ -35,7 +24,7 @@ Set-Location -Path 'build-release'
|
||||
|
||||
# CMake gives a syntax error when file paths with backward slashes are used.
|
||||
# Here, we use forward slashes only to work around this.
|
||||
& cmake .. `
|
||||
cmake .. `
|
||||
-GNinja `
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" `
|
||||
-DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
|
||||
@@ -54,7 +43,7 @@ ninja install
|
||||
CheckLastExitCode
|
||||
|
||||
Write-Output "Main test suite..."
|
||||
& "stage3-release\bin\zig.exe" build test docs `
|
||||
stage3-release\bin\zig.exe build test docs `
|
||||
--maxrss $ZSF_MAX_RSS `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
--search-prefix "$PREFIX_PATH" `
|
||||
@@ -67,7 +56,7 @@ CheckLastExitCode
|
||||
|
||||
# Ensure that stage3 and stage4 are byte-for-byte identical.
|
||||
Write-Output "Build and compare stage4..."
|
||||
& "stage3-release\bin\zig.exe" build `
|
||||
stage3-release\bin\zig.exe build `
|
||||
--prefix stage4-release `
|
||||
-Denable-llvm `
|
||||
-Dno-lib `
|
||||
@@ -85,39 +74,38 @@ Compare-Object (Get-Content stage3-release\bin\zig.exe) (Get-Content stage4-rele
|
||||
CheckLastExitCode
|
||||
|
||||
Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
|
||||
& "stage3-release\bin\zig.exe" test `
|
||||
..\test\behavior.zig `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
-ofmt=c `
|
||||
-femit-bin="test-x86_64-windows-msvc.c" `
|
||||
--test-no-exec `
|
||||
-target x86_64-windows-msvc `
|
||||
-lc
|
||||
CheckLastExitCode
|
||||
|
||||
& "stage3-release\bin\zig.exe" build-obj `
|
||||
stage3-release\bin\zig.exe build-obj `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
-ofmt=c `
|
||||
-OReleaseSmall `
|
||||
--name compiler_rt `
|
||||
-femit-bin="compiler_rt-x86_64-windows-msvc.c" `
|
||||
--dep build_options `
|
||||
-target x86_64-windows-msvc `
|
||||
-Mroot="..\lib\compiler_rt.zig" `
|
||||
-Mbuild_options="config.zig"
|
||||
-lc `
|
||||
..\lib\compiler_rt.zig
|
||||
CheckLastExitCode
|
||||
|
||||
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
|
||||
stage3-release\bin\zig.exe test `
|
||||
--zig-lib-dir "$ZIG_LIB_DIR" `
|
||||
-ofmt=c `
|
||||
-femit-bin="behavior-x86_64-windows-msvc.c" `
|
||||
--test-no-exec `
|
||||
-target x86_64-windows-msvc `
|
||||
-lc `
|
||||
..\test\behavior.zig
|
||||
CheckLastExitCode
|
||||
|
||||
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" `
|
||||
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
|
||||
CheckLastExitCode
|
||||
|
||||
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" `
|
||||
-DevCmdArguments '-arch=x64 -no_logo' `
|
||||
-StartInPath $(Get-Location)
|
||||
CheckLastExitCode
|
||||
|
||||
Write-Output "Build and run behavior tests with msvc..."
|
||||
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
|
||||
cl /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
|
||||
CheckLastExitCode
|
||||
|
||||
& .\test-x86_64-windows-msvc.exe
|
||||
.\behavior-x86_64-windows-msvc
|
||||
CheckLastExitCode
|
||||
|
||||
+43
-5
@@ -128,6 +128,7 @@
|
||||
}
|
||||
.table-wrapper {
|
||||
width: 100%;
|
||||
margin: 1em auto;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
@@ -2102,8 +2103,9 @@ or
|
||||
less than {#syntax#}1 << 29{#endsyntax#}.
|
||||
</p>
|
||||
<p>
|
||||
In Zig, a pointer type has an alignment value. If the value is equal to the
|
||||
alignment of the underlying type, it can be omitted from the type:
|
||||
Pointer types may explicitly specify an alignment in bytes. If it is not
|
||||
specified, the alignment is assumed to be equal to the alignment of the
|
||||
underlying type.
|
||||
</p>
|
||||
{#code|test_variable_alignment.zig#}
|
||||
|
||||
@@ -3471,6 +3473,42 @@ void do_a_thing(struct Foo *foo) {
|
||||
without rounding (i.e. the integer's precision does not exceed the float's significand precision).
|
||||
Larger integer types that cannot be safely coerced must be explicitly casted with {#link|@floatFromInt#}.
|
||||
</p>
|
||||
<div class="table-wrapper">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Float Type</th>
|
||||
<th scope="col">Largest Integer Types</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">{#syntax#}f16{#endsyntax#}</th>
|
||||
<td>{#syntax#}i12{#endsyntax#} and {#syntax#}u11{#endsyntax#}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{#syntax#}f32{#endsyntax#}</th>
|
||||
<td>{#syntax#}i25{#endsyntax#} and {#syntax#}u24{#endsyntax#}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{#syntax#}f64{#endsyntax#}</th>
|
||||
<td>{#syntax#}i54{#endsyntax#} and {#syntax#}u53{#endsyntax#}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{#syntax#}f80{#endsyntax#}</th>
|
||||
<td>{#syntax#}i65{#endsyntax#} and {#syntax#}u64{#endsyntax#}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{#syntax#}f128{#endsyntax#}</th>
|
||||
<td>{#syntax#}i114{#endsyntax#} and {#syntax#}u113{#endsyntax#}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{#syntax#}c_longdouble{#endsyntax#}</th>
|
||||
<td>Varies by target</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{#code|test_int_to_float_coercion.zig#}
|
||||
{#code|test_failed_int_to_float_coercion.zig#}
|
||||
|
||||
@@ -4828,7 +4866,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@errorFromInt#}
|
||||
<pre>{#syntax#}@errorFromInt(value: std.meta.Int(.unsigned, @bitSizeOf(anyerror))) anyerror{#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@errorFromInt(value: @Int(.unsigned, @bitSizeOf(anyerror))) anyerror{#endsyntax#}</pre>
|
||||
<p>
|
||||
Converts from the integer representation of an error into {#link|The Global Error Set#} type.
|
||||
</p>
|
||||
@@ -5069,7 +5107,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@intFromError#}
|
||||
<pre>{#syntax#}@intFromError(err: anytype) std.meta.Int(.unsigned, @bitSizeOf(anyerror)){#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@intFromError(err: anytype) @Int(.unsigned, @bitSizeOf(anyerror)){#endsyntax#}</pre>
|
||||
<p>
|
||||
Supports the following types:
|
||||
</p>
|
||||
@@ -6330,7 +6368,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
|
||||
</p>
|
||||
<p>
|
||||
Zig has a general purpose allocator available to be imported
|
||||
with {#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#}. However, it is still recommended to
|
||||
with {#syntax#}std.heap.DebugAllocator{#endsyntax#}. However, it is still recommended to
|
||||
follow the {#link|Choosing an Allocator#} guide.
|
||||
</p>
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@ pub const CallModifier = enum {
|
||||
/// Equivalent to function call syntax.
|
||||
auto,
|
||||
|
||||
/// Equivalent to async keyword used with function call syntax.
|
||||
async_kw,
|
||||
|
||||
/// Prevents tail call optimization. This guarantees that the return
|
||||
/// address will point to the callsite, as opposed to the callsite's
|
||||
/// callsite. If the call is otherwise required to be tail-called
|
||||
@@ -17,7 +14,7 @@ pub const CallModifier = enum {
|
||||
|
||||
/// Asserts that the function call will not suspend. This allows a
|
||||
/// non-async function to call an async function.
|
||||
no_async,
|
||||
no_suspend,
|
||||
|
||||
/// Guarantees that the call will be generated with tail call optimization.
|
||||
/// If this is not possible, a compile error is emitted instead.
|
||||
|
||||
@@ -4,6 +4,7 @@ const c = @cImport({
|
||||
@cInclude("stdio.h");
|
||||
});
|
||||
pub fn main() void {
|
||||
if (@import("builtin").os.tag == .netbsd) return; // https://github.com/Vexu/arocc/issues/960
|
||||
_ = c.printf("hello\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ fn charToDigit(c: u8) u8 {
|
||||
|
||||
test "parse u64" {
|
||||
const result = try parseU64("1234", 10);
|
||||
try std.testing.expect(result == 1234);
|
||||
try std.testing.expectEqual(1234, result);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
test "attempt to swap array elements with array initializer" {
|
||||
var arr: [2]u32 = .{ 1, 2 };
|
||||
arr = .{ arr[1], arr[0] };
|
||||
@@ -6,8 +6,8 @@ test "attempt to swap array elements with array initializer" {
|
||||
// arr[0] = arr[1];
|
||||
// arr[1] = arr[0];
|
||||
// So this fails!
|
||||
try expect(arr[0] == 2); // succeeds
|
||||
try expect(arr[1] == 1); // fails
|
||||
try expectEqual(2, arr[0]); // succeeds
|
||||
try expectEqual(1, arr[1]); // fails
|
||||
}
|
||||
|
||||
// test_error=
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "no runtime side effects" {
|
||||
var data: i32 = 0;
|
||||
const T = @TypeOf(foo(i32, &data));
|
||||
try comptime expect(T == i32);
|
||||
try expect(data == 0);
|
||||
try comptime expectEqual(i32, T);
|
||||
try expectEqual(0, data);
|
||||
}
|
||||
|
||||
fn foo(comptime T: type, ptr: *T) T {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const expect = std.testing.expect;
|
||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
||||
|
||||
test "using an allocator" {
|
||||
var buffer: [100]u8 = undefined;
|
||||
var fba = std.heap.FixedBufferAllocator.init(&buffer);
|
||||
const allocator = fba.allocator();
|
||||
const result = try concat(allocator, "foo", "bar");
|
||||
try expect(std.mem.eql(u8, "foobar", result));
|
||||
try expectEqualStrings("foobar", result);
|
||||
}
|
||||
|
||||
fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "allowzero" {
|
||||
var zero: usize = 0; // var to make to runtime-known
|
||||
_ = &zero; // suppress 'var is never mutated' error
|
||||
const ptr: *allowzero i32 = @ptrFromInt(zero);
|
||||
try expect(@intFromPtr(ptr) == 0);
|
||||
try expectEqual(0, @intFromPtr(ptr));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "fully anonymous struct" {
|
||||
try check(.{
|
||||
@@ -11,11 +12,11 @@ test "fully anonymous struct" {
|
||||
}
|
||||
|
||||
fn check(args: anytype) !void {
|
||||
try expect(args.int == 1234);
|
||||
try expect(args.float == 12.34);
|
||||
try expectEqual(1234, args.int);
|
||||
try expectEqual(12.34, args.float);
|
||||
try expect(args.b);
|
||||
try expect(args.s[0] == 'h');
|
||||
try expect(args.s[1] == 'i');
|
||||
try expectEqual('h', args.s[0]);
|
||||
try expectEqual('i', args.s[1]);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const Number = union {
|
||||
int: i32,
|
||||
@@ -9,8 +9,8 @@ const Number = union {
|
||||
test "anonymous union literal syntax" {
|
||||
const i: Number = .{ .int = 42 };
|
||||
const f = makeNumber();
|
||||
try expect(i.int == 42);
|
||||
try expect(f.float == 12.34);
|
||||
try expectEqual(42, i.int);
|
||||
try expectEqual(12.34, f.float);
|
||||
}
|
||||
|
||||
fn makeNumber() Number {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
const assert = @import("std").debug.assert;
|
||||
const mem = @import("std").mem;
|
||||
|
||||
@@ -29,7 +29,7 @@ test "iterate over an array" {
|
||||
for (message) |byte| {
|
||||
sum += byte;
|
||||
}
|
||||
try expect(sum == 'h' + 'e' + 'l' * 2 + 'o');
|
||||
try expectEqual('h' + 'e' + 'l' * 2 + 'o', sum);
|
||||
}
|
||||
|
||||
// modifiable array
|
||||
@@ -39,8 +39,8 @@ test "modify an array" {
|
||||
for (&some_integers, 0..) |*item, i| {
|
||||
item.* = @intCast(i);
|
||||
}
|
||||
try expect(some_integers[10] == 10);
|
||||
try expect(some_integers[99] == 99);
|
||||
try expectEqual(10, some_integers[10]);
|
||||
try expectEqual(99, some_integers[99]);
|
||||
}
|
||||
|
||||
// array concatenation works if the values are known
|
||||
@@ -91,8 +91,8 @@ const Point = struct {
|
||||
};
|
||||
|
||||
test "compile-time array initialization" {
|
||||
try expect(fancy_array[4].x == 4);
|
||||
try expect(fancy_array[4].y == 8);
|
||||
try expectEqual(4, fancy_array[4].x);
|
||||
try expectEqual(8, fancy_array[4].y);
|
||||
}
|
||||
|
||||
// call a function to initialize an array
|
||||
@@ -104,9 +104,9 @@ fn makePoint(x: i32) Point {
|
||||
};
|
||||
}
|
||||
test "array initialization with function calls" {
|
||||
try expect(more_points[4].x == 3);
|
||||
try expect(more_points[4].y == 6);
|
||||
try expect(more_points.len == 10);
|
||||
try expectEqual(3, more_points[4].x);
|
||||
try expectEqual(6, more_points[4].y);
|
||||
try expectEqual(10, more_points.len);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
const expectEqualSlices = @import("std").testing.expectEqualSlices;
|
||||
|
||||
test "basic slices" {
|
||||
@@ -12,14 +12,14 @@ test "basic slices" {
|
||||
|
||||
try expectEqualSlices(i32, slice, alt_slice);
|
||||
|
||||
try expect(@TypeOf(slice) == []i32);
|
||||
try expect(&slice[0] == &array[0]);
|
||||
try expect(slice.len == array.len);
|
||||
try expectEqual([]i32, @TypeOf(slice));
|
||||
try expectEqual(&array[0], &slice[0]);
|
||||
try expectEqual(array.len, slice.len);
|
||||
|
||||
// If you slice with comptime-known start and end positions, the result is
|
||||
// a pointer to an array, rather than a slice.
|
||||
const array_ptr = array[0..array.len];
|
||||
try expect(@TypeOf(array_ptr) == *[array.len]i32);
|
||||
try expectEqual(*[array.len]i32, @TypeOf(array_ptr));
|
||||
|
||||
// You can perform a slice-by-length by slicing twice. This allows the compiler
|
||||
// to perform some optimisations like recognising a comptime-known length when
|
||||
@@ -28,13 +28,13 @@ test "basic slices" {
|
||||
_ = &runtime_start;
|
||||
const length = 2;
|
||||
const array_ptr_len = array[runtime_start..][0..length];
|
||||
try expect(@TypeOf(array_ptr_len) == *[length]i32);
|
||||
try expectEqual(*[length]i32, @TypeOf(array_ptr_len));
|
||||
|
||||
// Using the address-of operator on a slice gives a single-item pointer.
|
||||
try expect(@TypeOf(&slice[0]) == *i32);
|
||||
try expectEqual(*i32, @TypeOf(&slice[0]));
|
||||
// Using the `ptr` field gives a many-item pointer.
|
||||
try expect(@TypeOf(slice.ptr) == [*]i32);
|
||||
try expect(@intFromPtr(slice.ptr) == @intFromPtr(&slice[0]));
|
||||
try expectEqual([*]i32, @TypeOf(slice.ptr));
|
||||
try expectEqual(@intFromPtr(slice.ptr), @intFromPtr(&slice[0]));
|
||||
|
||||
// Slices have array bounds checking. If you try to access something out
|
||||
// of bounds, you'll get a safety check failure:
|
||||
@@ -47,8 +47,8 @@ test "basic slices" {
|
||||
const empty1 = &[0]u8{};
|
||||
// If the type is known you can use this short hand:
|
||||
const empty2: []u8 = &.{};
|
||||
try expect(empty1.len == 0);
|
||||
try expect(empty2.len == 0);
|
||||
try expectEqual(0, empty1.len);
|
||||
try expectEqual(0, empty2.len);
|
||||
|
||||
// A zero-length initialization can always be used to create an empty slice, even if the slice is mutable.
|
||||
// This is because the pointed-to data is zero bits long, so its immutability is irrelevant.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const BitField = packed struct {
|
||||
a: u3,
|
||||
@@ -9,13 +9,13 @@ const BitField = packed struct {
|
||||
|
||||
test "offsets of non-byte-aligned fields" {
|
||||
comptime {
|
||||
try expect(@bitOffsetOf(BitField, "a") == 0);
|
||||
try expect(@bitOffsetOf(BitField, "b") == 3);
|
||||
try expect(@bitOffsetOf(BitField, "c") == 6);
|
||||
try expectEqual(0, @bitOffsetOf(BitField, "a"));
|
||||
try expectEqual(3, @bitOffsetOf(BitField, "b"));
|
||||
try expectEqual(6, @bitOffsetOf(BitField, "c"));
|
||||
|
||||
try expect(@offsetOf(BitField, "a") == 0);
|
||||
try expect(@offsetOf(BitField, "b") == 0);
|
||||
try expect(@offsetOf(BitField, "c") == 0);
|
||||
try expectEqual(0, @offsetOf(BitField, "a"));
|
||||
try expectEqual(0, @offsetOf(BitField, "b"));
|
||||
try expectEqual(0, @offsetOf(BitField, "c"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "noinline function call" {
|
||||
try expect(@call(.auto, add, .{ 3, 9 }) == 12);
|
||||
try expectEqual(12, @call(.auto, add, .{ 3, 9 }));
|
||||
}
|
||||
|
||||
fn add(a: i32, b: i32) i32 {
|
||||
|
||||
@@ -12,7 +12,7 @@ const AllocationError = error{
|
||||
|
||||
test "coerce subset to superset" {
|
||||
const err = foo(AllocationError.OutOfMemory);
|
||||
try std.testing.expect(err == FileOpenError.OutOfMemory);
|
||||
try std.testing.expectEqual(FileOpenError.OutOfMemory, err);
|
||||
}
|
||||
|
||||
fn foo(err: AllocationError) FileOpenError {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "coercing large integer type to smaller one when value is comptime-known to fit" {
|
||||
const x: u64 = 255;
|
||||
const y: u8 = x;
|
||||
try expect(y == 255);
|
||||
try expectEqual(255, y);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "coerce to optionals wrapped in error union" {
|
||||
const x: anyerror!?i32 = 1234;
|
||||
const y: anyerror!?i32 = null;
|
||||
|
||||
try expect((try x).? == 1234);
|
||||
try expect((try y) == null);
|
||||
try expectEqual(1234, (try x).?);
|
||||
try expectEqual(null, (try y));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "coerce to optionals" {
|
||||
const x: ?i32 = 1234;
|
||||
const y: ?i32 = null;
|
||||
|
||||
try expect(x.? == 1234);
|
||||
try expect(y == null);
|
||||
try expectEqual(1234, x.?);
|
||||
try expectEqual(null, y);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
||||
const expectEqualSlices = std.testing.expectEqualSlices;
|
||||
|
||||
// You can assign constant pointers to arrays to a slice with
|
||||
// const modifier on the element type. Useful in particular for
|
||||
@@ -7,48 +9,48 @@ const expect = std.testing.expect;
|
||||
test "*const [N]T to []const T" {
|
||||
const x1: []const u8 = "hello";
|
||||
const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
|
||||
try expect(std.mem.eql(u8, x1, x2));
|
||||
try expectEqualStrings(x1, x2);
|
||||
|
||||
const y: []const f32 = &[2]f32{ 1.2, 3.4 };
|
||||
try expect(y[0] == 1.2);
|
||||
try expectEqual(1.2, y[0]);
|
||||
}
|
||||
|
||||
// Likewise, it works when the destination type is an error union.
|
||||
test "*const [N]T to E![]const T" {
|
||||
const x1: anyerror![]const u8 = "hello";
|
||||
const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
|
||||
try expect(std.mem.eql(u8, try x1, try x2));
|
||||
try expectEqualStrings(try x1, try x2);
|
||||
|
||||
const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
|
||||
try expect((try y)[0] == 1.2);
|
||||
try expectEqual(1.2, (try y)[0]);
|
||||
}
|
||||
|
||||
// Likewise, it works when the destination type is an optional.
|
||||
test "*const [N]T to ?[]const T" {
|
||||
const x1: ?[]const u8 = "hello";
|
||||
const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
|
||||
try expect(std.mem.eql(u8, x1.?, x2.?));
|
||||
try expectEqualStrings(x1.?, x2.?);
|
||||
|
||||
const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
|
||||
try expect(y.?[0] == 1.2);
|
||||
try expectEqual(1.2, y.?[0]);
|
||||
}
|
||||
|
||||
// In this cast, the array length becomes the slice length.
|
||||
test "*[N]T to []T" {
|
||||
var buf: [5]u8 = "hello".*;
|
||||
const x: []u8 = &buf;
|
||||
try expect(std.mem.eql(u8, x, "hello"));
|
||||
try expectEqualStrings("hello", x);
|
||||
|
||||
const buf2 = [2]f32{ 1.2, 3.4 };
|
||||
const x2: []const f32 = &buf2;
|
||||
try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
|
||||
try expectEqualSlices(f32, &[2]f32{ 1.2, 3.4 }, x2);
|
||||
}
|
||||
|
||||
// Single-item pointers to arrays can be coerced to many-item pointers.
|
||||
test "*[N]T to [*]T" {
|
||||
var buf: [5]u8 = "hello".*;
|
||||
const x: [*]u8 = &buf;
|
||||
try expect(x[4] == 'o');
|
||||
try expectEqual('o', x[4]);
|
||||
// x[5] would be an uncaught out of bounds pointer dereference!
|
||||
}
|
||||
|
||||
@@ -56,7 +58,7 @@ test "*[N]T to [*]T" {
|
||||
test "*[N]T to ?[*]T" {
|
||||
var buf: [5]u8 = "hello".*;
|
||||
const x: ?[*]u8 = &buf;
|
||||
try expect(x.?[4] == 'o');
|
||||
try expectEqual('o', x.?[4]);
|
||||
}
|
||||
|
||||
// Single-item pointers can be cast to len-1 single-item arrays.
|
||||
@@ -64,14 +66,14 @@ test "*T to *[1]T" {
|
||||
var x: i32 = 1234;
|
||||
const y: *[1]i32 = &x;
|
||||
const z: [*]i32 = y;
|
||||
try expect(z[0] == 1234);
|
||||
try expectEqual(1234, z[0]);
|
||||
}
|
||||
|
||||
// Sentinel-terminated slices can be coerced into sentinel-terminated pointers
|
||||
test "[:x]T to [*:x]T" {
|
||||
const buf: [:0]const u8 = "hello";
|
||||
const buf2: [*:0]const u8 = buf;
|
||||
try expect(buf2[4] == 'o');
|
||||
try expectEqual('o', buf2[4]);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "coercion to error unions" {
|
||||
const x: anyerror!i32 = 1234;
|
||||
const y: anyerror!i32 = error.Failure;
|
||||
|
||||
try expect((try x) == 1234);
|
||||
try expectEqual(1234, (try x));
|
||||
try std.testing.expectError(error.Failure, y);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const Tuple = struct { u8, u8 };
|
||||
test "coercion from homogeneous tuple to array" {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const E = enum {
|
||||
one,
|
||||
@@ -28,22 +28,22 @@ const U2 = union(enum) {
|
||||
test "coercion between unions and enums" {
|
||||
const u = U{ .two = 12.34 };
|
||||
const e: E = u; // coerce union to enum
|
||||
try expect(e == E.two);
|
||||
try expectEqual(E.two, e);
|
||||
|
||||
const three = E.three;
|
||||
const u_2: U = three; // coerce enum to union
|
||||
try expect(u_2 == E.three);
|
||||
try expectEqual(E.three, u_2);
|
||||
|
||||
const u_3: U = .three; // coerce enum literal to union
|
||||
try expect(u_3 == E.three);
|
||||
try expectEqual(E.three, u_3);
|
||||
|
||||
const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.
|
||||
try expect(u_4.tag() == 1);
|
||||
try expectEqual(1, u_4.tag());
|
||||
|
||||
// The following example is invalid.
|
||||
// error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
|
||||
//var u_5: U2 = .b;
|
||||
//try expect(u_5.tag() == 2);
|
||||
//try expectEqual(2, u_5.tag());
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
const CmdFn = struct {
|
||||
name: []const u8,
|
||||
@@ -32,9 +32,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
|
||||
}
|
||||
|
||||
test "perform fn" {
|
||||
try expect(performFn('t', 1) == 6);
|
||||
try expect(performFn('o', 0) == 1);
|
||||
try expect(performFn('w', 99) == 99);
|
||||
try expectEqual(6, performFn('t', 1));
|
||||
try expectEqual(1, performFn('o', 0));
|
||||
try expectEqual(99, performFn('w', 99));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
comptime {
|
||||
const err = error.AnError;
|
||||
const number = @intFromError(err) + 10;
|
||||
const invalid_err = @errorFromInt(number);
|
||||
_ = invalid_err;
|
||||
_ = @errorFromInt(12345);
|
||||
}
|
||||
|
||||
// test_error=integer value '11' represents no error
|
||||
// test_error=integer value '12345' represents no error
|
||||
|
||||
@@ -8,7 +8,7 @@ fn max(comptime T: type, a: T, b: T) T {
|
||||
}
|
||||
}
|
||||
test "try to compare bools" {
|
||||
try @import("std").testing.expect(max(bool, false, true) == true);
|
||||
try @import("std").testing.expectEqual(true, max(bool, false, true));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "comptime @ptrFromInt" {
|
||||
comptime {
|
||||
@@ -6,8 +6,8 @@ test "comptime @ptrFromInt" {
|
||||
// ptr is never dereferenced.
|
||||
const ptr: *i32 = @ptrFromInt(0xdeadbee0);
|
||||
const addr = @intFromPtr(ptr);
|
||||
try expect(@TypeOf(addr) == usize);
|
||||
try expect(addr == 0xdeadbee0);
|
||||
try expectEqual(usize, @TypeOf(addr));
|
||||
try expectEqual(0xdeadbee0, addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "comptime pointers" {
|
||||
comptime {
|
||||
@@ -6,7 +6,7 @@ test "comptime pointers" {
|
||||
const ptr = &x;
|
||||
ptr.* += 1;
|
||||
x += 1;
|
||||
try expect(ptr.* == 3);
|
||||
try expectEqual(3, ptr.*);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "comptime vars" {
|
||||
var x: i32 = 1;
|
||||
@@ -8,8 +8,8 @@ test "comptime vars" {
|
||||
x += 1;
|
||||
y += 1;
|
||||
|
||||
try expect(x == 2);
|
||||
try expect(y == 2);
|
||||
try expectEqual(2, x);
|
||||
try expectEqual(2, y);
|
||||
|
||||
if (y != 2) {
|
||||
// This compile error never triggers because y is a comptime variable,
|
||||
|
||||
@@ -31,7 +31,7 @@ fn sum(numbers: []const i32) i32 {
|
||||
}
|
||||
|
||||
test "variable values" {
|
||||
try @import("std").testing.expect(sum_of_first_25_primes == 1060);
|
||||
try @import("std").testing.expectEqual(1060, sum_of_first_25_primes);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -2,8 +2,8 @@ var y: i32 = add(10, x);
|
||||
const x: i32 = add(12, 34);
|
||||
|
||||
test "container level variables" {
|
||||
try expect(x == 46);
|
||||
try expect(y == 56);
|
||||
try expectEqual(46, x);
|
||||
try expectEqual(56, y);
|
||||
}
|
||||
|
||||
fn add(a: i32, b: i32) i32 {
|
||||
@@ -11,6 +11,6 @@ fn add(a: i32, b: i32) i32 {
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const print = std.debug.print;
|
||||
|
||||
fn deferExample() !usize {
|
||||
@@ -9,14 +9,14 @@ fn deferExample() !usize {
|
||||
defer a = 2;
|
||||
a = 1;
|
||||
}
|
||||
try expect(a == 2);
|
||||
try expectEqual(2, a);
|
||||
|
||||
a = 5;
|
||||
return a;
|
||||
}
|
||||
|
||||
test "defer basics" {
|
||||
try expect((try deferExample()) == 5);
|
||||
try expectEqual(5, (try deferExample()));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test {
|
||||
const a = {};
|
||||
const b = void{};
|
||||
try expect(@TypeOf(a) == void);
|
||||
try expect(@TypeOf(b) == void);
|
||||
try expect(a == b);
|
||||
try expectEqual(void, @TypeOf(a));
|
||||
try expectEqual(void, @TypeOf(b));
|
||||
try expectEqual(a, b);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const Color = enum {
|
||||
auto,
|
||||
@@ -10,7 +11,7 @@ const Color = enum {
|
||||
test "enum literals" {
|
||||
const color1: Color = .auto;
|
||||
const color2 = Color.auto;
|
||||
try expect(color1 == color2);
|
||||
try expectEqual(color1, color2);
|
||||
}
|
||||
|
||||
test "switch using enum literals" {
|
||||
|
||||
+18
-16
@@ -1,4 +1,6 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
const expectEqualStrings = @import("std").testing.expectEqualStrings;
|
||||
const mem = @import("std").mem;
|
||||
|
||||
// Declare an enum.
|
||||
@@ -20,9 +22,9 @@ const Value = enum(u2) {
|
||||
// Now you can cast between u2 and Value.
|
||||
// The ordinal value starts from 0, counting up by 1 from the previous member.
|
||||
test "enum ordinal value" {
|
||||
try expect(@intFromEnum(Value.zero) == 0);
|
||||
try expect(@intFromEnum(Value.one) == 1);
|
||||
try expect(@intFromEnum(Value.two) == 2);
|
||||
try expectEqual(0, @intFromEnum(Value.zero));
|
||||
try expectEqual(1, @intFromEnum(Value.one));
|
||||
try expectEqual(2, @intFromEnum(Value.two));
|
||||
}
|
||||
|
||||
// You can override the ordinal value for an enum.
|
||||
@@ -32,9 +34,9 @@ const Value2 = enum(u32) {
|
||||
million = 1000000,
|
||||
};
|
||||
test "set enum ordinal value" {
|
||||
try expect(@intFromEnum(Value2.hundred) == 100);
|
||||
try expect(@intFromEnum(Value2.thousand) == 1000);
|
||||
try expect(@intFromEnum(Value2.million) == 1000000);
|
||||
try expectEqual(100, @intFromEnum(Value2.hundred));
|
||||
try expectEqual(1000, @intFromEnum(Value2.thousand));
|
||||
try expectEqual(1000000, @intFromEnum(Value2.million));
|
||||
}
|
||||
|
||||
// You can also override only some values.
|
||||
@@ -46,11 +48,11 @@ const Value3 = enum(u4) {
|
||||
e,
|
||||
};
|
||||
test "enum implicit ordinal values and overridden values" {
|
||||
try expect(@intFromEnum(Value3.a) == 0);
|
||||
try expect(@intFromEnum(Value3.b) == 8);
|
||||
try expect(@intFromEnum(Value3.c) == 9);
|
||||
try expect(@intFromEnum(Value3.d) == 4);
|
||||
try expect(@intFromEnum(Value3.e) == 5);
|
||||
try expectEqual(0, @intFromEnum(Value3.a));
|
||||
try expectEqual(8, @intFromEnum(Value3.b));
|
||||
try expectEqual(9, @intFromEnum(Value3.c));
|
||||
try expectEqual(4, @intFromEnum(Value3.d));
|
||||
try expectEqual(5, @intFromEnum(Value3.e));
|
||||
}
|
||||
|
||||
// Enums can have methods, the same as structs and unions.
|
||||
@@ -84,7 +86,7 @@ test "enum switch" {
|
||||
Foo.number => "this is a number",
|
||||
Foo.none => "this is a none",
|
||||
};
|
||||
try expect(mem.eql(u8, what_is_it, "this is a number"));
|
||||
try expectEqualStrings(what_is_it, "this is a number");
|
||||
}
|
||||
|
||||
// @typeInfo can be used to access the integer tag type of an enum.
|
||||
@@ -95,18 +97,18 @@ const Small = enum {
|
||||
four,
|
||||
};
|
||||
test "std.meta.Tag" {
|
||||
try expect(@typeInfo(Small).@"enum".tag_type == u2);
|
||||
try expectEqual(u2, @typeInfo(Small).@"enum".tag_type);
|
||||
}
|
||||
|
||||
// @typeInfo tells us the field count and the fields names:
|
||||
test "@typeInfo" {
|
||||
try expect(@typeInfo(Small).@"enum".fields.len == 4);
|
||||
try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two"));
|
||||
try expectEqual(4, @typeInfo(Small).@"enum".fields.len);
|
||||
try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two");
|
||||
}
|
||||
|
||||
// @tagName gives a [:0]const u8 representation of an enum value:
|
||||
test "@tagName" {
|
||||
try expect(mem.eql(u8, @tagName(Small.three), "three"));
|
||||
try expectEqualStrings(@tagName(Small.three), "three");
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "error union" {
|
||||
var foo: anyerror!i32 = undefined;
|
||||
@@ -10,10 +10,10 @@ test "error union" {
|
||||
foo = error.SomeError;
|
||||
|
||||
// Use compile-time reflection to access the payload type of an error union:
|
||||
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32);
|
||||
try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).error_union.payload);
|
||||
|
||||
// Use compile-time reflection to access the error set type of an error union:
|
||||
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror);
|
||||
try comptime expectEqual(anyerror, @typeInfo(@TypeOf(foo)).error_union.error_set);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
fn fibonacci(index: u32) u32 {
|
||||
//if (index < 2) return index;
|
||||
@@ -6,7 +6,7 @@ fn fibonacci(index: u32) u32 {
|
||||
}
|
||||
|
||||
test "fibonacci" {
|
||||
try comptime expect(fibonacci(7) == 13);
|
||||
try comptime expectEqual(13, fibonacci(7));
|
||||
}
|
||||
|
||||
// test_error=overflow of integer type
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
fn fibonacci(index: u32) u32 {
|
||||
if (index < 2) return index;
|
||||
@@ -7,10 +7,10 @@ fn fibonacci(index: u32) u32 {
|
||||
|
||||
test "fibonacci" {
|
||||
// test fibonacci at run-time
|
||||
try expect(fibonacci(7) == 13);
|
||||
try expectEqual(13, fibonacci(7));
|
||||
|
||||
// test fibonacci at compile-time
|
||||
try comptime expect(fibonacci(7) == 13);
|
||||
try comptime expectEqual(13, fibonacci(7));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const Point = struct {
|
||||
x: u32,
|
||||
@@ -8,23 +9,20 @@ const Point = struct {
|
||||
};
|
||||
|
||||
test "field access by string" {
|
||||
const expect = std.testing.expect;
|
||||
var p = Point{ .x = 0, .y = 0 };
|
||||
|
||||
@field(p, "x") = 4;
|
||||
@field(p, "y") = @field(p, "x") + 1;
|
||||
|
||||
try expect(@field(p, "x") == 4);
|
||||
try expect(@field(p, "y") == 5);
|
||||
try expectEqual(4, @field(p, "x"));
|
||||
try expectEqual(5, @field(p, "y"));
|
||||
}
|
||||
|
||||
test "decl access by string" {
|
||||
const expect = std.testing.expect;
|
||||
|
||||
try expect(@field(Point, "z") == 1);
|
||||
try expectEqual(1, @field(Point, "z"));
|
||||
|
||||
@field(Point, "z") = 2;
|
||||
try expect(@field(Point, "z") == 2);
|
||||
try expectEqual(2, @field(Point, "z"));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -3,8 +3,8 @@ const math = std.math;
|
||||
const testing = std.testing;
|
||||
|
||||
test "fn reflection" {
|
||||
try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool);
|
||||
try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir);
|
||||
try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.?);
|
||||
try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?);
|
||||
|
||||
try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
fn addFortyTwo(x: anytype) @TypeOf(x) {
|
||||
return x + 42;
|
||||
}
|
||||
|
||||
test "fn type inference" {
|
||||
try expect(addFortyTwo(1) == 43);
|
||||
try expect(@TypeOf(addFortyTwo(1)) == comptime_int);
|
||||
try expectEqual(43, addFortyTwo(1));
|
||||
try expectEqual(comptime_int, @TypeOf(addFortyTwo(1)));
|
||||
const y: i64 = 2;
|
||||
try expect(addFortyTwo(y) == 44);
|
||||
try expect(@TypeOf(addFortyTwo(y)) == i64);
|
||||
try expectEqual(44, addFortyTwo(y));
|
||||
try expectEqual(i64, @TypeOf(addFortyTwo(y)));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
+12
-12
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "for basics" {
|
||||
const items = [_]i32{ 4, 5, 3, 4, 0 };
|
||||
@@ -12,22 +12,22 @@ test "for basics" {
|
||||
}
|
||||
sum += value;
|
||||
}
|
||||
try expect(sum == 16);
|
||||
try expectEqual(16, sum);
|
||||
|
||||
// To iterate over a portion of a slice, reslice.
|
||||
for (items[0..1]) |value| {
|
||||
sum += value;
|
||||
}
|
||||
try expect(sum == 20);
|
||||
try expectEqual(20, sum);
|
||||
|
||||
// To access the index of iteration, specify a second condition as well
|
||||
// as a second capture value.
|
||||
var sum2: i32 = 0;
|
||||
for (items, 0..) |_, i| {
|
||||
try expect(@TypeOf(i) == usize);
|
||||
try expectEqual(usize, @TypeOf(i));
|
||||
sum2 += @as(i32, @intCast(i));
|
||||
}
|
||||
try expect(sum2 == 10);
|
||||
try expectEqual(10, sum2);
|
||||
|
||||
// To iterate over consecutive integers, use the range syntax.
|
||||
// Unbounded range is always a compile error.
|
||||
@@ -35,7 +35,7 @@ test "for basics" {
|
||||
for (0..5) |i| {
|
||||
sum3 += i;
|
||||
}
|
||||
try expect(sum3 == 10);
|
||||
try expectEqual(10, sum3);
|
||||
}
|
||||
|
||||
test "multi object for" {
|
||||
@@ -50,7 +50,7 @@ test "multi object for" {
|
||||
count += i + j;
|
||||
}
|
||||
|
||||
try expect(count == 21);
|
||||
try expectEqual(21, count);
|
||||
}
|
||||
|
||||
test "for reference" {
|
||||
@@ -62,9 +62,9 @@ test "for reference" {
|
||||
value.* += 1;
|
||||
}
|
||||
|
||||
try expect(items[0] == 4);
|
||||
try expect(items[1] == 5);
|
||||
try expect(items[2] == 3);
|
||||
try expectEqual(4, items[0]);
|
||||
try expectEqual(5, items[1]);
|
||||
try expectEqual(3, items[2]);
|
||||
}
|
||||
|
||||
test "for else" {
|
||||
@@ -79,10 +79,10 @@ test "for else" {
|
||||
sum += value.?;
|
||||
}
|
||||
} else blk: {
|
||||
try expect(sum == 12);
|
||||
try expectEqual(12, sum);
|
||||
break :blk sum;
|
||||
};
|
||||
try expect(result == 12);
|
||||
try expectEqual(12, result);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "nested break" {
|
||||
var count: usize = 0;
|
||||
@@ -9,7 +9,7 @@ test "nested break" {
|
||||
break :outer;
|
||||
}
|
||||
}
|
||||
try expect(count == 1);
|
||||
try expectEqual(1, count);
|
||||
}
|
||||
|
||||
test "nested continue" {
|
||||
@@ -21,7 +21,7 @@ test "nested continue" {
|
||||
}
|
||||
}
|
||||
|
||||
try expect(count == 8);
|
||||
try expectEqual(8, count);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const native_arch = builtin.cpu.arch;
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
// Functions are declared like this
|
||||
fn add(a: i8, b: i8) i8 {
|
||||
@@ -57,8 +57,8 @@ fn doOp(fnCall: Call2Op, op1: i8, op2: i8) i8 {
|
||||
}
|
||||
|
||||
test "function" {
|
||||
try expect(doOp(add, 5, 6) == 11);
|
||||
try expect(doOp(sub2, 5, 6) == -1);
|
||||
try expectEqual(11, doOp(add, 5, 6));
|
||||
try expectEqual(-1, doOp(sub2, 5, 6));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
comptime {
|
||||
asm (
|
||||
@@ -14,7 +14,7 @@ comptime {
|
||||
extern fn my_func(a: i32, b: i32) i32;
|
||||
|
||||
test "global assembly" {
|
||||
try expect(my_func(12, 34) == 46);
|
||||
try expectEqual(46, my_func(12, 34));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
// * anyerror!T
|
||||
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "if expression" {
|
||||
// If expressions are used instead of a ternary expression.
|
||||
const a: u32 = 5;
|
||||
const b: u32 = 4;
|
||||
const result = if (a != b) 47 else 3089;
|
||||
try expect(result == 47);
|
||||
try expectEqual(result, 47);
|
||||
}
|
||||
|
||||
test "if boolean" {
|
||||
@@ -32,7 +33,7 @@ test "if error union" {
|
||||
|
||||
const a: anyerror!u32 = 0;
|
||||
if (a) |value| {
|
||||
try expect(value == 0);
|
||||
try expectEqual(value, 0);
|
||||
} else |err| {
|
||||
_ = err;
|
||||
unreachable;
|
||||
@@ -43,17 +44,17 @@ test "if error union" {
|
||||
_ = value;
|
||||
unreachable;
|
||||
} else |err| {
|
||||
try expect(err == error.BadValue);
|
||||
try expectEqual(err, error.BadValue);
|
||||
}
|
||||
|
||||
// The else and |err| capture is strictly required.
|
||||
if (a) |value| {
|
||||
try expect(value == 0);
|
||||
try expectEqual(value, 0);
|
||||
} else |_| {}
|
||||
|
||||
// To check only the error value, use an empty block expression.
|
||||
if (b) |_| {} else |err| {
|
||||
try expect(err == error.BadValue);
|
||||
try expectEqual(err, error.BadValue);
|
||||
}
|
||||
|
||||
// Access the value by reference using a pointer capture.
|
||||
@@ -65,7 +66,7 @@ test "if error union" {
|
||||
}
|
||||
|
||||
if (c) |value| {
|
||||
try expect(value == 9);
|
||||
try expectEqual(value, 9);
|
||||
} else |_| {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "if optional" {
|
||||
// If expressions test for null.
|
||||
|
||||
const a: ?u32 = 0;
|
||||
if (a) |value| {
|
||||
try expect(value == 0);
|
||||
try expectEqual(0, value);
|
||||
} else {
|
||||
unreachable;
|
||||
}
|
||||
@@ -19,7 +20,7 @@ test "if optional" {
|
||||
|
||||
// The else is not required.
|
||||
if (a) |value| {
|
||||
try expect(value == 0);
|
||||
try expectEqual(0, value);
|
||||
}
|
||||
|
||||
// To test against null only, use the binary equality operator.
|
||||
@@ -34,7 +35,7 @@ test "if optional" {
|
||||
}
|
||||
|
||||
if (c) |value| {
|
||||
try expect(value == 2);
|
||||
try expectEqual(2, value);
|
||||
} else {
|
||||
unreachable;
|
||||
}
|
||||
@@ -46,7 +47,7 @@ test "if error union with optional" {
|
||||
|
||||
const a: anyerror!?u32 = 0;
|
||||
if (a) |optional_value| {
|
||||
try expect(optional_value.? == 0);
|
||||
try expectEqual(0, optional_value.?);
|
||||
} else |err| {
|
||||
_ = err;
|
||||
unreachable;
|
||||
@@ -54,7 +55,7 @@ test "if error union with optional" {
|
||||
|
||||
const b: anyerror!?u32 = null;
|
||||
if (b) |optional_value| {
|
||||
try expect(optional_value == null);
|
||||
try expectEqual(null, optional_value);
|
||||
} else |_| {
|
||||
unreachable;
|
||||
}
|
||||
@@ -64,7 +65,7 @@ test "if error union with optional" {
|
||||
_ = optional_value;
|
||||
unreachable;
|
||||
} else |err| {
|
||||
try expect(err == error.BadValue);
|
||||
try expectEqual(error.BadValue, err);
|
||||
}
|
||||
|
||||
// Access the value by reference by using a pointer capture each time.
|
||||
@@ -78,7 +79,7 @@ test "if error union with optional" {
|
||||
}
|
||||
|
||||
if (d) |optional_value| {
|
||||
try expect(optional_value.? == 9);
|
||||
try expectEqual(9, optional_value.?);
|
||||
} else |_| {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ const std = @import("std");
|
||||
test "pointer alignment safety" {
|
||||
var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
|
||||
const bytes = std.mem.sliceAsBytes(array[0..]);
|
||||
try std.testing.expect(foo(bytes) == 0x11111111);
|
||||
try std.testing.expectEqual(0x11111111, foo(bytes));
|
||||
}
|
||||
fn foo(bytes: []u8) u32 {
|
||||
const slice4 = bytes[1..5];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const SliceTypeA = extern struct {
|
||||
len: usize,
|
||||
@@ -42,8 +42,8 @@ fn withSwitch(any: AnySlice) usize {
|
||||
|
||||
test "inline for and inline else similarity" {
|
||||
const any = AnySlice{ .c = "hello" };
|
||||
try expect(withFor(any) == 5);
|
||||
try expect(withSwitch(any) == 5);
|
||||
try expectEqual(5, withFor(any));
|
||||
try expectEqual(5, withSwitch(any));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "inline for loop" {
|
||||
const nums = [_]i32{ 2, 4, 6 };
|
||||
@@ -12,7 +12,7 @@ test "inline for loop" {
|
||||
};
|
||||
sum += typeNameLength(T);
|
||||
}
|
||||
try expect(sum == 9);
|
||||
try expectEqual(9, sum);
|
||||
}
|
||||
|
||||
fn typeNameLength(comptime T: type) usize {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const U = union(enum) {
|
||||
a: u32,
|
||||
@@ -21,7 +21,7 @@ fn getNum(u: U) u32 {
|
||||
|
||||
test "test" {
|
||||
const u = U{ .b = 42 };
|
||||
try expect(getNum(u) == 42);
|
||||
try expectEqual(42, getNum(u));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "inline while loop" {
|
||||
comptime var i = 0;
|
||||
@@ -12,7 +12,7 @@ test "inline while loop" {
|
||||
};
|
||||
sum += typeNameLength(T);
|
||||
}
|
||||
try expect(sum == 9);
|
||||
try expectEqual(9, sum);
|
||||
}
|
||||
|
||||
fn typeNameLength(comptime T: type) usize {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "@intFromPtr and @ptrFromInt" {
|
||||
const ptr: *i32 = @ptrFromInt(0xdeadbee0);
|
||||
const addr = @intFromPtr(ptr);
|
||||
try expect(@TypeOf(addr) == usize);
|
||||
try expect(addr == 0xdeadbee0);
|
||||
try expectEqual(usize, @TypeOf(addr));
|
||||
try expectEqual(0xdeadbee0, addr);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const mem = std.mem;
|
||||
|
||||
test "integer widening" {
|
||||
@@ -10,13 +10,13 @@ test "integer widening" {
|
||||
const d: u64 = c;
|
||||
const e: u64 = d;
|
||||
const f: u128 = e;
|
||||
try expect(f == a);
|
||||
try expectEqual(f, a);
|
||||
}
|
||||
|
||||
test "implicit unsigned integer to signed integer" {
|
||||
const a: u8 = 250;
|
||||
const b: i16 = a;
|
||||
try expect(b == 250);
|
||||
try expectEqual(250, b);
|
||||
}
|
||||
|
||||
test "float widening" {
|
||||
@@ -24,7 +24,7 @@ test "float widening" {
|
||||
const b: f32 = a;
|
||||
const c: f64 = b;
|
||||
const d: f128 = c;
|
||||
try expect(d == a);
|
||||
try expectEqual(d, a);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "labeled break from labeled block expression" {
|
||||
var y: i32 = 123;
|
||||
@@ -8,8 +8,8 @@ test "labeled break from labeled block expression" {
|
||||
y += 1;
|
||||
break :blk y;
|
||||
};
|
||||
try expect(x == 124);
|
||||
try expect(y == 124);
|
||||
try expectEqual(124, x);
|
||||
try expectEqual(124, y);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const BitField = packed struct {
|
||||
a: u3,
|
||||
@@ -14,7 +14,7 @@ var bit_field = BitField{
|
||||
};
|
||||
|
||||
test "pointer to non-byte-aligned field" {
|
||||
try expect(bar(&bit_field.b) == 2);
|
||||
try expectEqual(2, bar(&bit_field.b));
|
||||
}
|
||||
|
||||
fn bar(x: *const u3) u3 {
|
||||
|
||||
@@ -3,4 +3,4 @@ test "missized packed struct" {
|
||||
_ = S{ .a = 4, .b = 2 };
|
||||
}
|
||||
|
||||
// test_error=backing integer type 'u32' has bit size 32 but the struct fields have a total bit size of 24
|
||||
// test_error=backing integer bit width does not match total bit width of fields
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const mat4x5 = [4][5]f32{
|
||||
@@ -13,20 +12,20 @@ test "multidimensional arrays" {
|
||||
try expectEqual(mat4x5[1], [_]f32{ 0.0, 1.0, 0.0, 1.0, 0.0 });
|
||||
|
||||
// Access the 2D array by indexing the outer array, and then the inner array.
|
||||
try expect(mat4x5[3][4] == 9.9);
|
||||
try expectEqual(9.9, mat4x5[3][4]);
|
||||
|
||||
// Here we iterate with for loops.
|
||||
for (mat4x5, 0..) |row, row_index| {
|
||||
for (row, 0..) |cell, column_index| {
|
||||
if (row_index == column_index) {
|
||||
try expect(cell == 1.0);
|
||||
try expectEqual(1.0, cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize a multidimensional array to zeros.
|
||||
const all_zero: [4][5]f32 = .{.{0} ** 5} ** 4;
|
||||
try expect(all_zero[0][0] == 0);
|
||||
try expectEqual(0, all_zero[0][0]);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "namespaced container level variable" {
|
||||
try expect(foo() == 1235);
|
||||
try expect(foo() == 1236);
|
||||
try expectEqual(1235, foo());
|
||||
try expectEqual(1236, foo());
|
||||
}
|
||||
|
||||
const S = struct {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const native_arch = builtin.cpu.arch;
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .{ .x86_stdcall = .{} } else .c;
|
||||
extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(WINAPI) noreturn;
|
||||
|
||||
test "foo" {
|
||||
const value = bar() catch ExitProcess(1);
|
||||
try expect(value == 1234);
|
||||
try expectEqual(1234, value);
|
||||
}
|
||||
|
||||
fn bar() anyerror!u32 {
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "0-terminated sentinel array" {
|
||||
const array = [_:0]u8{ 1, 2, 3, 4 };
|
||||
|
||||
try expect(@TypeOf(array) == [4:0]u8);
|
||||
try expect(array.len == 4);
|
||||
try expect(array[4] == 0);
|
||||
try expectEqual([4:0]u8, @TypeOf(array));
|
||||
try expectEqual(4, array.len);
|
||||
try expectEqual(0, array[4]);
|
||||
}
|
||||
|
||||
test "extra 0s in 0-terminated sentinel array" {
|
||||
// The sentinel value may appear earlier, but does not influence the compile-time 'len'.
|
||||
const array = [_:0]u8{ 1, 0, 0, 4 };
|
||||
|
||||
try expect(@TypeOf(array) == [4:0]u8);
|
||||
try expect(array.len == 4);
|
||||
try expect(array[4] == 0);
|
||||
try expectEqual([4:0]u8, @TypeOf(array));
|
||||
try expectEqual(4, array.len);
|
||||
try expectEqual(0, array[4]);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "0-terminated slice" {
|
||||
const slice: [:0]const u8 = "hello";
|
||||
|
||||
try expect(slice.len == 5);
|
||||
try expect(slice[5] == 0);
|
||||
try expectEqual(5, slice.len);
|
||||
try expectEqual(0, slice[5]);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "0-terminated slicing" {
|
||||
var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 };
|
||||
@@ -7,8 +7,8 @@ test "0-terminated slicing" {
|
||||
_ = &runtime_length;
|
||||
const slice = array[0..runtime_length :0];
|
||||
|
||||
try expect(@TypeOf(slice) == [:0]u8);
|
||||
try expect(slice.len == 3);
|
||||
try expectEqual([:0]u8, @TypeOf(slice));
|
||||
try expectEqual(3, slice.len);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "optional pointers" {
|
||||
// Pointers cannot be null. If you want a null pointer, use the optional
|
||||
@@ -8,11 +8,11 @@ test "optional pointers" {
|
||||
var x: i32 = 1;
|
||||
ptr = &x;
|
||||
|
||||
try expect(ptr.?.* == 1);
|
||||
try expectEqual(1, ptr.?.*);
|
||||
|
||||
// Optional pointers are the same size as normal pointers, because pointer
|
||||
// value 0 is used as the null value.
|
||||
try expect(@sizeOf(?*i32) == @sizeOf(*i32));
|
||||
try expectEqual(@sizeOf(?*i32), @sizeOf(*i32));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "optional type" {
|
||||
// Declare an optional and coerce from null:
|
||||
@@ -8,7 +8,7 @@ test "optional type" {
|
||||
foo = 1234;
|
||||
|
||||
// Use compile-time reflection to access the child type of the optional:
|
||||
try comptime expect(@typeInfo(@TypeOf(foo)).optional.child == i32);
|
||||
try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).optional.child);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const S = packed struct {
|
||||
a: u32,
|
||||
@@ -9,7 +9,7 @@ test "overaligned pointer to packed struct" {
|
||||
var foo: S align(4) = .{ .a = 1, .b = 2 };
|
||||
const ptr: *align(4) S = &foo;
|
||||
const ptr_to_b = &ptr.b;
|
||||
try expect(ptr_to_b.* == 2);
|
||||
try expectEqual(2, ptr_to_b.*);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "packed struct equality" {
|
||||
const S = packed struct {
|
||||
@@ -8,7 +8,7 @@ test "packed struct equality" {
|
||||
};
|
||||
const x: S = .{ .a = 1, .b = 2 };
|
||||
const y: S = .{ .b = 2, .a = 1 };
|
||||
try expect(x == y);
|
||||
try expectEqual(x, y);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const BitField = packed struct {
|
||||
a: u3,
|
||||
@@ -14,8 +14,8 @@ var bit_field = BitField{
|
||||
};
|
||||
|
||||
test "pointers of sub-byte-aligned fields share addresses" {
|
||||
try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.b));
|
||||
try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.c));
|
||||
try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.b));
|
||||
try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.c));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const std = @import("std");
|
||||
const native_endian = @import("builtin").target.cpu.arch.endian();
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const Full = packed struct {
|
||||
number: u16,
|
||||
@@ -17,23 +17,23 @@ test "@bitCast between packed structs" {
|
||||
}
|
||||
|
||||
fn doTheTest() !void {
|
||||
try expect(@sizeOf(Full) == 2);
|
||||
try expect(@sizeOf(Divided) == 2);
|
||||
try expectEqual(2, @sizeOf(Full));
|
||||
try expectEqual(2, @sizeOf(Divided));
|
||||
const full = Full{ .number = 0x1234 };
|
||||
const divided: Divided = @bitCast(full);
|
||||
try expect(divided.half1 == 0x34);
|
||||
try expect(divided.quarter3 == 0x2);
|
||||
try expect(divided.quarter4 == 0x1);
|
||||
try expectEqual(0x34, divided.half1);
|
||||
try expectEqual(0x2, divided.quarter3);
|
||||
try expectEqual(0x1, divided.quarter4);
|
||||
|
||||
const ordered: [2]u8 = @bitCast(full);
|
||||
switch (native_endian) {
|
||||
.big => {
|
||||
try expect(ordered[0] == 0x12);
|
||||
try expect(ordered[1] == 0x34);
|
||||
try expectEqual(0x12, ordered[0]);
|
||||
try expectEqual(0x34, ordered[1]);
|
||||
},
|
||||
.little => {
|
||||
try expect(ordered[0] == 0x34);
|
||||
try expect(ordered[1] == 0x12);
|
||||
try expectEqual(0x34, ordered[0]);
|
||||
try expectEqual(0x12, ordered[1]);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ fn foo(point: Point) i32 {
|
||||
return point.x + point.y;
|
||||
}
|
||||
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "pass struct to function" {
|
||||
try expect(foo(Point{ .x = 1, .y = 2 }) == 3);
|
||||
try expectEqual(3, foo(Point{ .x = 1, .y = 2 }));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const mem = std.mem;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
||||
|
||||
test "peer resolve int widening" {
|
||||
const a: i8 = 12;
|
||||
const b: i16 = 34;
|
||||
const c = a + b;
|
||||
try expect(c == 46);
|
||||
try expect(@TypeOf(c) == i16);
|
||||
try expectEqual(46, c);
|
||||
try expectEqual(i16, @TypeOf(c));
|
||||
}
|
||||
|
||||
test "peer resolve arrays of different size to const slice" {
|
||||
try expect(mem.eql(u8, boolToStr(true), "true"));
|
||||
try expect(mem.eql(u8, boolToStr(false), "false"));
|
||||
try comptime expect(mem.eql(u8, boolToStr(true), "true"));
|
||||
try comptime expect(mem.eql(u8, boolToStr(false), "false"));
|
||||
try expectEqualStrings("true", boolToStr(true));
|
||||
try expectEqualStrings("false", boolToStr(false));
|
||||
try comptime expectEqualStrings("true", boolToStr(true));
|
||||
try comptime expectEqualStrings("false", boolToStr(false));
|
||||
}
|
||||
fn boolToStr(b: bool) []const u8 {
|
||||
return if (b) "true" else "false";
|
||||
@@ -27,16 +27,16 @@ test "peer resolve array and const slice" {
|
||||
fn testPeerResolveArrayConstSlice(b: bool) !void {
|
||||
const value1 = if (b) "aoeu" else @as([]const u8, "zz");
|
||||
const value2 = if (b) @as([]const u8, "zz") else "aoeu";
|
||||
try expect(mem.eql(u8, value1, "aoeu"));
|
||||
try expect(mem.eql(u8, value2, "zz"));
|
||||
try expectEqualStrings("aoeu", value1);
|
||||
try expectEqualStrings("zz", value2);
|
||||
}
|
||||
|
||||
test "peer type resolution: ?T and T" {
|
||||
try expect(peerTypeTAndOptionalT(true, false).? == 0);
|
||||
try expect(peerTypeTAndOptionalT(false, false).? == 3);
|
||||
try expectEqual(0, peerTypeTAndOptionalT(true, false).?);
|
||||
try expectEqual(3, peerTypeTAndOptionalT(false, false).?);
|
||||
comptime {
|
||||
try expect(peerTypeTAndOptionalT(true, false).? == 0);
|
||||
try expect(peerTypeTAndOptionalT(false, false).? == 3);
|
||||
try expectEqual(0, peerTypeTAndOptionalT(true, false).?);
|
||||
try expectEqual(3, peerTypeTAndOptionalT(false, false).?);
|
||||
}
|
||||
}
|
||||
fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
|
||||
@@ -48,11 +48,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
|
||||
}
|
||||
|
||||
test "peer type resolution: *[0]u8 and []const u8" {
|
||||
try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
|
||||
try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
|
||||
try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len);
|
||||
try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len);
|
||||
comptime {
|
||||
try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
|
||||
try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
|
||||
try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len);
|
||||
try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len);
|
||||
}
|
||||
}
|
||||
fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
|
||||
@@ -66,14 +66,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {
|
||||
{
|
||||
var data = "hi".*;
|
||||
const slice = data[0..];
|
||||
try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len);
|
||||
try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len);
|
||||
}
|
||||
comptime {
|
||||
var data = "hi".*;
|
||||
const slice = data[0..];
|
||||
try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len);
|
||||
try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len);
|
||||
}
|
||||
}
|
||||
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
|
||||
@@ -87,8 +87,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
|
||||
test "peer type resolution: *const T and ?*T" {
|
||||
const a: *const usize = @ptrFromInt(0x123456780);
|
||||
const b: ?*usize = @ptrFromInt(0x123456780);
|
||||
try expect(a == b);
|
||||
try expect(b == a);
|
||||
try expectEqual(a, b);
|
||||
try expectEqual(b, a);
|
||||
}
|
||||
|
||||
test "peer type resolution: error union switch" {
|
||||
@@ -104,7 +104,7 @@ test "peer type resolution: error union switch" {
|
||||
error.B => 1,
|
||||
error.C => null,
|
||||
};
|
||||
try expect(@TypeOf(b) == ?u32);
|
||||
try expectEqual(?u32, @TypeOf(b));
|
||||
|
||||
// The non-error and error cases are only peers if the error case is just a switch expression;
|
||||
// the pattern `x catch |err| blk: { switch (err) {...} }` does not consider the unwrapped `x`
|
||||
@@ -114,7 +114,7 @@ test "peer type resolution: error union switch" {
|
||||
error.B => 1,
|
||||
error.C => null,
|
||||
};
|
||||
try expect(@TypeOf(c) == ?u32);
|
||||
try expectEqual(?u32, @TypeOf(c));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "pointer arithmetic with many-item pointer" {
|
||||
const array = [_]i32{ 1, 2, 3, 4 };
|
||||
var ptr: [*]const i32 = &array;
|
||||
|
||||
try expect(ptr[0] == 1);
|
||||
try expectEqual(1, ptr[0]);
|
||||
ptr += 1;
|
||||
try expect(ptr[0] == 2);
|
||||
try expectEqual(2, ptr[0]);
|
||||
|
||||
// slicing a many-item pointer without an end is equivalent to
|
||||
// pointer arithmetic: `ptr[start..] == ptr + start`
|
||||
try expect(ptr[1..] == ptr + 1);
|
||||
try expectEqual(ptr[1..], ptr + 1);
|
||||
|
||||
// subtraction between any two pointers except slices based on element size is supported
|
||||
try expect(&ptr[1] - &ptr[0] == 1);
|
||||
try expectEqual(1, &ptr[1] - &ptr[0]);
|
||||
}
|
||||
|
||||
test "pointer arithmetic with slices" {
|
||||
@@ -22,14 +22,14 @@ test "pointer arithmetic with slices" {
|
||||
_ = &length; // suppress 'var is never mutated' error
|
||||
var slice = array[length..array.len];
|
||||
|
||||
try expect(slice[0] == 1);
|
||||
try expect(slice.len == 4);
|
||||
try expectEqual(1, slice[0]);
|
||||
try expectEqual(4, slice.len);
|
||||
|
||||
slice.ptr += 1;
|
||||
// now the slice is in an bad state since len has not been updated
|
||||
|
||||
try expect(slice[0] == 2);
|
||||
try expect(slice.len == 4);
|
||||
try expectEqual(2, slice[0]);
|
||||
try expectEqual(4, slice.len);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "pointer casting" {
|
||||
const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
|
||||
const u32_ptr: *const u32 = @ptrCast(&bytes);
|
||||
try expect(u32_ptr.* == 0x12121212);
|
||||
try expectEqual(0x12121212, u32_ptr.*);
|
||||
|
||||
// Even this example is contrived - there are better ways to do the above than
|
||||
// pointer casting. For example, using a slice narrowing cast:
|
||||
const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0];
|
||||
try expect(u32_value == 0x12121212);
|
||||
try expectEqual(0x12121212, u32_value);
|
||||
|
||||
// And even another way, the most straightforward way to do it:
|
||||
try expect(@as(u32, @bitCast(bytes)) == 0x12121212);
|
||||
try expectEqual(0x12121212, @as(u32, @bitCast(bytes)));
|
||||
}
|
||||
|
||||
test "pointer child type" {
|
||||
// pointer types have a `child` field which tells you the type they point to.
|
||||
try expect(@typeInfo(*u32).pointer.child == u32);
|
||||
try expectEqual(u32, @typeInfo(*u32).pointer.child);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
||||
const mem = std.mem;
|
||||
|
||||
test "cast *[1][*:0]const u8 to []const ?[*:0]const u8" {
|
||||
const window_name = [1][*:0]const u8{"window name"};
|
||||
const x: []const ?[*:0]const u8 = &window_name;
|
||||
try expect(mem.eql(u8, mem.span(x[0].?), "window name"));
|
||||
try expectEqualStrings("window name", mem.span(x[0].?));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const BitField = packed struct {
|
||||
a: u3,
|
||||
@@ -15,7 +15,7 @@ var foo = BitField{
|
||||
|
||||
test "pointer to non-byte-aligned field" {
|
||||
const ptr = &foo.b;
|
||||
try expect(ptr.* == 2);
|
||||
try expectEqual(2, ptr.*);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "vector @reduce" {
|
||||
const V = @Vector(4, i32);
|
||||
const value = V{ 1, -1, 1, -1 };
|
||||
const result = value > @as(V, @splat(0));
|
||||
// result is { true, false, true, false };
|
||||
try comptime expect(@TypeOf(result) == @Vector(4, bool));
|
||||
try comptime expectEqual(@Vector(4, bool), @TypeOf(result));
|
||||
const is_all_true = @reduce(.And, result);
|
||||
try comptime expect(@TypeOf(is_all_true) == bool);
|
||||
try expect(is_all_true == false);
|
||||
try comptime expectEqual(bool, @TypeOf(is_all_true));
|
||||
try expectEqual(false, is_all_true);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "@round" {
|
||||
try expect(@round(1.4) == 1);
|
||||
try expect(@round(1.5) == 2);
|
||||
try expect(@round(-1.4) == -1);
|
||||
try expect(@round(-2.5) == -3);
|
||||
try expectEqual(1, @round(1.4));
|
||||
try expectEqual(2, @round(1.5));
|
||||
try expectEqual(-1, @round(-1.4));
|
||||
try expectEqual(-3, @round(-2.5));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "sentinel mismatch" {
|
||||
var array = [_]u8{ 3, 2, 1, 0 };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
||||
|
||||
test "vector @shuffle" {
|
||||
const a = @Vector(7, u8){ 'o', 'l', 'h', 'e', 'r', 'z', 'w' };
|
||||
@@ -9,12 +9,12 @@ test "vector @shuffle" {
|
||||
// Notice that we can re-order, duplicate, or omit elements of the input vector
|
||||
const mask1 = @Vector(5, i32){ 2, 3, 1, 1, 0 };
|
||||
const res1: @Vector(5, u8) = @shuffle(u8, a, undefined, mask1);
|
||||
try expect(std.mem.eql(u8, &@as([5]u8, res1), "hello"));
|
||||
try expectEqualStrings("hello", &@as([5]u8, res1));
|
||||
|
||||
// Combining two vectors
|
||||
const mask2 = @Vector(6, i32){ -1, 0, 4, 1, -2, -3 };
|
||||
const res2: @Vector(6, u8) = @shuffle(u8, a, b, mask2);
|
||||
try expect(std.mem.eql(u8, &@as([6]u8, res2), "world!"));
|
||||
try expectEqualStrings("world!", &@as([6]u8, res2));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
const Payload = union {
|
||||
int: i64,
|
||||
@@ -8,9 +8,9 @@ const Payload = union {
|
||||
};
|
||||
test "simple union" {
|
||||
var payload = Payload{ .int = 1234 };
|
||||
try expect(payload.int == 1234);
|
||||
try expectEqual(1234, payload.int);
|
||||
payload = Payload{ .float = 12.34 };
|
||||
try expect(payload.float == 12.34);
|
||||
try expectEqual(12.34, payload.float);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "address of syntax" {
|
||||
// Get the address of a variable:
|
||||
@@ -6,17 +6,17 @@ test "address of syntax" {
|
||||
const x_ptr = &x;
|
||||
|
||||
// Dereference a pointer:
|
||||
try expect(x_ptr.* == 1234);
|
||||
try expectEqual(1234, x_ptr.*);
|
||||
|
||||
// When you get the address of a const variable, you get a const single-item pointer.
|
||||
try expect(@TypeOf(x_ptr) == *const i32);
|
||||
try expectEqual(*const i32, @TypeOf(x_ptr));
|
||||
|
||||
// If you want to mutate the value, you'd need an address of a mutable variable:
|
||||
var y: i32 = 5678;
|
||||
const y_ptr = &y;
|
||||
try expect(@TypeOf(y_ptr) == *i32);
|
||||
try expectEqual(*i32, @TypeOf(y_ptr));
|
||||
y_ptr.* += 1;
|
||||
try expect(y_ptr.* == 5679);
|
||||
try expectEqual(5679, y_ptr.*);
|
||||
}
|
||||
|
||||
test "pointer array access" {
|
||||
@@ -25,11 +25,11 @@ test "pointer array access" {
|
||||
// does not support pointer arithmetic.
|
||||
var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
const ptr = &array[2];
|
||||
try expect(@TypeOf(ptr) == *u8);
|
||||
try expectEqual(*u8, @TypeOf(ptr));
|
||||
|
||||
try expect(array[2] == 3);
|
||||
try expectEqual(3, array[2]);
|
||||
ptr.* += 1;
|
||||
try expect(array[2] == 4);
|
||||
try expectEqual(4, array[2]);
|
||||
}
|
||||
|
||||
test "slice syntax" {
|
||||
@@ -39,11 +39,11 @@ test "slice syntax" {
|
||||
|
||||
// Convert to array pointer using slice syntax:
|
||||
const x_array_ptr = x_ptr[0..1];
|
||||
try expect(@TypeOf(x_array_ptr) == *[1]i32);
|
||||
try expectEqual(*[1]i32, @TypeOf(x_array_ptr));
|
||||
|
||||
// Coerce to many-item pointer:
|
||||
const x_many_ptr: [*]i32 = x_array_ptr;
|
||||
try expect(x_many_ptr[0] == 1234);
|
||||
try expectEqual(1234, x_many_ptr[0]);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
const expect = @import("std").testing.expect;
|
||||
const expectEqual = @import("std").testing.expectEqual;
|
||||
|
||||
test "pointer slicing" {
|
||||
var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
var start: usize = 2; // var to make it runtime-known
|
||||
_ = &start; // suppress 'var is never mutated' error
|
||||
const slice = array[start..4];
|
||||
try expect(slice.len == 2);
|
||||
try expectEqual(2, slice.len);
|
||||
|
||||
try expect(array[3] == 4);
|
||||
try expectEqual(4, array[3]);
|
||||
slice[1] += 1;
|
||||
try expect(array[3] == 5);
|
||||
try expectEqual(5, array[3]);
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const mem = std.mem;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
||||
const fmt = std.fmt;
|
||||
|
||||
test "using slices for strings" {
|
||||
@@ -23,13 +23,13 @@ test "using slices for strings" {
|
||||
// Generally, you can use UTF-8 and not worry about whether something is a
|
||||
// string. If you don't need to deal with individual characters, no need
|
||||
// to decode.
|
||||
try expect(mem.eql(u8, hello_world, "hello 世界"));
|
||||
try expectEqualStrings("hello 世界", hello_world);
|
||||
}
|
||||
|
||||
test "slice pointer" {
|
||||
var array: [10]u8 = undefined;
|
||||
const ptr = &array;
|
||||
try expect(@TypeOf(ptr) == *[10]u8);
|
||||
try expectEqual(*[10]u8, @TypeOf(ptr));
|
||||
|
||||
// A pointer to an array can be sliced just like an array:
|
||||
var start: usize = 0;
|
||||
@@ -37,16 +37,16 @@ test "slice pointer" {
|
||||
_ = .{ &start, &end };
|
||||
const slice = ptr[start..end];
|
||||
// The slice is mutable because we sliced a mutable pointer.
|
||||
try expect(@TypeOf(slice) == []u8);
|
||||
try expectEqual([]u8, @TypeOf(slice));
|
||||
slice[2] = 3;
|
||||
try expect(array[2] == 3);
|
||||
try expectEqual(3, array[2]);
|
||||
|
||||
// Again, slicing with comptime-known indexes will produce another pointer
|
||||
// to an array:
|
||||
const ptr2 = slice[2..3];
|
||||
try expect(ptr2.len == 1);
|
||||
try expect(ptr2[0] == 3);
|
||||
try expect(@TypeOf(ptr2) == *[1]u8);
|
||||
try expectEqual(1, ptr2.len);
|
||||
try expectEqual(3, ptr2[0]);
|
||||
try expectEqual(*[1]u8, @TypeOf(ptr2));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqualSlices = std.testing.expectEqualSlices;
|
||||
|
||||
test "vector @splat" {
|
||||
const scalar: u32 = 5;
|
||||
const result: @Vector(4, u32) = @splat(scalar);
|
||||
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
|
||||
try expectEqualSlices(u32, &[_]u32{ 5, 5, 5, 5 }, &@as([4]u32, result));
|
||||
}
|
||||
|
||||
test "array @splat" {
|
||||
const scalar: u32 = 5;
|
||||
const result: [4]u32 = @splat(scalar);
|
||||
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
|
||||
try expectEqualSlices(u32, &[_]u32{ 5, 5, 5, 5 }, &@as([4]u32, result));
|
||||
}
|
||||
|
||||
// test
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
|
||||
test "@src" {
|
||||
try doTheTest();
|
||||
@@ -8,8 +9,8 @@ test "@src" {
|
||||
fn doTheTest() !void {
|
||||
const src = @src();
|
||||
|
||||
try expect(src.line == 9);
|
||||
try expect(src.column == 17);
|
||||
try expectEqual(10, src.line);
|
||||
try expectEqual(17, src.column);
|
||||
try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
|
||||
try expect(std.mem.endsWith(u8, src.file, "test_src_builtin.zig"));
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user