Skip to content

Commit

Permalink
tests/function/repl: Characterise the missing doc comment behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Jul 15, 2024
1 parent 21e9265 commit e8b8a50
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/libexpr/nixexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ std::string ExprLambda::showNamePos(const EvalState & state) const
}

void ExprLambda::setDocComment(DocComment docComment) {
// RFC 145 specifies that the innermost doc comment wins.
// See https://github.com/NixOS/rfcs/blob/master/rfcs/0145-doc-strings.md#ambiguous-placement
if (!this->docComment) {
this->docComment = docComment;

Expand Down
24 changes: 24 additions & 0 deletions tests/functional/repl/doc-comment-curried-args.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Nix <nix version>
Type :? for help.
Added <number omitted> variables.

Function curriedArgs
… defined at
/path/to/tests/functional/repl/doc-comments.nix:48:5

A documented function.


"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

The function returned by applying once

"This won't produce documentation, because we can't actually document arbitrary values"

error: value does not have documentation


7 changes: 7 additions & 0 deletions tests/functional/repl/doc-comment-curried-args.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:l doc-comments.nix
:doc curriedArgs
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"
:doc x 2
13 changes: 13 additions & 0 deletions tests/functional/repl/doc-comment-formals.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Nix <nix version>
Type :? for help.
Added <number omitted> variables.

"Note that this is not yet complete"

Function documentedFormals
… defined at
/path/to/tests/functional/repl/doc-comments.nix:57:5

Finds x


3 changes: 3 additions & 0 deletions tests/functional/repl/doc-comment-formals.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:l doc-comments.nix
"Note that this is not yet complete"
:doc documentedFormals
29 changes: 16 additions & 13 deletions tests/functional/repl/doc-comments.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

compact=/**boom*/x: x;

# https://github.com/NixOS/rfcs/blob/master/rfcs/0145-doc-strings.md#ambiguous-placement
/** Ignore!!! */
unambiguous =
/** Very close */
Expand All @@ -41,17 +42,19 @@

# TODO

# /** This returns a documented function. */
# documentedArgs =
# /** x */
# x:
# /** y */
# y:
# /** x + y */
# x + y;

# /** Documented formals */
# documentedFormals =
# /** x */
# x: x;
/** You won't see this. */
curriedArgs =
/** A documented function. */
x:
/** The function returned by applying once */
y:
/** A function body performing summation of two items */
x + y;

/** Documented formals (but you won't see this comment) */
documentedFormals =
/** Finds x */
{ /** The x attribute */
x
}: x;
}
28 changes: 14 additions & 14 deletions tests/functional/repl/doc-constant.expected
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ error: value does not have documentation
Attribute version

… defined at
/path/to/tests/functional/repl/doc-comments.nix:29:3
/path/to/tests/functional/repl/doc-comments.nix:30:3

Immovably fixed.

Attribute empty

… defined at
/path/to/tests/functional/repl/doc-comments.nix:32:3
/path/to/tests/functional/repl/doc-comments.nix:33:3

Unchangeably constant.

error:
… while evaluating the attribute 'attr.undocument'
at /path/to/tests/functional/repl/doc-comments.nix:32:3:
31| /** Unchangeably constant. */
32| lib.attr.empty = { };
at /path/to/tests/functional/repl/doc-comments.nix:33:3:
32| /** Unchangeably constant. */
33| lib.attr.empty = { };
| ^
33|
34|

error: attribute 'undocument' missing
at «string»:1:1:
Expand All @@ -35,28 +35,28 @@ error:
Attribute constant

… defined at
/path/to/tests/functional/repl/doc-comments.nix:26:3
/path/to/tests/functional/repl/doc-comments.nix:27:3

Firmly rigid.

Attribute version

… defined at
/path/to/tests/functional/repl/doc-comments.nix:29:3
/path/to/tests/functional/repl/doc-comments.nix:30:3

Immovably fixed.

Attribute empty

… defined at
/path/to/tests/functional/repl/doc-comments.nix:32:3
/path/to/tests/functional/repl/doc-comments.nix:33:3

Unchangeably constant.

Attribute undocumented

… defined at
/path/to/tests/functional/repl/doc-comments.nix:34:3
/path/to/tests/functional/repl/doc-comments.nix:35:3

No documentation found.

Expand Down Expand Up @@ -87,11 +87,11 @@ error: attribute 'missing' missing

error:
… while evaluating the attribute 'attr.undocumental'
at /path/to/tests/functional/repl/doc-comments.nix:32:3:
31| /** Unchangeably constant. */
32| lib.attr.empty = { };
at /path/to/tests/functional/repl/doc-comments.nix:33:3:
32| /** Unchangeably constant. */
33| lib.attr.empty = { };
| ^
33|
34|

error: attribute 'undocumental' missing
at «string»:1:1:
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/repl/doc-lambda-flavors.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ Added <number omitted> variables.

Function nonStrict
… defined at
/path/to/tests/functional/repl/doc-comments.nix:36:70
/path/to/tests/functional/repl/doc-comments.nix:37: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
/path/to/tests/functional/repl/doc-comments.nix:38: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
/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:40:53
/path/to/tests/functional/repl/doc-comments.nix:41:53

Here's another way to do this

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/repl/doc-unambiguous.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Added <number omitted> variables.

Function unambiguous
… defined at
/path/to/tests/functional/repl/doc-comments.nix:23:5
/path/to/tests/functional/repl/doc-comments.nix:24:5

Very close

Expand Down

0 comments on commit e8b8a50

Please sign in to comment.