mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 00:08:07 +02:00
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:
parent
712ce2feac
commit
ca2cc26e12
14 changed files with 154 additions and 99 deletions
|
@ -176,22 +176,22 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT
|
||||||
return true;
|
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
|
// 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
|
// this results in a different behavior when running tests. The echoing is
|
||||||
// quite useful for reading the test output, so we add it here.
|
// quite useful for reading the test output, so we add it here.
|
||||||
if (auto e = getEnv("_NIX_TEST_REPL_ECHO"); s && e && *e == "1")
|
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
|
// This is probably not right for multi-line input, but we don't use that
|
||||||
// in the characterisation tests, so it's fine.
|
// in the characterisation tests, so it's fine.
|
||||||
std::cout << "nix-repl> " << s << std::endl;
|
std::cout << promptForType(promptType) << s << std::endl;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return false;
|
||||||
|
input += s;
|
||||||
|
input += '\n';
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,6 +262,14 @@ badExitCode=0
|
||||||
|
|
||||||
nixVersion="$(nix eval --impure --raw --expr 'builtins.nixVersion' --extra-experimental-features nix-command)"
|
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 () {
|
runRepl () {
|
||||||
|
|
||||||
# That is right, we are also filtering out the testdir _without underscores_.
|
# That is right, we are also filtering out the testdir _without underscores_.
|
||||||
|
@ -273,8 +281,11 @@ runRepl () {
|
||||||
testDirNoUnderscores="${testDir//_/}"
|
testDirNoUnderscores="${testDir//_/}"
|
||||||
|
|
||||||
# TODO: pass arguments to nix repl; see lang.sh
|
# TODO: pass arguments to nix repl; see lang.sh
|
||||||
|
_NIX_TEST_RAW_MARKDOWN=1 \
|
||||||
|
_NIX_TEST_REPL_ECHO=1 \
|
||||||
nix repl 2>&1 \
|
nix repl 2>&1 \
|
||||||
| stripColors \
|
| stripColors \
|
||||||
|
| stripEmptyLinesBeforePrompt \
|
||||||
| sed \
|
| sed \
|
||||||
-e "s@$testDir@/path/to/tests/functional@g" \
|
-e "s@$testDir@/path/to/tests/functional@g" \
|
||||||
-e "s@$testDirNoUnderscores@/path/to/tests/functional@g" \
|
-e "s@$testDirNoUnderscores@/path/to/tests/functional@g" \
|
||||||
|
|
|
@ -1,24 +1,30 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
Function curriedArgs
|
nix-repl> :doc curriedArgs
|
||||||
… defined at
|
Function `curriedArgs`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:48:5
|
… 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"
|
"Note that users may not expect this to behave as it currently does"
|
||||||
|
|
||||||
Function curriedArgs
|
nix-repl> :doc x
|
||||||
… defined at
|
Function `curriedArgs`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:50:5
|
… 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
|
error: value does not have documentation
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
x = curriedArgs 1
|
x = curriedArgs 1
|
||||||
"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"
|
||||||
:doc x
|
: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
|
:doc x 2
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
|
nix-repl> "Note that this is not yet complete"
|
||||||
"Note that this is not yet complete"
|
"Note that this is not yet complete"
|
||||||
|
|
||||||
Function documentedFormals
|
nix-repl> :doc documentedFormals
|
||||||
… defined at
|
Function `documentedFormals`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:57:5
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:57:5
|
||||||
|
|
||||||
Finds x
|
|
||||||
|
|
||||||
|
Finds x
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
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>
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
Function compact
|
nix-repl> :doc compact
|
||||||
… defined at
|
Function `compact`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:18:20
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:18:20
|
||||||
|
|
||||||
boom
|
|
||||||
|
|
||||||
|
boom
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
|
nix-repl> :doc constant
|
||||||
error: value does not have documentation
|
error: value does not have documentation
|
||||||
|
|
||||||
Attribute version
|
nix-repl> :doc lib.version
|
||||||
|
Attribute `version`
|
||||||
|
|
||||||
… defined at
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:30:3
|
||||||
/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
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:33:3
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:33:3
|
|
||||||
|
|
||||||
Unchangeably constant.
|
Unchangeably constant.
|
||||||
|
|
||||||
|
nix-repl> :doc lib.attr.undocument
|
||||||
error:
|
error:
|
||||||
… while evaluating the attribute 'attr.undocument'
|
… while evaluating the attribute 'attr.undocument'
|
||||||
at /path/to/tests/functional/repl/doc-comments.nix:33:3:
|
at /path/to/tests/functional/repl/doc-comments.nix:33:3:
|
||||||
|
@ -32,59 +36,65 @@ error:
|
||||||
| ^
|
| ^
|
||||||
Did you mean undocumented?
|
Did you mean undocumented?
|
||||||
|
|
||||||
Attribute constant
|
nix-repl> :doc (import ./doc-comments.nix).constant
|
||||||
|
Attribute `constant`
|
||||||
|
|
||||||
… defined at
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:27:3
|
||||||
/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
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:30:3
|
||||||
/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
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:33:3
|
||||||
/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
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:35:3
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:35:3
|
|
||||||
|
|
||||||
No documentation found.
|
No documentation found.
|
||||||
|
|
||||||
|
nix-repl> :doc missing
|
||||||
error: undefined variable 'missing'
|
error: undefined variable 'missing'
|
||||||
at «string»:1:1:
|
at «string»:1:1:
|
||||||
1| missing
|
1| missing
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
|
nix-repl> :doc constanz
|
||||||
error: undefined variable 'constanz'
|
error: undefined variable 'constanz'
|
||||||
at «string»:1:1:
|
at «string»:1:1:
|
||||||
1| constanz
|
1| constanz
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
|
nix-repl> :doc missing.attr
|
||||||
error: undefined variable 'missing'
|
error: undefined variable 'missing'
|
||||||
at «string»:1:1:
|
at «string»:1:1:
|
||||||
1| missing.attr
|
1| missing.attr
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
|
nix-repl> :doc lib.missing
|
||||||
error: attribute 'missing' missing
|
error: attribute 'missing' missing
|
||||||
at «string»:1:1:
|
at «string»:1:1:
|
||||||
1| lib.missing
|
1| lib.missing
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
|
nix-repl> :doc lib.missing.attr
|
||||||
error: attribute 'missing' missing
|
error: attribute 'missing' missing
|
||||||
at «string»:1:1:
|
at «string»:1:1:
|
||||||
1| lib.missing.attr
|
1| lib.missing.attr
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
|
nix-repl> :doc lib.attr.undocumental
|
||||||
error:
|
error:
|
||||||
… while evaluating the attribute 'attr.undocumental'
|
… while evaluating the attribute 'attr.undocumental'
|
||||||
at /path/to/tests/functional/repl/doc-comments.nix:33:3:
|
at /path/to/tests/functional/repl/doc-comments.nix:33:3:
|
||||||
|
@ -99,4 +109,4 @@ error:
|
||||||
| ^
|
| ^
|
||||||
Did you mean undocumented?
|
Did you mean undocumented?
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
Function floatedIn
|
nix-repl> :doc floatedIn
|
||||||
… defined at
|
Function `floatedIn`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:16:5
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:16:5
|
||||||
|
|
||||||
This also works.
|
|
||||||
|
|
||||||
|
This also works.
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -1,29 +1,31 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
Function nonStrict
|
nix-repl> :doc nonStrict
|
||||||
… defined at
|
Function `nonStrict`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:37:70
|
… 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
|
nix-repl> :doc strict
|
||||||
… defined at
|
Function `strict`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:38:63
|
… 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
|
nix-repl> :doc strictPre
|
||||||
… defined at
|
Function `strictPre`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:40:48
|
… 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
|
nix-repl> :doc strictPost
|
||||||
… defined at
|
Function `strictPost`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:41:53
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:41:53
|
||||||
|
|
||||||
Here's another way to do this
|
|
||||||
|
|
||||||
|
Here's another way to do this
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
Function measurement
|
nix-repl> :doc measurement
|
||||||
… defined at
|
Function `measurement`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:13:17
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:13:17
|
||||||
|
|
||||||
👈 precisely this wide 👉
|
|
||||||
|
|
||||||
|
👈 precisely this wide 👉
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
Function multiply
|
nix-repl> :doc multiply
|
||||||
… defined at
|
Function `multiply`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:10:14
|
… 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
|
|
||||||
|
|
||||||
|
|
||||||
|
Perform *arithmetic* multiplication. It's kind of like repeated **addition**, very neat.
|
||||||
|
|
||||||
|
```nix
|
||||||
|
multiply 2 3
|
||||||
|
=> 6
|
||||||
|
```
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l doc-comments.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
Function unambiguous
|
nix-repl> :doc unambiguous
|
||||||
… defined at
|
Function `unambiguous`\
|
||||||
/path/to/tests/functional/repl/doc-comments.nix:24:5
|
… defined at /path/to/tests/functional/repl/doc-comments.nix:24:5
|
||||||
|
|
||||||
Very close
|
|
||||||
|
|
||||||
|
Very close
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
|
@ -1,29 +1,39 @@
|
||||||
Nix <nix version>
|
Nix <nix version>
|
||||||
Type :? for help.
|
Type :? for help.
|
||||||
|
|
||||||
|
nix-repl> :l pretty-print-idempotent.nix
|
||||||
Added <number omitted> variables.
|
Added <number omitted> variables.
|
||||||
|
|
||||||
|
nix-repl> oneDeep
|
||||||
{ homepage = "https://example.com"; }
|
{ homepage = "https://example.com"; }
|
||||||
|
|
||||||
|
nix-repl> oneDeep
|
||||||
{ homepage = "https://example.com"; }
|
{ homepage = "https://example.com"; }
|
||||||
|
|
||||||
|
nix-repl> twoDeep
|
||||||
{
|
{
|
||||||
layerOne = { ... };
|
layerOne = { ... };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nix-repl> twoDeep
|
||||||
{
|
{
|
||||||
layerOne = { ... };
|
layerOne = { ... };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nix-repl> oneDeepList
|
||||||
[ "https://example.com" ]
|
[ "https://example.com" ]
|
||||||
|
|
||||||
|
nix-repl> oneDeepList
|
||||||
[ "https://example.com" ]
|
[ "https://example.com" ]
|
||||||
|
|
||||||
|
nix-repl> twoDeepList
|
||||||
[
|
[
|
||||||
[ ... ]
|
[ ... ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
nix-repl> twoDeepList
|
||||||
[
|
[
|
||||||
[ ... ]
|
[ ... ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
nix-repl>
|
||||||
|
|
Loading…
Reference in a new issue