aboutsummaryrefslogtreecommitdiff
path: root/lib/std/testing.zig
AgeCommit message (Collapse)Author
2024-02-27testing.expectFmt() - reuse expectEqualStrings()Travis Staloch
2024-01-08std.testing.expectEqualSlices: some improvementsWooster
This mainly replaces ChunkIterator with std.mem.window and also prints \n, \r, \t using Unicode symbols instead of periods because they're common non-printable characters. This same code exists in std.debug.hexdump. At some point maybe this code could be exposed through a public function. Then we could reuse the code in both places.
2024-01-03Update `std.testing.expectEqual` and friends to use peer type resolutionCarl Åstholm
This commit changes the type of the second parameter to `anytype`, which should make it easier to pass literals to these functions. This change shouldn't *silently* break existing code (the assertions themselves should retain the same behavior as before) but it may result in some new compile errors when struct/union/array literals or builtins like `@bitCast` are used for the second argument. These compile errors can be fixed by explicitly coercing these expressions to the correct type using `@as`.
2023-11-22Revert "Merge pull request #12060 from Vexu/IterableDir"Andrew Kelley
This reverts commit da94227f783ec3c92859c4713b80a668f1183f96, reversing changes made to 8f943b3d33432a26b7e242c1181e4220ed400501. I was against this change originally, but decided to approve it to keep an open mind. After a year of trying it in practice, I firmly believe that the previous way of doing it was better.
2023-11-19lib: correct unnecessary uses of 'var'mlugg
2023-10-15std.testing: disable expectEqualSlices printing for spirvRobin Voetter
2023-10-15std.testing: allow print() at comptimeRobin Voetter
This allows functions like expectEqual to be performed at comptime. If an error is detected, the result is logged via a compile error.
2023-09-23std.testing: expectEqualDeep() - support self-referential structstravisstaloch
2023-09-06std: enable FailingAllocator to fail on resizeGregory Anders
Now that allocator.resize() is allowed to fail, programs may wish to test code paths that handle resize() failure. The simplest way to do this now is to replace the vtable of the testing allocator with one that uses Allocator.noResize for the 'resize' function pointer. An alternative way to support this testing capability is to augment the FailingAllocator (which is already useful for testing allocation failure scenarios) to intentionally fail on calls to resize(). To do this, add a 'resize_fail_index' parameter to the FailingAllocator that causes resize() to fail after the given number of calls.
2023-08-05std.testing.expectEqualSlices: On failure, print address for pointer typesRyan Liptak
When comparing slice elements, `std.meta.eql` is used which only compares pointer address and length to determine equality for pointer types. This previously led to confusing results where `expectEqualSlices` would appear to fail on seemingly equal slices (judging by the output of `expectEqualSlices`. For example: try testing.expectEqualSlices( []const i64, &[_][]const i64{ &[_]i64{ 1, 2, 3 }, &[_]i64{ 5, 5, 5 } }, &[_][]const i64{ &[_]i64{ 1, 2, 3 }, &[_]i64{ 5, 5, 5 } }, ); Previously, this would result in: ============ expected this output: ============= len: 2 (0x2) [0]: { 1, 2, 3 } [1]: { 5, 5, 5 } ============= instead found this: ============== len: 2 (0x2) [0]: { 1, 2, 3 } [1]: { 5, 5, 5 } ================================================ After this commit, it will result in: ============ expected this output: ============= len: 2 (0x2) [0]i64@7ff7e2773758: { 1, 2, 3 } [1]i64@7ff7e2773770: { 5, 5, 5 } ============= instead found this: ============== len: 2 (0x2) [0]i64@7ff7e2773788: { 1, 2, 3 } [1]i64@7ff7e27737a0: { 5, 5, 5 } ================================================
2023-07-25make `@typeInfo` not return private declsJacob G-W
fixes #10731 Thanks @nektro for previous work in #14878 This change creates a small breaking change: It removes the `is_pub` field of a decl in `@typeInfo`
2023-07-12Remove len parameter from splat in standard libantlilja
2023-07-01testing: disable printing for targets that do not support itRobin Voetter
The SPIR-V cannot print the helpful error messages from the std.testing module. This commit overrides the default print function used here to one that only prints if the target supports it. For now, its only done for SPIR-V, but this function could be adapted to more targets that need it.
2023-06-17mem: rename align*Generic to mem.align*Motiejus Jakštys
Anecdote 1: The generic version is way more popular than the non-generic one in Zig codebase: git grep -w alignForward | wc -l 56 git grep -w alignForwardGeneric | wc -l 149 git grep -w alignBackward | wc -l 6 git grep -w alignBackwardGeneric | wc -l 15 Anecdote 2: In my project (turbonss) that does much arithmetic and alignment I exclusively use the Generic functions. Anecdote 3: we used only the Generic versions in the Macho Man's linker workshop.
2023-06-13std.math: hard deprecate obsolete constants (soft deprecated in 0.10)Eric Joldasov
Followup to 5b8ac9821dd25c3e5282130b4d93d6c5b7debb08. Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-29Prevent analysis of functions only referenced at comptimemlugg
The idea here is that there are two ways we can reference a function at runtime: * Through a direct call, i.e. where the function is comptime-known * Through a function pointer This means we can easily perform a form of rudimentary escape analysis on functions. If we ever see a `decl_ref` or `ref` of a function, we have a function pointer, which could "leak" into runtime code, so we emit the function; but for a plain `decl_val`, there's no need to. This change means that `comptime { _ = f; }` no longer forces a function to be emitted, which was used for some things (mainly tests). These use sites have been replaced with `_ = &f;`, which still triggers analysis of the function body, since you're taking a pointer to the function. Resolves: #6256 Resolves: #15353
2023-05-24std: Move std.debug.{TTY.Config,detectTTYConfig} to std.io.ttyLinus Groh
Also get rid of the TTY wrapper struct, which was exlusively used as a namespace - this is done by the tty.zig root struct now. detectTTYConfig has been renamed to just detectConfig, which is enough given the new namespace. Additionally, a doc comment had been added.
2023-05-24std.debug: Rename TTY.Color enum values to snake caseLinus Groh
2023-05-07convert s[start..start+len] to s[start..][0..len]dweiller
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