aboutsummaryrefslogtreecommitdiff
path: root/lib/std/testing.zig
AgeCommit message (Collapse)Author
2022-06-23checkAllAllocationFailures: add possibility of SwallowedOutOfMemoryError ↵Ryan Liptak
(split from NondeterministicMemoryUsage) Inducing failure but not getting OutOfMemory back is not as much of a problem as never inducing failure when it was expected to be induced, so treating them differently and allowing them to be handled differently by the caller is useful. For example, the current implementation of `std.HashMapUnmanaged.getOrPutContextAdapted` always tries to grow and then recovers from OutOfMemory by attempting a lookup of an existing key. If this function is used (i.e. from `std.BufMap.putMove`) with `checkAllAllocationFailures`, then we'd have previously triggered `error.NondeterministicMemoryUsage`, but the real cause is that `OutOfMemory` is being recovered from and so the error is being swallowed. The new error allows us to both understand what's happening easier and to catch it and ignore it if we're okay with the code we're testing handling `error.OutOfMemory` without always bubbling it up.
2022-06-23Integrate FailingAllocator stack trace with testing.checkAllAllocationFailuresRyan Liptak
2022-05-26std.testing: remove tight coupling with executing zig as child processAndrew Kelley
This tight coupling causes problems for various targets, requires hacky "get args" functionality, and bungles relative file system paths, making invalid assumptions about the zig-cache directory. In short, these are not unit tests; these should be standalone tests instead. Reverts e5d4a694ea7dd251e10d6434c9321b5e0a548d4b Reverts d976456ef665bf0aba3a83a8e7fccb4a92b2d3b2 Reverts dbbda0f41a7c5e214801925f8447a15193c3c731 Closes #11542
2022-04-29std: Do not allocate the result for ChildProcess.initJimmi Holst Christensen
Instead, just return ChildProcess directly. This structure does not require a stable address, so we can put it on the stack just fine. If someone wants it on the heap they should do. const proc = try allocator.create(ChildProcess); proc.* = ChildProcess.init(args, allocator);
2022-04-28Revert "Merge pull request #11214 from iddev5/ay-build-runner"Andrew Kelley
This reverts commit 75c9936737a6ba991d4ef187ddc9d51bc0ad0998, reversing changes made to 7f13f5cd5f5a518638b15d7225eae2d88ec1efb5. I don't think `runZigBuild` belongs in std.testing. We already have `test/standalone/*` for this. Additionally test names should explain what they are testing rather than referencing GitHub issue numbers.
2022-04-28Revert "std.testing: add writeZigFile for TmpDir"Andrew Kelley
This reverts commit 7f13f5cd5f5a518638b15d7225eae2d88ec1efb5. I'd like to review this one before it goes in. This is an awfully specific API that I don't think belongs in std.testing. Also I don't want any code snippets in doc strings. We have doctests for that.
2022-04-28Merge pull request #11532 from ziglang/compiler-rt-mathAndrew Kelley
compiler-rt math functions reorg
2022-04-28Merge pull request #11214 from iddev5/ay-build-runnerVeikka Tuominen
std: explicitly handle error.UnexpectedExitCode in build_runner
2022-04-28std.testing: add writeZigFile for TmpDirmatu3ba
* remove need for manual string concatenation for building binaries in test blocks * include small program snippet to show how to get binary path with subslicing
2022-04-27compiler-rt: math functions reorgAndrew Kelley
* unify the logic for exporting math functions from compiler-rt, with the appropriate suffixes and prefixes. - add all missing f128 and f80 exports. Functions with missing implementations call other functions and have TODO comments. - also add f16 functions * move math functions from freestanding libc to compiler-rt (#7265) * enable all the f128 and f80 code in the stage2 compiler and behavior tests (#11161). * update std lib to use builtins rather than `std.math`.
2022-04-16stdlib std.os: Improve wasi-libc parity for WASI CWD emulationCody Tapscott
Two major changes here: 1. We store the CWD as a simple `[]const u8` and lookup Preopens for every absolute or CWD-referenced file operation, based on the Preopen with the longest match (i.e. most specific path) 2. Preorders are normalized to POSIX absolute paths at init time. Behavior depends on the "cwd_root" parameter of `initPreopensWasi`: `cwd_root` is used for any Preopens that start with "." For example: "./foo/bar" - inits to -> "{cwd_root}/foo/bar" "foo/bar" - inits to -> "/foo/bar" "/foo/bar" - inits to -> "/foo/bar" `cwd_root` must be an absolute path. Using "/" as `cwd_root` gives behavior similar to wasi-libc.
2022-04-04std.testing: add function zigBuild for running zig build runner commandsiddev5
2022-04-04Add `std.testing.checkAllAllocationFailures`Ryan Liptak
Adds a function that allows checking for memory leaks (and other problems) by taking advantage of the FailingAllocator and inducing failure at every allocation point within the provided `test_fn` (based on the strategy employed in the Zig parser tests, which can now use this function).
2022-03-27std.testing: add methods tmpDirPath, getTestArgs, buildExematu3ba
continuation of #11093 to simplify testing IPC * use cases - get path to temporary directory - get the test arguments inside test block for reusage - build executables from text within test blocks, ie to test IPC * missing conventions - how to name and debug test cases - where do simple+repititve build commands for testing belong
2022-03-18stage2: improve `@typeName`Andrew Kelley
* make it always return a fully qualified name. stage1 is inconsistent about this. * AstGen: fix anon_name_strategy to correctly be `func` when anon type creation happens in the operand of the return expression. * Sema: implement type names for the "function" naming strategy. * Put "enum", "union", "opaque", or "struct" in place of "anon" when creating respective anonymous Decl names. * std.testing: add `expectStringStartsWith`. Didn't end up using it after all. Also this enables the real test runner for stage2 LLVM backend (sans wasm32) since it works now.
2022-03-17std.testing: fix incorrect docs that mentioned abortingAndrew Kelley
At some point we changed these functions to return errors instead of aborting.
2022-03-08std.json: correctly handle sentinel terminated slicesBenjamin San Souci
2022-02-18std.testing.refAllDecls: force decl to be analyzed with just `@field`Lee Cannon
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-02-13std: force refAllDecls to actually resolve all declsVeikka Tuominen
Only about half of the tests in std were actually being run (918 vs 2144).
2022-01-31a small crusade against std.meta.declarationsAndrew Kelley
2022-01-12stage2: implement `@ctz` and `@clz` including SIMDAndrew Kelley
AIR: * `array_elem_val` is now allowed to be used with a vector as the array type. * New instructions: splat, vector_init AstGen: * The splat ZIR instruction uses coerced_ty for the ResultLoc, avoiding an unnecessary `as` instruction, since the coercion will be performed in Sema. * Builtins that accept vectors now ignore the type parameter. Comment from this commit reproduced here: The accepted proposal #6835 tells us to remove the type parameter from these builtins. To stay source-compatible with stage1, we still observe the parameter here, but we do not encode it into the ZIR. To implement this proposal in stage2, only AstGen code will need to be changed. Sema: * `clz` and `ctz` ZIR instructions are now handled by the same function which accept AIR tag and comptime eval function pointer to differentiate. * `@typeInfo` for vectors is implemented. * `@splat` is implemented. It takes advantage of `Value.Tag.repeated` 😎 * `elemValue` is implemented for vectors, when the index is a scalar. Handling a vector index is still TODO. * Element-wise coercion is implemented for vectors. It could probably be optimized a bit, but it is at least complete & correct. * `Type.intInfo` supports vectors, returning int info for the element. * `Value.ctz` initial implementation. Needs work. * `Value.eql` is implemented for arrays and vectors. LLVM backend: * Implement vector support when lowering `array_elem_val`. * Implement vector support when lowering `ctz` and `clz`. * Implement `splat` and `vector_init`.
2021-12-21fix expectStringEndsWith error output.Stephen Lumenta
before it started outputting the actual starting, not ending characters.
2021-11-30allocgate: renamed getAllocator function to allocatorLee Cannon
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-13Use std.buuiltin instead of importing builtinTakeshi Yoneda
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-07-27WASI,libc: enable tests.Takeshi Yoneda
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-21std, src, doc, test: remove unused variablesJacob G-W
2021-05-15Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * build.zig * src/Compilation.zig * src/codegen/spirv/spec.zig * src/link/SpirV.zig * test/stage2/darwin.zig - this one might be problematic; start.zig looks for `main` in the root source file, not `_main`. Not sure why there is an underscore there in master branch.
2021-05-15std.testing: Added newline to the error messagesZapAnton
Added newline to every `std.debug.print` message. Closes https://github.com/ziglang/zig/issues/8777
2021-05-08Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * doc/langref.html.in * lib/std/enums.zig * lib/std/fmt.zig * lib/std/hash/auto_hash.zig * lib/std/math.zig * lib/std/mem.zig * lib/std/meta.zig * test/behavior/alignof.zig * test/behavior/bitcast.zig * test/behavior/bugs/1421.zig * test/behavior/cast.zig * test/behavior/ptrcast.zig * test/behavior/type_info.zig * test/behavior/vector.zig Master branch added `try` to a bunch of testing function calls, and some lines also had changed how to refer to the native architecture and other `@import("builtin")` stuff.
2021-05-08allow tests to failVeikka Tuominen
2021-04-15std: change `@import("builtin")` to `std.builtin`Andrew Kelley
2021-04-09testing: Avoid @import-ing builtins moduleLemonBoy
Use std.builtins instead.
2021-04-09testing: Avoid printing expected line twiceLemonBoy
When the line has trailing whitespace we already print it with a carriage return symbol at the end, don't print it one more time.
2021-04-09testing: Use indexOfScalar instead of indexOfLemonBoy
2021-03-28std/base64: cleanups & support url-safe and other non-padded variantsFrank Denis
This makes a few changes to the base64 codecs. * The padding character is optional. The common "URL-safe" variant, in particular, is generally not used with padding. This is also the case for password hashes, so having this will avoid code duplication with bcrypt, scrypt and other functions. * The URL-safe variant is added. Instead of having individual constants for each parameter of each variant, we are now grouping these in a struct. So, `standard_pad_char` just becomes `standard.pad_char`. * Types are not `snake_case`'d any more. So, `standard_encoder` becomes `standard.Encoder`, as it is a type. * Creating a decoder with ignored characters required the alphabet and padding. Now, `standard.decoderWithIgnore(<ignored chars>)` returns a decoder with the standard parameters and the set of ignored chars. * Whatever applies to `standard.*` obviously also works with `url_safe.*` * the `calcSize()` interface was inconsistent, taking a length in the encoder, and a slice in the encoder. Rename the variant that takes a slice to `calcSizeForSlice()`. * In the decoder with ignored characters, add `calcSizeUpperBound()`, which is more useful than the one that takes a slice in order to size a fixed buffer before we have the data. * Return `error.InvalidCharacter` when the input actually contains characters that are neither padding nor part of the alphabet. If we hit a padding issue (which includes extra bits at the end), consistently return `error.InvalidPadding`. * Don't keep the `char_in_alphabet` array permanently in a decoder; it is only required for sanity checks during initialization. * Tests are unchanged, but now cover both the standard (padded) and the url-safe (non-padded) variants. * Add an error set, rename `OutputTooSmallError` to `NoSpaceLeft` to match the `hex2bin` equivalent.
2021-03-14std: Replace testing fns for floating-point valuesLemonBoy
Beside handling NaNs and other non-numeric values better we finally offer the same pair of testing predicates in math and testing.
2021-02-09require specifier for arrayish typesJonathan Marler
2021-01-30Replace @TagType uses, mostly with std.meta.TagTadeo Kondrak
2021-01-22std: Update `test ""` to `test` where it makes senseLemonBoy
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