aboutsummaryrefslogtreecommitdiff
path: root/tests/lang
AgeCommit message (Collapse)Author
2023-12-01Put functional tests in `tests/functional`John Ericson
I think it is bad for these reasons when `tests/` contains a mix of functional and integration tests - Concepts is harder to understand, the documentation makes a good unit vs functional vs integration distinction, but when the integration tests are just two subdirs within `tests/` this is not clear. - Source filtering in the `flake.nix` is more complex. We need to filter out some of the dirs from `tests/`, rather than simply pick the dirs we want and take all of them. This is a good sign the structure of what we are trying to do is not matching the structure of the files. With this change we have a clean: ```shell-session $ git show 'HEAD:tests' tree HEAD:tests functional/ installer/ nixos/ ``` (cherry picked from commit 68c81c737571794f7246db53fb4774e94fcf4b7e)
2023-10-01pathExists: isDir when endswith /.Robert Hensing
(cherry picked from commit f8a3893e8d77ce4a6e23719a0b2d88464cb84b9c)
2023-08-25pathExists: isDir when endswith /Robert Hensing
Fixes https://github.com/NixOS/nix/issues/8838
2023-08-25tests/lang/eval-okay-pathexists: Add casesRobert Hensing
2023-07-31toJSON: Add attribute path to traceRobert Hensing
2023-07-25Add `parseFlakeRef` and `flakeRefToString` builtins (#8670)Alex Ameen
Over the last year or so I've run into several use cases where I need to parse and/or serialize URLs for use by `builtins.fetchTree` or `builtins.getFlake`, largely in order to produce _lockfile-like_ files for lang2nix frameworks or tools which use `nix` internally to drive builds. I've gone through the painstaking process of emulating `nix::FlakeRef::fromAttrs` and `nix::parseFlakeRef` several times with mixed success; but these are difficult to create and even harder to maintain if I hope to stay aligned with changes to the real parser/serializer. I understand why adding new `builtins` isn't something we want to do flagrantly. I'm recommending this addition simply because I keep encountering use cases where I need to parse/serialize these URIs in `nix` expressions, and I want a reliable solution. Co-authored-by: Eelco Dolstra <edolstra@gmail.com> Co-authored-by: John Ericson <git@JohnEricson.me>
2023-07-21parser: merge nested dynamic attributesNaïm Favier
Fixes https://github.com/NixOS/nix/issues/7115
2023-07-13Fix race condition in the language testsJohn Ericson
When we pipe to `>(...)` like that, we unfortunately don't wait for the process to finish. Better to just substitute the file. Also, use the "unified" diff output that people (including myself) are more familiar with, thanks to Git.
2023-07-11Expanded test suiteMathnerd314
* Lang now verifies errors and parse output * Some new miscellaneous tests * Easy way to update the tests * Document workflow in manual * Use `!` not `~` as separater char for sed It is confusing to use `~` when we are talking about paths and home directories! * Test test suite itself (`test/lang-test/infra.sh`) Additionally, run shellcheck on `tests/lang.sh` to help ensure it is correct, now that is is more complex. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-07-10Fix test file nameJohn Ericson
It's UTF-8, not UFT-8.
2023-06-15rename files referring to antiquotationValentin Gagarin
since we renamed this to string interpolation, file names should be fixed up as well
2023-06-09Parse TOML timestamps (#8120)Andrea Bedini
Currently `fromTOML` throws an exception when encountering a timestamp since the Nix language lacks a way to represent them. This patch changes this beaviour and makes `fromTOML` parse timestamps as attrsets of the format { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; } This is guarded by an experimental feature flag to leave room for iterating on the representation.
2023-05-25primops: lazy evaluation of replaceStrings replacementspolykernel
The primop `builtins.replaceStrings` currently always strictly evaluates the replacement strings, however time and space are wasted for their computation if the corresponding pattern do not occur in the input string. This commit makes the evaluation of the replacement strings lazy by deferring their evaluation to when the corresponding pattern are matched and memoize the result for efficient retrieval on subsequent matches. The testcases for replaceStrings was updated to check for lazy evaluation of the replacements. A note was also added in the release notes to document the behavior change.
2023-02-19Merge pull request #7158 from sternenseemann/foldl-strict-accumulation-valueValentin Gagarin
2023-01-23Merge pull request #7447 from aakropotkin/read-file-typeRobert Hensing
Read file type
2023-01-22primop: add readFileType, optimize readDirAlex Ameen
Allows checking directory entry type of a single file/directory. This was added to optimize the use of `builtins.readDir` on some filesystems and operating systems which cannot detect this information using POSIX's `readdir`. Previously `builtins.readDir` would eagerly use system calls to lookup these filetypes using other interfaces; this change makes these operations lazy in the attribute values for each file with application of `builtins.readFileType`.
2023-01-21Expand tests to reproduce #7655John Ericson
The original `builtins.getContext` test from 1d757292d0cb78beec32fcdfe15c2944a4bc4a95 would have caught this. The problem is that b30be6b450f872f8be6dc8afa28f4b030fa8d1d1 adding `builtins.appendContext` modified that test to make it test too much at once, rather than adding a separate test. We now have isolated tests for both functions, and also a property test showing everything put together (in the form of an eta rule for strings with context). This is better coverage and properly reproduces the bug.
2023-01-02Merge pull request #5941 from hercules-ci/optimize-intersectAttrsThéophane Hufschmitt
Optimize intersectAttrs performance
2023-01-02antiquotation -> string interpolationValentin Gagarin
as proposed by @mkaito[1] and @tazjin[2] and discussed with @edolstra and Nix maintainers [1]: https://github.com/NixOS/nix.dev/pull/267#issuecomment-1270076332 [2]: https://github.com/NixOS/nix.dev/pull/267#issuecomment-1270201979 Co-authored-by: John Ericson <git@JohnEricson.me> Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
2022-12-24Optimize intersectAttrs performanceRobert Hensing
Always traverse the shortest set.
2022-12-12Fix reference to test directory pathEelco Dolstra
2022-12-12Enable some language tests that were accidentally disabledEelco Dolstra
This didn't run because the corresponding .exp file didn't exist.
2022-10-25Merge pull request #7196 from sternenseemann/reenable-eval-okay-eqThéophane Hufschmitt
tests/lang: re-enable eval-okay-eq.nix tests
2022-10-19tests/lang: re-enable eval-okay-eq.nix testssternenseemann
This is a really old test case (which was originally written before the proper Nix syntax). The tested deep comparison behavior was implemented and reverted soon after due to performance problems, but it has been restored in today's Nix again (thanks to the derivation comparison optimization, presumably).
2022-10-16primops: make nature of foldl' strictness clearersternenseemann
* Clarify the documentation of foldl': That the arguments are forced before application (?) of `op` is necessarily true. What is important to stress is that we force every application of `op`, even when the value turns out to be unused. * Move the example before the comment about strictness to make it less confusing: It is a general example and doesn't really showcase anything about foldl' strictness. * Add test cases which nail down aspects of foldl' strictness: * The initial accumulator value is not forced unconditionally. * Applications of op are forced. * The list elements are not forced unconditionally.
2022-10-08tests/lang/eval-okay-versions.nix: add test for previous commitAdam Joseph
This commit adds a test covering the discrepancy between parseDrvName's implementation and documentation (the discrepancy was eliminated in the previous commit).
2022-05-25Handle EOFs in string literals correctlyEelco Dolstra
We can't return a STR token without setting a valid StringToken, otherwise the parser will crash. Fixes #6562.
2022-05-05Change json example to be originalthkoch2001
Closes: #3391
2022-02-02Merge branch 'parser-improvements' of https://github.com/pennae/nixEelco Dolstra
2022-01-25Fix parsing of variable names that are a suffix of '__curPos'regnat
Follow-up from #5969 Fix #5982
2022-01-24Fix parsing of variable names that are a prefix of '__curPos'Eelco Dolstra
Fixes $ nix-instantiate --parse -E 'x: with x; _' (x: (with x; __curPos))
2022-01-19defer formals duplicate check for incresed efficiency all roundpennae
if we defer the duplicate argument check for lambda formals we can use more efficient data structures for the formals set, and we can get rid of the duplication of formals names to boot. instead of a list of formals we've seen and a set of names we'll keep a vector instead and run a sort+dupcheck step before moving the parsed formals into a newly created lambda. this improves performance on search and rebuild by ~1%, pure parsing gains more (about 4%). this does reorder lambda arguments in the xml output, but the output is still stable. this shouldn't be a problem since argument order is not semantically important anyway. before nix search --no-eval-cache --offline ../nixpkgs hello Time (mean ± σ): 8.550 s ± 0.060 s [User: 6.470 s, System: 1.664 s] Range (min … max): 8.435 s … 8.666 s 20 runs nix eval -f ../nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix Time (mean ± σ): 346.7 ms ± 2.1 ms [User: 312.4 ms, System: 34.2 ms] Range (min … max): 343.8 ms … 353.4 ms 20 runs nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system' Time (mean ± σ): 2.720 s ± 0.031 s [User: 2.415 s, System: 0.231 s] Range (min … max): 2.662 s … 2.780 s 20 runs after nix search --no-eval-cache --offline ../nixpkgs hello Time (mean ± σ): 8.462 s ± 0.063 s [User: 6.398 s, System: 1.661 s] Range (min … max): 8.339 s … 8.542 s 20 runs nix eval -f ../nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix Time (mean ± σ): 329.1 ms ± 1.4 ms [User: 296.8 ms, System: 32.3 ms] Range (min … max): 326.1 ms … 330.8 ms 20 runs nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system' Time (mean ± σ): 2.687 s ± 0.035 s [User: 2.392 s, System: 0.228 s] Range (min … max): 2.626 s … 2.754 s 20 runs
2022-01-03add zipAttrsWith primoppennae
nixpkgs can save a good bit of eval memory with this primop. zipAttrsWith is used quite a bit around nixpkgs (eg in the form of recursiveUpdate), but the most costly application for this primop is in the module system. it improves the implementation of zipAttrsWith from nixpkgs by not checking an attribute multiple times if it occurs more than once in the input list, allocates less values and set elements, and just avoids many a temporary object in general. nixpkgs has a more generic version of this operation, zipAttrsWithNames, but this version is only used once so isn't suitable for being the base of a new primop. if it were to be used more we should add a second primop instead.
2021-12-16Add a test case for builtins.groupBySilvan Mosberger
2021-11-24Make lists be comparableSilvan Mosberger
Makes lists comparable using lexicographic comparison. Increments builtins.langVersion in order for this change to be detectable
2021-08-06path antiquotations: rename confusing testTaeer Bar-Yam
2021-08-06add path antiqutations testTaeer Bar-Yam
2021-05-29Add .tar.zst support for TarballInputSchemeTimothy Klim
2021-05-10Implement `builtins.floor` and `builtins.ceil` using the C library functions ↵Maximilian Bosch
internally Closes #4782 Note: even though the type is internally called `NixFloat`, it's actually a `double`.
2020-12-22Move <nix/fetchurl.nix> into the nix binaryEelco Dolstra
This makes the statically linked nix binary just work, without needing any additional files.
2020-09-14Escape `${` in strings when printing Nix expressionsregnat
Otherwise the result of the printing can't be parsed back correctly by Nix (because the unescaped `${` will be parsed as the begining of an anti-quotation). Fix #3989
2020-04-02Make function arguments retain position infoSilvan Mosberger
This allows querying the location of function arguments. E.g. builtins.unsafeGetAttrPos "x" (builtins.functionArgs ({ x }: null)) => { column = 57; file = "/home/infinisil/src/nix/inst/test.nix"; line = 1; }
2020-03-11Move some corepkgs into the nix binaryEelco Dolstra
2020-03-04Add test for foldl'Eelco Dolstra
2020-01-07Add support for \u escape in fromJSONNikola Knezevic
As fromTOML supports \u and \U escapes, bring fromJSON on par. As JSON defaults to UTF-8 encoding (every JSON parser must support UTF-8), this change parses the `\u hex hex hex hex` sequence (\u followed by 4 hexadecimal digits) into an UTF-8 representation. Add a test to verify correct parsing, using all escape sequences from json.org.
2019-11-25Add testcase for attrset using __overrides and dynamic attrsPuck Meerburg
2019-10-27Merge branch 'tojson-tostring-fix' of https://github.com/mayflower/nixEelco Dolstra
2019-10-27builtins.toJSON: fix __toString usageRobin Gloster
2019-06-24Fix abort in fromTOMLEelco Dolstra
Fixes #2969.
2019-06-24Add more fromTOML testsEelco Dolstra