-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dhall-docs): Add test-setup and assertions as examples #1899
Conversation
Oh, this looks very exciting! I'll review it properly soon. For now, I'm wondering whether the golden tests could include an HTML beautifier step, so the golden files are more human-readable. That should also help with understanding changes to the test output. You could just run
No worries at all, @german1608! :) |
Sure! Take your time, this PR is quite large :)
from I'll checkout later if there is a beautifier in some other package that is not bound to the |
ae6aa0d
to
fb9f6a6
Compare
Also, Hydra is failing with this error:
https://hydra.dhall-lang.org/jobset/dhall-haskell/1899#tabs-errors It looks like the |
Mm weird because that's the path of the golden files, which are included |
@sjakobi I noticed that I was reading its code and it turns out it adds a |
Yeah. I don't really want to make the library code less readable and slower than necessary. I've been googling for a HTML prettyprinter in Haskell but without much success. I think the most promising thing I found is the |
Same here
Sure, I'll give it a try |
@sjakobi I did what you suggest and although it isn't the best prettyprinter, it is way more readable than a single line so I'll keep it, thanks for your help! @Gabriel439 (or maybe @sjakobi), would you help me with the issue in hydra with the bad glob pattern? I don't get why it is wrong, tried locally and it's the same. |
Indeed it outputs |
Yeah, that's strange. It should match
Oof, yeah. The output isn't exactly beautiful. ;) What's the problem with the |
One way to work around it would probably be to use Cabal >= 2.4: https://cabal.readthedocs.io/en/latest/file-format-changelog.html#cabal-version-2-4 Could we simply turn off hydra builds for |
Yes it should
The following is invalid, although there are other html tags that supports it:
|
Where can I see what cabal version is nix using? |
Further debugging guided me to the following. First, *.html matches
then I see that it didn't failed on the I change
and it still fails, with an error from |
Definetly it's an issue with |
I think that as workaround I can manually intercept generated |
Strange! Have you worked out where the problem with the |
[] -> Nothing | ||
binding : _ -> Just binding | ||
|
||
{-| Calculate the relative path needed to access files on the first argument | ||
relative from the second argument. | ||
examplesFromAssertions :: Expr Void Import -> [Expr Void Import] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether this can handle properties like https://github.com/dhall-lang/dhall-lang/blob/f035ea1947d9392bcedbe7f8c563f33559370efd/Prelude/Natural/lessThanEqual#L14-L16 or this example.
Admittedly I'm also unsure what the expected output should look like. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmmm maybe we could traverse the Lam
constructor on the binding and remove the assert there?
The issue is that we might need to traverse all the binded values in the file and check if there is at least an assert, which might add some overhead.
If a binding has assert
ions, we remove them. Then for that property example:
let property0 = λ(n : Natural) → assert : lessThanEqual 0 n ≡ True
we should strip the assert and we might be ready to go:
λ(n : Natural) → lessThanEqual 0 n ≡ True
|
||
-- | Generate all of the docs for a package | ||
createIndexes :: Text -> [DhallFile] -> [(Path Rel File, Text)] | ||
createIndexes packageName files = map toIndex dirToDirsAndFilesMapAssocs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code inside this function feels kind of messy and impenetrable. I'm not sure how to best fix it though.
I somewhat wonder whether the (Map (Path Rel Dir))
is a good fit for this logic, or if possibly a custom tree structure would be a better fit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IKR!?
The most messy part IMO is the dirToDirsMap
, that was the best I could do to get it right.
If you're wondering what it does (probably could guide me to another solution) is to try to compact listed paths as much as it can.
for isntance, the folders at the tasty/data/package
are the following:
./
./a/
./a/b/
./a/b/c/
./deep/
./deep/nested/
./deep/nested/folder
but on ./deep/
and ./deep/nested/
folders there is no file.
So it's kind of dissapointing if the package directory at ./
listed ./deep/index.html
and the last listed ./deep/nested/index.html
to finally list ./deep/nested/folder/index.html
.
So what it does is to compact paths as much as it cans, without altering the actual directory structure.
An expected output for that directory structure is the output in the golden files:
./
./a/
./a/b/
./a/b/c/
./deep/nested/folder
I'm still thinking a better solution or at least a more readable one. Get back to you if I find out something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjakobi: The most I could do was to use foldl
instead of passing the whole list to go
at dirToDirsMap
.
Another idea I got was the following (pseudocode):
def f(sortedDirs):
stack = [sortedDirs[0]]
map = { sortedDirs[0] = [ ] }
for i in range(sortedDirs):
t = stack.top()
d = sortedDirs[i]
if t prefix of d:
stack.push(d)
map[t].add(d)
else:
while stack.top() not prefix of d:
stack.pop()
map[stack.top()].add(d)
stack.push(d)
return map
... but couldn't write a legible implementation, at least not better than our current one.
I haven't tried yet using a tree-like structure, but I think for that in another PR.
It was in our nix setup: Lines 6 to 16 in 282be96
It's there for a reason, so I'll keep the |
I updated tasty-silver to 3.1.15 because on later versions it didn't properly showed diff between text. It shows the diff if |
I don't know if this is because this update, but I found a bug in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why the index.html
is filtered out in the sdist.nix
?
Some of my comments are still open, but they don't really need to be addressed within this PR.
👍
Actually no, maybe @Gabriel439 knows why
I'll think a little about how can we improve Regarding the properties rendering, I think that it will be worth to discuss on our weekly call. To end, thanks for your approval @sjakobi ! |
@german1608: I think you can delete the line filtering out |
documentation to get more information. | ||
-} | ||
dirToDirsMap :: Map (Path Rel Dir) [Path Rel Dir] | ||
dirToDirsMap = Map.map removeHereDir $ foldl go initialMap dirs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I'd recommend using foldl'
over foldl
for folding over lists. There's a bit of a discussion here: hasura/graphql-engine#2933 (comment)
Hi there!
First things first: I apologize about not being so active this (almost ended) week. I had to finish some things from my university that needed to be done for this next week, so I had to take some time from this to do them.
I'll try to brief all the details that this (kind of big) PR includes.
The most important thing is the test-setup. I decided to go with a golden-test setup using tasty-silver similar to what we've done on
dhall-{json,yaml}
. Basically:dhall-docs/tasty/data/package
dhall-docs/tasty/data/golden
[path]/foo.dhall
is on the package folder, the[path]/foo.dhall.html
is on the golden folder.lucid
doesn't provide a way to render html as text in a non-minified way (check the golden files for a example).--accept
flag is the best thing people invented. It not only updates the files, but create new ones if the file is missing. This is useful to add new tests by adding a new file on the package folder.... but before doing this whole test-setup, I had to basically rewrite the whole logic for document generation (thanks god I splitted
Html ()
generation from there). Specifically:IO
freeWriter
monad to properly handle warnings.createIndexes
function, probably it can be improved and moreover it may be difficult to understand.Core.hs
module (and basically all thedhall-docs
one) isgenerateDocs
,generatedDocsPure
andGeneratedDocs
...and to end, I added assertions as examples on the test files.
I need to say that the new code, although it was difficult to get it right, looks way cleaner from my perspective. Also, tests adds a lot of value to
dhall-docs
, and I'd like to thanks @sjakobi for the suggestion to do this.