aboutsummaryrefslogtreecommitdiff
path: root/lib/std/testing.zig
AgeCommit message (Collapse)Author
2021-01-12Move fmt.testFmt to testing.expectFmtJay Petacat
2021-01-02convert more {} to {d} and {s}Andrew Kelley
2021-01-02langref: Update langref to use {s}LemonBoy
2021-01-02std: Use {s} instead of {} when printing stringsLemonBoy
2020-12-31Year++Frank Denis
2020-12-28zig test: std.testing.zig_exe_path is now availableAndrew Kelley
it will be set to the path of the zig executable which is running `zig test`.
2020-12-24Return encoded slice from base64 encodefrmdstryr
2020-12-18std: introduce a thread-local CSPRNG for general useAndrew Kelley
std.crypto.random * cross platform, even freestanding * can't fail. on initialization for some systems requires calling os.getrandom(), in which case there are rare but theoretically possible errors. The code panics in these cases, however the application may choose to override the default seed function and then handle the failure another way. * thread-safe * supports the full Random interface * cryptographically secure * no syscall required to initialize on Linux (AT_RANDOM) * calls arc4random on systems that support it `std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`. I moved some of the Random implementations into their own files in the interest of organization. stage2 no longer requires passing a RNG; instead it uses this API. Closes #6704
2020-12-08add std.testing.expectStringEndsWithAndrew Kelley
2020-11-01std: Fix expectWithinEpsilon with negative valuesLemonBoy
2020-10-29std: Better handling of type values in expectEqualLemonBoy
2020-10-15std: move std.meta.refAllDecls to std.testingTadeo Kondrak
2020-09-30fix the cli test expected string to support native path separatorsAndrew Kelley
2020-08-20add license header to all std lib filesAndrew Kelley
add SPDX license identifier copyright ownership is zig contributors
2020-08-08restore previous behavior of allowing std.testing.allocatorAndrew Kelley
even outside of unit tests
2020-08-07std: introduce GeneralPurposeAllocatorAndrew Kelley
`std.GeneralPurposeAllocator` is now available. It is a function that takes a configuration struct (with default field values) and returns an allocator. There is a detailed description of this allocator in the doc comments at the top of the new file. The main feature of this allocator is that it is *safe*. It prevents double-free, use-after-free, and detects leaks. Some deprecation compile errors are removed. The Allocator interface gains `old_align` as a new parameter to `resizeFn`. This is useful to quickly look up allocations. `std.heap.page_allocator` is improved to use mmap address hints to avoid obtaining the same virtual address pages when unmapping and mapping pages. The new general purpose allocator uses the page allocator as its backing allocator by default. `std.testing.allocator` is replaced with usage of this new allocator, which does leak checking, and so the LeakCheckAllocator is retired. stage1 is improved so that the `@typeInfo` of a pointer has a lazy value for the alignment of the child type, to avoid false dependency loops when dealing with pointers to async function frames. The `std.mem.Allocator` interface is refactored to be in its own file. `std.Mutex` now exposes the dummy mutex with `std.Mutex.Dummy`. This allocator is great for debug mode, however it needs some work to have better performance in release modes. The next step will be setting up a series of tests in ziglang/gotta-go-fast and then making improvements to the implementation.
2020-07-25run zig fmt on std.testingAndrew Kelley
2020-07-26Merge pull request #5678 from antlilja/float-testingAndrew Kelley
Add functions for testing floats with margins and epsilons to standard library
2020-07-11run zig fmt on std lib and self hostedVexu
2020-07-08start to make test runner aware of loggingAndrew Kelley
by default the test runner will only print logs with "warning" or higher. this can be configured via the std.testing API. See #5738 for future plans
2020-06-27new allocator interface after Andrew Kelley reviewJonathan Marler
2020-06-26new allocator interfaceJonathan Marler
2020-06-23Refactor PreopenList.find()Jakub Konka
This commit generalizes `std.fs.wasi.PreopenList.find(...)` allowing search by `std.fs.wasi.PreopenType` union type rather than by dir name. In the future releases of WASI, it is expected to have more preopen types (or capabilities) than just directories. This commit aligns itself with that vision. This is a potentially breaking change. However, since `std.fs.wasi.PreopenList` wasn't made part of any Zig release yet, I think we should be OK to introduce those changes without pointing to any deprecations.
2020-06-23Add expectWithinEpsilon + testantlilja
2020-06-23Add expectWithinMargin and testantlilja
2020-05-22std.testing: fix a crash when printing diffsAndrew Kelley
2020-05-18Integrate getTestDir with tmpDir logicJakub Konka
2020-05-18Add/fix missing WASI functionality to pass libstd testsJakub Konka
This rather large commit adds/fixes missing WASI functionality in `libstd` needed to pass the `libstd` tests. As such, now by default tests targeting `wasm32-wasi` target are enabled in `test/tests.zig` module. However, they can be disabled by passing the `-Dskip-wasi=true` flag when invoking the `zig build test` command. When the flag is set to `false`, i.e., when WASI tests are included, `wasmtime` with `--dir=.` is used as the default testing command. Since the majority of `libstd` tests were relying on `fs.cwd()` call to get current working directory handle wrapped in `Dir` struct, in order to make the tests WASI-friendly, `fs.cwd()` call was replaced with `testing.getTestDir()` function which resolved to either `fs.cwd()` for non-WASI targets, or tries to fetch the preopen list from the WASI runtime and extract a preopen for '.' path. The summary of changes introduced by this commit: * implement `Dir.makeDir` and `Dir.openDir` targeting WASI * implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI * fix `os.close` and map errors in `unlinkat` * move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi` to `std.os` module * implement `lseek_{SET, CUR, END}` targeting WASI * implement `futimens` targeting WASI * implement `ftruncate` targeting WASI * implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI * make sure ANSI escape codes are _not_ used in stderr or stdout in WASI, as WASI always sanitizes stderr, and sanitizes stdout if fd is a TTY * fix specifying WASI rights when opening/creating files/dirs * tweak `AtomicFile` to be WASI-compatible * implement `os.renameatWasi` for WASI-compliant `os.renameat` function * implement sleep() targeting WASI * fix `process.getEnvMap` targeting WASI
2020-05-01rework std.math.big.IntAndrew Kelley
Now there are 3 types: * std.math.big.int.Const - the memory is immutable, only stores limbs and is_positive - all methods operating on constant data go here * std.math.big.int.Mutable - the memory is mutable, stores capacity in addition to limbs and is_positive - methods here have some Mutable parameters and some Const parameters. These methods expect callers to pre-calculate the amount of resources required, and asserts that the resources are available. * std.math.big.int.Managed - the memory is mutable and additionally stores an allocator. - methods here perform the resource calculations for the programmer. - this is the high level abstraction from before Each of these 3 types can be converted to the other ones. You can see the use case for this in the self-hosted compiler, where we only store limbs, and construct the big ints as needed. This gets rid of the hack where the allocator was optional and the notion of "fixed" versions of the struct. Such things are now modeled with the `big.int.Const` type.
2020-05-01add ZIR compare output test case to test suiteAndrew Kelley
2020-04-30move printWithVisibleNewlines to testing.expectEqualStringsVexu
2020-04-07fix broken testsVexu
2020-03-01short std.builtin enum literals in std libxackus
2020-02-28separate std.Target and std.zig.CrossTargetAndrew Kelley
Zig now supports a more fine-grained sense of what is native and what is not. Some examples: This is now allowed: -target native Different OS but native CPU, default Windows C ABI: -target native-windows This could be useful for example when running in Wine. Different CPU but native OS, native C ABI. -target x86_64-native -mcpu=skylake Different C ABI but otherwise native target: -target native-native-musl -target native-native-gnu Lots of breaking changes to related std lib APIs. Calls to getOs() will need to be changed to getOsTag(). Calls to getArch() will need to be changed to getCpuArch(). Usage of Target.Cross and Target.Native need to be updated to use CrossTarget API. `std.build.Builder.standardTargetOptions` is changed to accept its parameters as a struct with default values. It now has the ability to specify a whitelist of targets allowed, as well as the default target. Rather than two different ways of collecting the target, it's now always a string that is validated, and prints helpful diagnostics for invalid targets. This feature should now be actually useful, and contributions welcome to further improve the user experience. `std.build.LibExeObjStep.setTheTarget` is removed. `std.build.LibExeObjStep.setTarget` is updated to take a CrossTarget parameter. `std.build.LibExeObjStep.setTargetGLibC` is removed. glibc versions are handled in the CrossTarget API and can be specified with the `-target` triple. `std.builtin.Version` gains a `format` method.
2020-02-14std: increase memory available to testing allocatordaurnimator
2020-02-13Vector comparison in meta and testingdata-man
2020-01-30Convert a few more page_allocatorBenjamin Feng
2020-01-29Promoted "leak_count_allocator" to the main testing.allocatorBenjamin Feng
2020-01-29Move FailingAllocator to testingBenjamin Feng
2020-01-29Create leak_count_allocatorBenjamin Feng
2020-01-29Move debug.global_allocator to testing.allocatorBenjamin Feng
2019-12-29Fixes #3966data-man
2019-12-10Replace @typeOf with @TypeOf in all zig sourceRobin Voetter
This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually.
2019-12-09remove no-longer-needed workaround for var argsAndrew Kelley
See #557
2019-12-09remove var args from the languageAndrew Kelley
closes #208
2019-12-08std.fmt.format: tuple parameter instead of var argsAndrew Kelley
2019-11-27Implements std.testing.expectEqual for tagged unions. (#3773)Felix Queißner
2019-11-19std.testing.expectEqual: show differing pointer valuesJohan Bolmsjö
Show differing pointer values when comparing pointers instead of the content they point to. It's confusing for a test to say "expected S{.x = 1}, found S{.x = 1}" as illustrated below when it was the pointers that differed. There seems to be different rules for when a pointer is dereferenced by the printing routine depending on its type. I don't fully grok this but it's also illustrated below. const std = @import("std"); const S = struct { x: u32 }; // before: ...expected S{ .x = 1 }, found S{ .x = 1 } // after: ...expected S@7ffcd20b7798, found S@7ffcd20b7790 test "compare_ptr_to_struct" { var a = S{.x = 1}; var b = S{.x = 1}; std.testing.expectEqual(&a, &b); } // before: ...expected u32@7fff316ba31c, found u32@7fff316ba318 // after: ...expected u32@7ffecec622dc, found u32@7ffecec622d8 test "compare_ptr_to_scalar" { var a: u32 = 1; var b: u32 = 1; std.testing.expectEqual(&a, &b); }
2019-09-25mv std/ lib/Andrew Kelley
that's all this commit does. further commits will fix cli flags and such. see #2221