mirror of
https://github.com/NixOS/nix
synced 2025-07-08 11:03:54 +02:00
Track doc comments and render them in :doc
This commit is contained in:
parent
e5af7cbeb9
commit
7fae378835
25 changed files with 515 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source common.sh
|
||||
source characterisation/framework.sh
|
||||
|
||||
testDir="$PWD"
|
||||
cd "$TEST_ROOT"
|
||||
|
@ -244,3 +245,32 @@ testReplResponseNoRegex '
|
|||
y = { a = 1 };
|
||||
}
|
||||
'
|
||||
|
||||
# TODO: move init to characterisation/framework.sh
|
||||
badDiff=0
|
||||
badExitCode=0
|
||||
|
||||
nixVersion="$(nix eval --impure --raw --expr 'builtins.nixVersion' --extra-experimental-features nix-command)"
|
||||
|
||||
runRepl () {
|
||||
# TODO: pass arguments to nix repl; see lang.sh
|
||||
nix repl 2>&1 \
|
||||
| stripColors \
|
||||
| sed \
|
||||
-e "s@$testDir@/path/to/tests/functional@g" \
|
||||
-e "s@$nixVersion@<nix version>@g" \
|
||||
-e "s@Added [0-9]* variables@Added <number omitted> variables@g" \
|
||||
| grep -vF $'warning: you don\'t have Internet access; disabling some network-dependent features' \
|
||||
;
|
||||
}
|
||||
|
||||
for test in $(cd "$testDir/repl"; echo *.in); do
|
||||
test="$(basename "$test" .in)"
|
||||
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"
|
||||
diffAndAcceptInner "$test" "$actual" "$expected"
|
||||
done
|
||||
|
||||
characterisationTestExit
|
||||
|
|
0
tests/functional/repl/characterisation/empty
Normal file
0
tests/functional/repl/characterisation/empty
Normal file
8
tests/functional/repl/doc-comment-function.expected
Normal file
8
tests/functional/repl/doc-comment-function.expected
Normal file
|
@ -0,0 +1,8 @@
|
|||
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
|
||||
|
||||
|
1
tests/functional/repl/doc-comment-function.in
Normal file
1
tests/functional/repl/doc-comment-function.in
Normal file
|
@ -0,0 +1 @@
|
|||
:doc import ./doc-comment-function.nix
|
3
tests/functional/repl/doc-comment-function.nix
Normal file
3
tests/functional/repl/doc-comment-function.nix
Normal file
|
@ -0,0 +1,3 @@
|
|||
/** A doc comment for a file that only contains a function */
|
||||
{ ... }:
|
||||
{ }
|
57
tests/functional/repl/doc-comments.nix
Normal file
57
tests/functional/repl/doc-comments.nix
Normal file
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
/**
|
||||
Perform *arithmetic* multiplication. It's kind of like repeated **addition**, very neat.
|
||||
|
||||
```nix
|
||||
multiply 2 3
|
||||
=> 6
|
||||
```
|
||||
*/
|
||||
multiply = x: y: x * y;
|
||||
|
||||
/**👈 precisely this wide 👉*/
|
||||
measurement = x: x;
|
||||
|
||||
floatedIn = /** This also works. */
|
||||
x: y: x;
|
||||
|
||||
compact=/**boom*/x: x;
|
||||
|
||||
/** Ignore!!! */
|
||||
unambiguous =
|
||||
/** Very close */
|
||||
x: x;
|
||||
|
||||
/** Firmly rigid. */
|
||||
constant = true;
|
||||
|
||||
/** Immovably fixed. */
|
||||
lib.version = "9000";
|
||||
|
||||
/** Unchangeably constant. */
|
||||
lib.attr.empty = { };
|
||||
|
||||
lib.attr.undocumented = { };
|
||||
|
||||
nonStrict = /** My syntax is not strict, but I'm strict anyway. */ x: x;
|
||||
strict = /** I don't have to be strict, but I am anyway. */ { ... }: null;
|
||||
# Note that pre and post are the same here. I just had to name them somehow.
|
||||
strictPre = /** Here's one way to do this */ a@{ ... }: a;
|
||||
strictPost = /** Here's another way to do this */ { ... }@a: a;
|
||||
|
||||
# TODO
|
||||
|
||||
# /** This returns a documented function. */
|
||||
# documentedArgs =
|
||||
# /** x */
|
||||
# x:
|
||||
# /** y */
|
||||
# y:
|
||||
# /** x + y */
|
||||
# x + y;
|
||||
|
||||
# /** Documented formals */
|
||||
# documentedFormals =
|
||||
# /** x */
|
||||
# x: x;
|
||||
}
|
11
tests/functional/repl/doc-compact.expected
Normal file
11
tests/functional/repl/doc-compact.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
Nix <nix version>
|
||||
Type :? for help.
|
||||
Added <number omitted> variables.
|
||||
|
||||
Function compact
|
||||
… defined at
|
||||
/path/to/tests/functional/repl/doc-comments.nix:18:20
|
||||
|
||||
boom
|
||||
|
||||
|
2
tests/functional/repl/doc-compact.in
Normal file
2
tests/functional/repl/doc-compact.in
Normal file
|
@ -0,0 +1,2 @@
|
|||
:l doc-comments.nix
|
||||
:doc compact
|
11
tests/functional/repl/doc-floatedIn.expected
Normal file
11
tests/functional/repl/doc-floatedIn.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
Nix <nix version>
|
||||
Type :? for help.
|
||||
Added <number omitted> variables.
|
||||
|
||||
Function floatedIn
|
||||
… defined at
|
||||
/path/to/tests/functional/repl/doc-comments.nix:16:5
|
||||
|
||||
This also works.
|
||||
|
||||
|
2
tests/functional/repl/doc-floatedIn.in
Normal file
2
tests/functional/repl/doc-floatedIn.in
Normal file
|
@ -0,0 +1,2 @@
|
|||
:l doc-comments.nix
|
||||
:doc floatedIn
|
29
tests/functional/repl/doc-lambda-flavors.expected
Normal file
29
tests/functional/repl/doc-lambda-flavors.expected
Normal file
|
@ -0,0 +1,29 @@
|
|||
Nix <nix version>
|
||||
Type :? for help.
|
||||
Added <number omitted> variables.
|
||||
|
||||
Function nonStrict
|
||||
… defined at
|
||||
/path/to/tests/functional/repl/doc-comments.nix:36:70
|
||||
|
||||
My syntax is not strict, but I'm strict anyway.
|
||||
|
||||
Function strict
|
||||
… defined at
|
||||
/path/to/tests/functional/repl/doc-comments.nix:37:63
|
||||
|
||||
I don't have to be strict, but I am anyway.
|
||||
|
||||
Function strictPre
|
||||
… defined at
|
||||
/path/to/tests/functional/repl/doc-comments.nix:39:48
|
||||
|
||||
Here's one way to do this
|
||||
|
||||
Function strictPost
|
||||
… defined at
|
||||
/path/to/tests/functional/repl/doc-comments.nix:40:53
|
||||
|
||||
Here's another way to do this
|
||||
|
||||
|
5
tests/functional/repl/doc-lambda-flavors.in
Normal file
5
tests/functional/repl/doc-lambda-flavors.in
Normal file
|
@ -0,0 +1,5 @@
|
|||
:l doc-comments.nix
|
||||
:doc nonStrict
|
||||
:doc strict
|
||||
:doc strictPre
|
||||
:doc strictPost
|
11
tests/functional/repl/doc-measurement.expected
Normal file
11
tests/functional/repl/doc-measurement.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
Nix <nix version>
|
||||
Type :? for help.
|
||||
Added <number omitted> variables.
|
||||
|
||||
Function measurement
|
||||
… defined at
|
||||
/path/to/tests/functional/repl/doc-comments.nix:13:17
|
||||
|
||||
👈 precisely this wide 👉
|
||||
|
||||
|
2
tests/functional/repl/doc-measurement.in
Normal file
2
tests/functional/repl/doc-measurement.in
Normal file
|
@ -0,0 +1,2 @@
|
|||
:l doc-comments.nix
|
||||
:doc measurement
|
15
tests/functional/repl/doc-multiply.expected
Normal file
15
tests/functional/repl/doc-multiply.expected
Normal file
|
@ -0,0 +1,15 @@
|
|||
Nix <nix version>
|
||||
Type :? for help.
|
||||
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
|
||||
|
||||
|
2
tests/functional/repl/doc-multiply.in
Normal file
2
tests/functional/repl/doc-multiply.in
Normal file
|
@ -0,0 +1,2 @@
|
|||
:l doc-comments.nix
|
||||
:doc multiply
|
11
tests/functional/repl/doc-unambiguous.expected
Normal file
11
tests/functional/repl/doc-unambiguous.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
Nix <nix version>
|
||||
Type :? for help.
|
||||
Added <number omitted> variables.
|
||||
|
||||
Function unambiguous
|
||||
… defined at
|
||||
/path/to/tests/functional/repl/doc-comments.nix:23:5
|
||||
|
||||
Very close
|
||||
|
||||
|
2
tests/functional/repl/doc-unambiguous.in
Normal file
2
tests/functional/repl/doc-unambiguous.in
Normal file
|
@ -0,0 +1,2 @@
|
|||
:l doc-comments.nix
|
||||
:doc unambiguous
|
Loading…
Add table
Add a link
Reference in a new issue