aboutsummaryrefslogtreecommitdiff
path: root/lib/std/testing.zig
AgeCommit message (Collapse)Author
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-01-29std: add expectEqualDeep (#13995)Jiacai Liu
2022-12-17std.builtin: rename Type.UnionField and Type.StructField's field_type to typer00ster91
2022-12-15std.debug.TTY: Fix colors not resetting on WindowsRyan Liptak
This fixes a regression introduced in #12298 where colors would never reset in a Windows console because the attributes would be queried on every `setColor` call, and then try to 'reset' the attributes to what it just queried (i.e. it was essentially doing a complicated no-op on .Reset). This fixes the problem while (I think) keeping with the spirit of the changes in #12298--that is, `TTY.Config` is not specifically tied to stderr like it was before #12298. To that end, detectTTYConfig now takes a `File` and that's what gets used to query the initial attributes to reset to. (for context, before #12298, the first `setColor` call is where the reset attributes would get queried and it would always use stderr to do it)
2022-12-13Merge pull request #13907 from Vexu/call-mergeAndrew Kelley
Remove `stack` option from `@call`
2022-12-13update usages of `@call`Veikka Tuominen
2022-12-13fix(terminal): handle some possible errors and resolve TODOsr00ster91
2022-12-09Eliminate `BoundFn` type from the languageVeikka Tuominen
Closes #9484
2022-12-09std.testing: Fully absorb expectEqualBytes into expectEqualSlicesRyan Liptak
- In #13720, expectEqualBytes was added as a standalone function - In #13723, expectEqualSlices was made to use expectEqualBytes when the type was u8 - In this commit, expectEqualSlices has fully absorbed expectEqualBytes, and expectEqualBytes itself has been removed For non-`u8` types, expectEqualSlices will now work similarly to expectEqualBytes (highlighting diffs in red), but will use a full line for each index and therefore will only print a maximum of 16 indexes.
2022-12-07AstGen: make `@compileError` operand implicitly comptimeVeikka Tuominen
This matches the language reference.
2022-12-01std.testing: Improve expectEqualBytes for large inputs and make ↵Ryan Liptak
expectEqualSlices use it `expectEqualBytes` will now truncate the hexdump of each input to a maximum window of 256 bytes, which makes it safe to use for arbitrarily large inputs. Therefore, it can be used in `expectEqualSlices` when the type is u8.
2022-11-30std.testing: Add expectEqualBytes that outputs hexdumps with diffs ↵Ryan Liptak
highlighted in red The coloring is controlled by `std.debug.detectTTYConfig` so it will be disabled when appropriate.
2022-11-26std.os: Fix std.os.chdir for WASICody Tapscott
Test coverage was lacking for chdir() on WASI, allowing this to regress. This change makes os.chdir() compile again, and improves the test logic to use our standard CWD support for WASI.
2022-11-12Make invalidFmtError public and use in place of compileErrors for bad format ↵Nick Cernis
strings (#13526) * Export invalidFmtErr To allow consistent use of "invalid format string" compile error response for badly formatted format strings. See https://github.com/ziglang/zig/pull/13489#issuecomment-1311759340. * Replace format compile errors with invalidFmtErr - Provides more consistent compile errors. - Gives user info about the type of the badly formated value. * Rename invalidFmtErr as invalidFmtError For consistency. Zig seems to use “Error” more often than “Err”. * std: add invalid format string checks to remaining custom formatters * pass reference-trace to comp when building build file; fix checkobjectstep
2022-10-05fix(text): hyphenation and other fixesr00ster91
2022-09-29docs: minor improvementsr00ster91
Just some minor improvements when passing by.
2022-09-29fix(std.testing.refAllDeclsRecursive): silently return if !builtin.is_testr00ster91
2022-09-29testing: fix copy paste typoJacob Young
2022-09-14Move std.testing.zig_exe_path into build optionsMartin Wickham
2022-07-25std.testing: make the caret indicator line more helpfulr00ster
2022-07-24std: compile error on invalid testing allocator usageAli Chraghi
2022-07-16std.testing: add `refAllDeclsRecursive` functionalichraghi
2022-07-16Fix checkAllAllocationFailures being too strict when checking arg typesRyan Liptak
Before this would fail to compile: ``` fn testFn(alloc: std.mem.Allocator, arr: []const u8) !void { _ = alloc; _ = arr; } test "checkAll" { var arr = [_]u8{ 1, 2, 3 }; try std.testing.checkAllAllocationFailures(std.testing.allocator, testFn, .{arr[0..]}); } ``` with the error `error: Unexpected type for extra argument at index 0: expected []const u8, found *[3]u8` By removing this strict equality check, we allow the type checking to be done during the `@field(args, arg_i_str) = @field(extra_args, field.name);` instead, which then allows for things like type coercion to work, but still will give a compile error if the types are incorrect. So, after this change, the above succeeds (because `*[3]u8` can be coerced to `[]const u8`). The new compile error when providing an incorrect type that can't be coerced looks like this: ``` zig/lib/std/testing.zig:639:35: error: expected type '[]const u8', found '*[3]u32' @field(args, arg_i_str) = @field(extra_args, field.name); ^ ```
2022-07-15std.fs: remove `OpenDirOptions.iterate`Veikka Tuominen
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