tests/functional/repl: Improve precision and readability

... as well as match buildReadlineNoMarkdown.

Unfortunately it doesn't support long inputs or multiline inputs
for now.
This needs to make better use of the interacter interface.
This commit is contained in:
Robert Hensing 2024-07-23 17:52:28 +02:00
parent 712ce2feac
commit ca2cc26e12
14 changed files with 154 additions and 99 deletions

View file

@ -176,22 +176,22 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT
return true;
}
if (!s)
return false;
input += s;
input += '\n';
#ifndef USE_READLINE
// editline doesn't echo the input to the output when non-interactive, unlike readline
// this results in a different behavior when running tests. The echoing is
// quite useful for reading the test output, so we add it here.
if (auto e = getEnv("_NIX_TEST_REPL_ECHO"); s && e && *e == "1")
{
#ifndef USE_READLINE
// This is probably not right for multi-line input, but we don't use that
// in the characterisation tests, so it's fine.
std::cout << "nix-repl> " << s << std::endl;
}
std::cout << promptForType(promptType) << s << std::endl;
#endif
}
if (!s)
return false;
input += s;
input += '\n';
return true;
}

View file

@ -262,6 +262,14 @@ badExitCode=0
nixVersion="$(nix eval --impure --raw --expr 'builtins.nixVersion' --extra-experimental-features nix-command)"
# 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. Ideally we get the two to agree
# or use a simpler interacter for testing.
stripEmptyLinesBeforePrompt() {
# --null-data: treat input as NUL-terminated instead of newline-terminated
sed --null-data 's/\n\n*nix-repl>/\n\nnix-repl>/g'
}
runRepl () {
# That is right, we are also filtering out the testdir _without underscores_.
@ -273,8 +281,11 @@ 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 \
| stripEmptyLinesBeforePrompt \
| sed \
-e "s@$testDir@/path/to/tests/functional@g" \
-e "s@$testDirNoUnderscores@/path/to/tests/functional@g" \

View file

@ -1,24 +1,30 @@
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
nix-repl>

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,16 @@
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
nix-repl>

View file

@ -1,8 +1,9 @@
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
nix-repl>

View file

@ -1,11 +1,13 @@
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
nix-repl>

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:
@ -99,4 +109,4 @@ error:
| ^
Did you mean undocumented?
nix-repl>

View file

@ -1,11 +1,13 @@
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.
nix-repl>

View file

@ -1,29 +1,31 @@
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
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
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
nix-repl>

View file

@ -1,11 +1,13 @@
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 👉
nix-repl>

View file

@ -1,15 +1,19 @@
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
```
nix-repl>

View file

@ -1,11 +1,13 @@
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
nix-repl>

View file

@ -1,29 +1,39 @@
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
[
[ ... ]
]
nix-repl>