1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-10 04:43:53 +02:00

Merge pull request #11167 from NixOS/repl-test-rejiggle

Fix repl test for `buildReadlineNoMarkdown`
This commit is contained in:
Robert Hensing 2024-07-27 00:55:57 +02:00 committed by GitHub
commit 861bd102a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 302 additions and 157 deletions

View file

@ -262,6 +262,23 @@ badExitCode=0
nixVersion="$(nix eval --impure --raw --expr 'builtins.nixVersion' --extra-experimental-features nix-command)"
# TODO: write a repl interacter for testing. Papering over the differences between readline / editline and between platforms is a pain.
# I couldn't get readline and editline to agree on the newline before the prompt,
# so let's just force it to be one empty line.
stripEmptyLinesBeforePrompt() {
# --null-data: treat input as NUL-terminated instead of newline-terminated
sed --null-data 's/\n\n*nix-repl>/\n\nnix-repl>/g'
}
# We don't get a final prompt on darwin, so we strip this as well.
stripFinalPrompt() {
# Strip the final prompt and/or any trailing spaces
sed --null-data \
-e 's/\(.*[^\n]\)\n\n*nix-repl>[ \n]*$/\1/' \
-e 's/[ \n]*$/\n/'
}
runRepl () {
# That is right, we are also filtering out the testdir _without underscores_.
@ -273,8 +290,13 @@ runRepl () {
testDirNoUnderscores="${testDir//_/}"
# TODO: pass arguments to nix repl; see lang.sh
_NIX_TEST_RAW_MARKDOWN=1 \
_NIX_TEST_REPL_ECHO=1 \
nix repl 2>&1 \
| stripColors \
| tr -d '\0' \
| stripEmptyLinesBeforePrompt \
| stripFinalPrompt \
| sed \
-e "s@$testDir@/path/to/tests/functional@g" \
-e "s@$testDirNoUnderscores@/path/to/tests/functional@g" \
@ -289,7 +311,10 @@ for test in $(cd "$testDir/repl"; echo *.in); do
in="$testDir/repl/$test.in"
actual="$testDir/repl/$test.actual"
expected="$testDir/repl/$test.expected"
(cd "$testDir/repl"; set +x; runRepl 2>&1) < "$in" > "$actual"
(cd "$testDir/repl"; set +x; runRepl 2>&1) < "$in" > "$actual" || {
echo "FAIL: $test (exit code $?)" >&2
badExitCode=1
}
diffAndAcceptInner "$test" "$actual" "$expected"
done

View file

@ -1,24 +1,28 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
Function curriedArgs
… defined at
/path/to/tests/functional/repl/doc-comments.nix:48:5
nix-repl> :doc curriedArgs
Function `curriedArgs`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:48:5
A documented function.
A documented function.
nix-repl> x = curriedArgs 1
nix-repl> "Note that users may not expect this to behave as it currently does"
"Note that users may not expect this to behave as it currently does"
Function curriedArgs
… defined at
/path/to/tests/functional/repl/doc-comments.nix:50:5
nix-repl> :doc x
Function `curriedArgs`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:50:5
The function returned by applying once
The function returned by applying once
"This won't produce documentation, because we can't actually document arbitrary values"
nix-repl> "This won't produce docs; no support for arbitrary values"
"This won't produce docs; no support for arbitrary values"
nix-repl> :doc x 2
error: value does not have documentation

View file

@ -3,5 +3,5 @@
x = curriedArgs 1
"Note that users may not expect this to behave as it currently does"
:doc x
"This won't produce documentation, because we can't actually document arbitrary values"
"This won't produce docs; no support for arbitrary values"
:doc x 2

View file

@ -1,13 +1,14 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
nix-repl> "Note that this is not yet complete"
"Note that this is not yet complete"
Function documentedFormals
… defined at
/path/to/tests/functional/repl/doc-comments.nix:57:5
Finds x
nix-repl> :doc documentedFormals
Function `documentedFormals`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:57:5
Finds x

View file

@ -1,8 +1,7 @@
Nix <nix version>
Type :? for help.
Function defined at
/path/to/tests/functional/repl/doc-comment-function.nix:2:1
A doc comment for a file that only contains a function
nix-repl> :doc import ./doc-comment-function.nix
Function defined at /path/to/tests/functional/repl/doc-comment-function.nix:2:1
A doc comment for a file that only contains a function

View file

@ -1,11 +1,11 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
Function compact
… defined at
/path/to/tests/functional/repl/doc-comments.nix:18:20
boom
nix-repl> :doc compact
Function `compact`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:18:20
boom

View file

@ -1,23 +1,27 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
nix-repl> :doc constant
error: value does not have documentation
Attribute version
nix-repl> :doc lib.version
Attribute `version`
… defined at
/path/to/tests/functional/repl/doc-comments.nix:30:3
… defined at /path/to/tests/functional/repl/doc-comments.nix:30:3
Immovably fixed.
Immovably fixed.
Attribute empty
nix-repl> :doc lib.attr.empty
Attribute `empty`
… defined at
/path/to/tests/functional/repl/doc-comments.nix:33:3
… defined at /path/to/tests/functional/repl/doc-comments.nix:33:3
Unchangeably constant.
Unchangeably constant.
nix-repl> :doc lib.attr.undocument
error:
… while evaluating the attribute 'attr.undocument'
at /path/to/tests/functional/repl/doc-comments.nix:33:3:
@ -32,59 +36,65 @@ error:
| ^
Did you mean undocumented?
Attribute constant
nix-repl> :doc (import ./doc-comments.nix).constant
Attribute `constant`
… defined at
/path/to/tests/functional/repl/doc-comments.nix:27:3
… defined at /path/to/tests/functional/repl/doc-comments.nix:27:3
Firmly rigid.
Firmly rigid.
Attribute version
nix-repl> :doc (import ./doc-comments.nix).lib.version
Attribute `version`
… defined at
/path/to/tests/functional/repl/doc-comments.nix:30:3
… defined at /path/to/tests/functional/repl/doc-comments.nix:30:3
Immovably fixed.
Immovably fixed.
Attribute empty
nix-repl> :doc (import ./doc-comments.nix).lib.attr.empty
Attribute `empty`
… defined at
/path/to/tests/functional/repl/doc-comments.nix:33:3
… defined at /path/to/tests/functional/repl/doc-comments.nix:33:3
Unchangeably constant.
Unchangeably constant.
Attribute undocumented
nix-repl> :doc (import ./doc-comments.nix).lib.attr.undocumented
Attribute `undocumented`
… defined at
/path/to/tests/functional/repl/doc-comments.nix:35:3
… defined at /path/to/tests/functional/repl/doc-comments.nix:35:3
No documentation found.
No documentation found.
nix-repl> :doc missing
error: undefined variable 'missing'
at «string»:1:1:
1| missing
| ^
nix-repl> :doc constanz
error: undefined variable 'constanz'
at «string»:1:1:
1| constanz
| ^
nix-repl> :doc missing.attr
error: undefined variable 'missing'
at «string»:1:1:
1| missing.attr
| ^
nix-repl> :doc lib.missing
error: attribute 'missing' missing
at «string»:1:1:
1| lib.missing
| ^
nix-repl> :doc lib.missing.attr
error: attribute 'missing' missing
at «string»:1:1:
1| lib.missing.attr
| ^
nix-repl> :doc lib.attr.undocumental
error:
… while evaluating the attribute 'attr.undocumental'
at /path/to/tests/functional/repl/doc-comments.nix:33:3:
@ -98,5 +108,3 @@ error:
1| lib.attr.undocumental
| ^
Did you mean undocumented?

View file

@ -1,11 +1,11 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
Function floatedIn
… defined at
/path/to/tests/functional/repl/doc-comments.nix:16:5
This also works.
nix-repl> :doc floatedIn
Function `floatedIn`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:16:5
This also works.

View file

@ -1,29 +1,29 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
Function nonStrict
… defined at
/path/to/tests/functional/repl/doc-comments.nix:37:70
nix-repl> :doc nonStrict
Function `nonStrict`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:37:70
My syntax is not strict, but I'm strict anyway.
My syntax is not strict, but I'm strict anyway.
Function strict
… defined at
/path/to/tests/functional/repl/doc-comments.nix:38:63
nix-repl> :doc strict
Function `strict`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:38:63
I don't have to be strict, but I am anyway.
I don't have to be strict, but I am anyway.
Function strictPre
… defined at
/path/to/tests/functional/repl/doc-comments.nix:40:48
nix-repl> :doc strictPre
Function `strictPre`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:40:48
Here's one way to do this
Function strictPost
… defined at
/path/to/tests/functional/repl/doc-comments.nix:41:53
Here's another way to do this
Here's one way to do this
nix-repl> :doc strictPost
Function `strictPost`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:41:53
Here's another way to do this

View file

@ -1,11 +1,11 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
Function measurement
… defined at
/path/to/tests/functional/repl/doc-comments.nix:13:17
👈 precisely this wide 👉
nix-repl> :doc measurement
Function `measurement`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:13:17
👈 precisely this wide 👉

View file

@ -1,15 +1,17 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
Function multiply
… defined at
/path/to/tests/functional/repl/doc-comments.nix:10:14
Perform arithmetic multiplication. It's kind of like
repeated addition, very neat.
| multiply 2 3
| => 6
nix-repl> :doc multiply
Function `multiply`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:10:14
Perform *arithmetic* multiplication. It's kind of like repeated **addition**, very neat.
```nix
multiply 2 3
=> 6
```

View file

@ -1,11 +1,11 @@
Nix <nix version>
Type :? for help.
nix-repl> :l doc-comments.nix
Added <number omitted> variables.
Function unambiguous
… defined at
/path/to/tests/functional/repl/doc-comments.nix:24:5
Very close
nix-repl> :doc unambiguous
Function `unambiguous`\
… defined at /path/to/tests/functional/repl/doc-comments.nix:24:5
Very close

View file

@ -1,29 +1,37 @@
Nix <nix version>
Type :? for help.
nix-repl> :l pretty-print-idempotent.nix
Added <number omitted> variables.
nix-repl> oneDeep
{ homepage = "https://example.com"; }
nix-repl> oneDeep
{ homepage = "https://example.com"; }
nix-repl> twoDeep
{
layerOne = { ... };
}
nix-repl> twoDeep
{
layerOne = { ... };
}
nix-repl> oneDeepList
[ "https://example.com" ]
nix-repl> oneDeepList
[ "https://example.com" ]
nix-repl> twoDeepList
[
[ ... ]
]
nix-repl> twoDeepList
[
[ ... ]
]