-
Notifications
You must be signed in to change notification settings - Fork 11
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
Automated Snippet Checking #15
Comments
These are the results of my own research into how we might automatically compile and check our documentation. File Style Snippetsmarkdown-unlit acts as a drop-in replacement for GHC's literate preprocessor to allow GHC to extract the Haskell snippets in markdown files. That sounds ideal for compiling haskell file style snippets, but it comes with some minor complications to the build process:
Since we won't want to worry about manually making sure there is a symbolic link for every GHCi Style SnippetsA lot of our code snippets are going to be example GHCi sessions, which means Auto-inserting GHCi resultspandoc-markdown-ghci-filter is a pandoc filter that pipes haskell snippets into GHCi, and inserts the results into the output document. If we could incorporate this into our build process then we'd have a guarantee that the output included in our lessons is what GHCi actually outputs, even as we update our dependencies and compiler versions. Poking around the source, it looks like it only uses Testing GHCi resultsAt best pandoc-markdown-ghci-filter assures us that our GHCi output snippets contain what GHCi actually outputs. What it doesn't do is tell us whether GHCi outputs what we expect it to. I haven't yet come accross any tools that can test this. We could just add a test suite that tests assertions on Haskell expressions rather than GHCi outputs, but if we want to be sure the GHCi output is correct we would have to try to manually make sure those tests always reflect the GHCi snippets. Maybe we could make a code review policy that whenever a PR adds or changes a A potential complication with this approach is that the test suite can only access terms from file-style snippets. Expressions that only appear in GHCi entries will have to be duplicated in the test, which may incentivize us push more definitions into the Haskell file style snippets rather than GHCi snippets. |
An alternative option for file style snippets: Pros:
Cons:
A similar approach could be used to extract ghci input snippets to a separate file, but the output would have to be written elsewhere and I'm not sure if the input and corresponding output could be placed in the same code block. |
I suggest that for the moment we try and implement the solution with pandoc-markdown-ghci-filter. Can you whip up a prototype @DrewFenwick ? |
@Kleidukos I'll see what I can do. |
At some point we want to have our Haskell snippets automatically compiled and checked as part of the CI checks to reduce the likelihood of releasing erroneous code examples.
There are a number of ways to make documents that serve as both document markup and compilable Haskell source.
What would be particularly handy is being able to directly compile markdown embedded snippets, since we're already using markdown.
As well as checking that Haskell file style snippets compile, It would be beneficial to be able to check that our GHCi session snippets are also correct.
There are no guarantees that a GHCi snippet that is correct at the time of writing will be correct forever.
Here are some of the ways a dependency update could break our GHCi snippets:
It would be ideal to be able to detect all of these situations in the CI checks.
The text was updated successfully, but these errors were encountered: