aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
AgeCommit message (Collapse)Author
2024-05-07remove the autoconf+Make buildsystemQyriad
We're not using it anymore. Any leftover bugs in the Meson buildsystem are now just bugs. Closes #249. Change-Id: I0465a0c37ae819f94d40e7829f5bff046aa63d73
2024-05-07libutil: de-callback-ify computeClosureeldritch horrors
only two users of this function exist. only one used it in a way that even bears resemblance to asynchronicity, and even that one didn't do it right. fully async and parallel computation would have only worked if any getEdgesAsync never calls the continuation it receives itself, only from more derived callbacks running on other threads. calling it directly would cause the decoupling promise to be awaited immediately *on the original thread*, completely negating all nice async effects. Change-Id: I0aa640950cf327533a32dee410105efdabb448df
2024-05-05filetransfer: abort transfer on receiver exceptioneldritch horrors
not doing this will cause transfers that had their readers disappear to linger. with lingering transfers the curl thread can't shut down, which will cause nix itself to not shut down until the transfer finishes some other way (most likely network timeouts). also add a new test for this. Change-Id: Id2401b3ac85731c824db05918d4079125be25b57
2024-05-03libutil: make rewriteStrings soundeldritch horrors
this is used in CA rewriting, replacement of placeholders in derivations, generating scripts for devShells, and some more places. in all of these transitive replacements are unsound, and overlapping replacements would be as well. there even is a test that transitive replacements do not happen (in the CA RewriteSink suite), but none for overlapping replacements. a minimally surprising binary rewriter surely would not do any of these replacements, the only reason we have not seen this break yet is probably that rewriteStrings is only called for store paths and things that look like store paths (and those should never overlap nor admit such transitive replacements) Change-Id: I6fc29f939d5061d9f56c752624a823ece8437c07
2024-05-02Merge changes from topic "profile-v3" into mainQyriad
* changes: nix3-profile: remove check "name" attr in manifests Add profile migration test nix3-profile: make element names stable getNameFromURL(): Support uppercase characters in attribute names nix3-profile: remove indices nix3-profile: allow using human-readable names to select packages implement parsing human-readable names from URLs
2024-05-02getNameFromURL(): Support uppercase characters in attribute namesEelco Dolstra
In particular, this makes it handle 'legacyPackages' correctly. (cherry picked from commit 936a3642264ac159f3f9093710be3465b70e0e89) Upstream-PR: https://github.com/NixOS/nix/pull/9657 Change-Id: Icc4efe02f7f8e90a2970589f72fd3d3cd4418d95
2024-05-02Disallow store path names that are . or .. (plus opt. -)Robert Hensing
As discussed in the maintainer meeting on 2024-01-29. Mainly this is to avoid a situation where the name is parsed and treated as a file name, mostly to protect users. .-* and ..-* are also considered invalid because they might strip on that separator to remove versions. Doesn't really work, but that's what we decided, and I won't argue with it, because .-* probably doesn't seem to have a real world application anyway. We do still permit a 1-character name that's just "-", which still poses a similar risk in such a situation. We can't start disallowing trailing -, because a non-zero number of users will need it and we've seen how annoying and painful such a change is. What matters most is preventing a situation where . or .. can be injected, and to just get this done. (cherry picked from commit f1b4663805a9dbcb1ace64ec110092d17c9155e0) Change-Id: I900a8509933cee662f888c3c76fa8986b0058839
2024-05-02test: Generate distinct hashesRobert Hensing
Gen::just is the constant generator. Don't just return that! (cherry picked from commit 8406da28773f050e00a006e4812e3ecbf919a2a9) Change-Id: Ibfd0bd40f90942077a4720086ce0cd3bfabef79d
2024-05-02test: Generate distinct path namesRobert Hensing
Gen: :just is the constant generator. Don't just return that! (cherry picked from commit 69bbd5852af9b2f0b794162bd1debcdf64fc6648) Change-Id: Id6e58141f5a42a1f67bd11d48c87b32a3ebd0500
2024-05-02parseStorePath: Support leading periodRobert Hensing
(cherry picked from commit b13e6a76b4f289c6db69ffaa7bd35b7e44f2a391) Change-Id: Ie14be437d87d17248f80e1f009aa2a4311ddede6
2024-05-02Revert "StorePath: reject names starting with '.'"Robert Hensing
This reverts commit 24bda0c7b381e1a017023c6f7cb9661fae8560bd. (cherry picked from commit 9ddd0f2af8fd95e1380027a70d0aa650ea2fd5e4) Change-Id: Ideb547e2a8ac911cf39d58d3e0c1553867bdd776
2024-04-30implement parsing human-readable names from URLsQyriad
Based off of commit 257b768436a0e8ab7887f9b790c5b92a7fe51ef5 Upstream-PR: https://github.com/NixOS/nix/pull/8678 Co-authored-by: Felix Uhl <felix.uhl@outlook.com> Change-Id: Idcb7f6191ca3310ef9dc854197f7798260c3f71d
2024-04-15abort with a descriptive message on bad HintFmt usageQyriad
Change-Id: Ic2f05572042343a8160fd971394372f5f2706fc4
2024-04-08Merge "Don't run libstore unit tests in project root" into mainrebecca “wiggles” turner
2024-04-08Don't run libstore unit tests in project rootRebecca Turner
This keeps the libstore unit tests from writing `libstore-unit-tests.xml` to the project root. Change-Id: I0d9909aabf9f3574cc1e72a5ae81daefba9a394b
2024-04-08Fix REPL test parser nitsRebecca Turner
Follow-up to https://gerrit.lix.systems/c/lix/+/546 Change-Id: Ie603f01e5520329bf879e061cea9e3fba45213fd
2024-04-08Merge "Add `PathsSetting`" into mainrebecca “wiggles” turner
2024-04-07Merge pull request #10208 from 9999years/print-strings-directlyRobert Hensing
`:print` strings directly in `nix repl` (cherry picked from commit 3539172fd2f7cee639ce46423c58beca4231f2db) Change-Id: I1972f3bf3b56312851f38288509d371d37f21677 Upstream-PR: https://github.com/NixOS/nix/pull/10208
2024-04-07Add `PathsSetting`Rebecca Turner
Change-Id: I1165f6ef033a5f757ca3716d3f8008ba36b01fd0
2024-04-06Merge "Rewrite REPL test parser" into mainrebecca “wiggles” turner
2024-04-05Rewrite REPL test parserRebecca Turner
- Use a recursive descent parser so that it's easy to extend. - Add `@args` to enable customizing command-line arguments - Add `@should-start` to enable `nix repl` tests that error before entering the REPL - Make sure to read all stdout output before comparing. This catches some extra output we were tossing out before! Change-Id: I5522555df4c313024ab15cd10f9f04e7293bda3a
2024-04-05Revert "libutil: drop Pool resources on exceptional free"eldritch horrors
This reverts commit de2884b82b376d10de5c400d8e73bc7d98f195d2. Change-Id: I1fa301149d7c2ed3d266a40c15b2d010e12e44e6
2024-04-03Add `EscapeStringOptions` and `escapeString` testsRebecca Turner
Change-Id: I86ead2f969c9e03c9edfa51bbc92ee06393fd7d6
2024-03-31Merge changes Ib62d3d68,Ic3e7affe into mainjade
* changes: Make things that can throw not noexcept anymore Fix various clang-tidy lints
2024-03-31libutil: remove Pool::flushBadeldritch horrors
this was never actually used, and bad design in the first place—why should a bad resource be put back into the idle pool? just drop it. Change-Id: Idab8774bee19dadae0209d404c4fb86dd4aeba1e
2024-03-30libutil: drop Pool resources on exceptional freeeldritch horrors
if a scope owning a resource does not gracefully drop that resource while handling exceptions from deeper down the call stack we should assume the resource is invalid state and drop it. currently it *is* true that such cases do not cause resources to be freed, but thanks to validator misuses this has so far not caused any larger problem. Change-Id: Ie4f91bcd60a64d05c5ff9d22cc97954816d13b97
2024-03-29Add `pre-commit` checksRebecca Turner
The big ones here are `trim-trailing-whitespace` and `end-of-file-fixer` (which makes sure that every file ends with exactly one newline character). Change-Id: Idca73b640883188f068f9903e013cf0d82aa1123
2024-03-29Fix various clang-tidy lintsJade Lovelace
* some things that can throw are marked noexcept yet the linter seems to think not. Maybe they can't throw in practice. I would rather not have the UB possibility in pretty obvious cold paths. * various default-case-missing complaints * a fair pile of casts from integer to character, which are in fact deliberate. * an instance of <https://clang.llvm.org/extra/clang-tidy/checks/bugprone/move-forwarding-reference.html> * bugprone-not-null-terminated-result on handing a string to curl in chunks of bytes. our usage is fine. * reassigning a unique_ptr by CRIMES instead of using release(), then using release() and ignoring the result. wild. let's use release() for its intended purpose. Change-Id: Ic3e7affef12383576213a8a7c8145c27e662513d
2024-03-29Move `escapeString` to its own fileRebecca Turner
Change-Id: Ie5c954ec73c46c9d3c679ef99a83a29cc7a08352
2024-03-29meson: add missing explicit dependency on nlohmann_jsonWinter
Without this, the Meson setup won't bail out if nlohmann_json is missing, leading to subpar DX (and maybe worse, but I'm not entirely sure). Change-Id: I5913111060226b540dcf003257c99a08e84da0de
2024-03-29Merge "Move `DebugChar` into its own file" into mainrebecca “wiggles” turner
2024-03-29Merge "Remove `HintFmt::operator%`" into mainwiggles dog
2024-03-28Move `DebugChar` into its own fileRebecca Turner
Change-Id: Ia40549e5d0b78ece8dd0722c3a5a032b9915f24b
2024-03-28Merge "Move `shell_words` into its own file" into mainwiggles dog
2024-03-27HOT SALE: 15% off your build times!Jade Lovelace
This was achieved by running maintainers/buildtime_report.sh on the build directory of a meson build, then asking "why the heck is json eating our build times", and strategically moving the json using bits out of widely included headers. It turns out that putting literally any metrics whatsoever into the build had immediate and predictable results. Results are 1382.5s frontend time -> 1175.4s frontend time, back end time approximately invariant. Related: https://git.lix.systems/lix-project/lix/issues/159 Change-Id: I7edea95c8536203325c8bb4dae5f32d727a21b2d
2024-03-26Move `shell_words` into its own fileRebecca Turner
Change-Id: I34c0ebfb6dcea49bf632d8880e04075335a132bf
2024-03-26Remove `HintFmt::operator%`Rebecca Turner
Change-Id: Ibcf1a7848b4b18ec9b0807628ff229079ae7a0fe
2024-03-26meson: implement unit testsQyriad
Unit tests can be run with `meson test -C build --suite check`. `--suite check` is optional, as right now that's the only test suite, but when functional tests are added those will be in a separate suite. Change-Id: I7f22f1cde4b489b3cdb5f9a36a544f0c409fcc1f
2024-03-18Merge "Delete hasPrefix and hasSuffix from the codebase" into mainjade
2024-03-18use byte indexed locations for PosIdxeldritch horrors
we now keep not a table of all positions, but a table of all origins and their sizes. position indices are now direct pointers into the virtual concatenation of all parsed contents. this slightly reduces memory usage and time spent in the parser, at the cost of not being able to report positions if the total input size exceeds 4GiB. this limit is not unique to nix though, rustc and clang also limit their input to 4GiB (although at least clang refuses to process inputs that are larger, we will not). this new 4GiB limit probably will not cause any problems for quite a while, all of nixpkgs together is less than 100MiB in size and already needs over 700MiB of memory and multiple seconds just to parse. 4GiB worth of input will easily take multiple minutes and over 30GiB of memory without even evaluating anything. if problems *do* arise we can probably recover the old table-based system by adding some tracking to Pos::Origin (or increasing the size of PosIdx outright), but for time being this looks like more complexity than it's worth. since we now need to read the entire input again to determine the line/column of a position we'll make unsafeGetAttrPos slightly lazy: mostly the set it returns is only used to determine the file of origin of an attribute, not its exact location. the thunks do not add measurable runtime overhead. notably this change is necessary to allow changing the parser since apparently nothing supports nix's very idiosyncratic line ending choice of "anything goes", making it very hard to calculate line/column positions in the parser (while byte offsets are very easy). (cherry picked from commit 5d9fdab3de0ee17c71369ad05806b9ea06dfceda) Change-Id: Ie0b2430cb120c09097afa8c0101884d94f4bbf34
2024-03-17Delete hasPrefix and hasSuffix from the codebaseJade Lovelace
These now have equivalents in the standard lib in C++20. This change was performed with a custom clang-tidy check which I will submit later. Executed like so: ninja -C build && run-clang-tidy -checks='-*,nix-*' -load=build/libnix-clang-tidy.so -p .. -fix ../tests | tee -a clang-tidy-result Change-Id: I62679e315ff9e7ce72a40b91b79c3e9fc01b27e9
2024-03-17builtins.nixVersion: return fixed fake versionJade Lovelace
This builtin is only going to cause us problems because we are not Nix, so let's just falsify being in the 2.18 series, since that is the closest target that has any meaning. In future we might want to have a better feature detection mechanism, for when we actually add stuff to some builtin's attr set argument. But builtins.nixVersion is just going to be hopelessly broken and it should be stubbed out. Fixes https://git.lix.systems/lix-project/lix/issues/144 Change-Id: Id7390b32a29c6147f2977737d81846320de5d67e
2024-03-15Implement a repl characterization test systemJade Lovelace
This allows for automating using the repl without needing a PTY, with very easy to write test files. Change-Id: Ia8d7854edd91f93477638942cb6fc261354e6035
2024-03-14Implement a parser for a literate testing system for the replJade Lovelace
This parser can be reused for other purposes. It's inspired by https://bitheap.org/cram/ Although eelco's impostor exists https://github.com/mobusoperandi/eelco, it is not very nice to depend on out of tree testing frameworks with no way to customize them. Change-Id: Ifca50177e09730182baf0ebf829c3505bbb0274a
2024-03-13support <program>_ENV variableseldritch horrors
this lets us set per-test-program environment variables rather than only a single, global default. this was supported in nix originally but might've gone partially missing in the upstream backports process? Change-Id: Iad0919841b1b6d11e0b7ebd3920449a62f544e77
2024-03-11import the revisions to the characterization test framework from cppnixJade Lovelace
This has some Flaws for sure (like, it is going to be a bit stretched to use for repl characterization), but it is a start. Change-Id: I258c8beb3aee236f45818a03be83bcda858120c9
2024-03-09Pretty-print values in the REPLeldritch horrors
Pretty-print values in the REPL by printing each item in a list or attrset on a separate line. When possible, single-item lists and attrsets are printed on one line, as long as they don't contain a nested list, attrset, or thunk. Before: ``` { attrs = { a = { b = { c = { }; }; }; }; list = [ 1 ]; list' = [ 1 2 3 ]; } ``` After: ``` { attrs = { a = { b = { c = { }; }; }; }; list = [ 1 ]; list' = [ 1 2 3 ]; } ``` (cherry picked from commit c0a15fb7d03dfb8f53bc6726c414bc88aa362592) Change-Id: Ia2b41849165a5ddb63f7a8c272a2476b3e4292df
2024-03-09Merge pull request #9925 from 9999years/fmt-cleanupeldritch horrors
Cleanup `fmt.hh` (cherry picked from commit 47a1dbb4b8e7913cbb9b4d604728b912e76e4ca0) Change-Id: Id076a45cb39652f437fe3f8bda10c310a9894777
2024-03-09libexpr: Support structured error classeseldritch horrors
While preparing PRs like #9753, I've had to change error messages in dozens of code paths. It would be nice if instead of EvalError("expected 'boolean' but found '%1%'", showType(v)) we could write TypeError(v, "boolean") or similar. Then, changing the error message could be a mechanical refactor with the compiler pointing out places the constructor needs to be changed, rather than the error-prone process of grepping through the codebase. Structured errors would also help prevent the "same" error from having multiple slightly different messages, and could be a first step towards error codes / an error index. This PR reworks the exception infrastructure in `libexpr` to support exception types with different constructor signatures than `BaseError`. Actually refactoring the exceptions to use structured data will come in a future PR (this one is big enough already, as it has to touch every exception in `libexpr`). The core design is in `eval-error.hh`. Generally, errors like this: state.error("'%s' is not a string", getAttrPathStr()) .debugThrow<TypeError>() are transformed like this: state.error<TypeError>("'%s' is not a string", getAttrPathStr()) .debugThrow() The type annotation has moved from `ErrorBuilder::debugThrow` to `EvalState::error`. (cherry picked from commit c6a89c1a1659b31694c0fbcd21d78a6dd521c732) Change-Id: Iced91ba4e00ca9e801518071fb43798936cbd05a
2024-03-09Merge pull request #9928 from 9999years/error-messages-in-nix-repleldritch horrors
Improve error printing in `nix repl` (cherry picked from commit a8050d9b83052e4b5c52bf2d116381aedec3a93e) Change-Id: I588f92d1dd4c546c98788b71403cc034f5e7129a