8000 Automated testing for examples in README.md by mattiuusitalo · Pull Request #1203 · metosin/malli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Automated testing for examples in README.md #1203

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

Merged
merged 16 commits into from
May 21, 2025

Conversation

mattiuusitalo
Copy link
Contributor
@mattiuusitalo mattiuusitalo commented May 14, 2025

This PR adds an automated test step which generates Clojure tests from most of the examples in the documentation and runs them to see if they still work. It uses https://github.com/lread/test-doc-blocks to do the testing.

We have over two hundred examples in the readmes and these can be verified with test-doc-blocks. The syntax is very similar to what we are already using to document the correct usage and the result it produces in the REPL. Think:

(assoc {} :foo :bar)
;; => {:foo
;;     :bar}

Pros

  • Checks that examples keep working and reflect the current state of the library
  • Nice way to avoid testing cases that won't work that doesn't mess up with the rendering in Github
  • Adds over a hundred new test cases (admittedly most should be covered by the test suite)
  • Can also test prints to stdout and stderr.

Cons

  • Can't check certain cases without making the examples more convoluted (for example generating data)
  • Have to conform to the example writing format from test-doc-blocks

mattiuusitalo and others added 4 commits May 14, 2025 14:17
Rewriting some of the examples to support test-doc-blocks library

=prints=> has been replaced with =stdout=> because that generates
actual tests for what it prints out
@mattiuusitalo mattiuusitalo changed the title WIP: Automated testing for examples in README.md Automated testing for examples in README.md May 21, 2025
@mattiuusitalo mattiuusitalo marked this pull request as ready for review May 21, 2025 04:38
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to add this to the other tests, since test-doc-blocks requires clojure 1.11. I also don't think at this point testing with the whole matrix of clojure versions is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file were required to make the comment blocks compatible with test-doc-blocks. I also found several small discrepancies between expected results and what it actually does. Some syntax errors as well.

@@ -368,17 +373,18 @@ Example of a multi-arity function with instrumentation scopes and custom reporti
([x y] (* x y)))))

(multi-arity-pow 4)
; =prints=> :malli.core/invalid-output {:output [:int {:max 6}], :value 16, :args [4], :schema [:=> [:cat :int] [:int {:max 6}]]}
; => 16
;; =stdout=> :malli.core/invalid-output {:output [:int {:max 6}], :value 16, :args [4], :schema [:=> [:cat :int] [:int {:max 6}]]}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example of leveraging test-doc-blocks' capability of verifying what it printed in stdout.

Copy link
Member
@opqdonut opqdonut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some suggestions tho

I missed this block as the upper expression can't be tested like
this. It returns a reified object which you can't test equality for.
Copy link
Member
@opqdonut opqdonut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@mattiuusitalo mattiuusitalo merged commit c6beb8a into metosin:master May 21, 2025
14 checks passed
@mattiuusitalo mattiuusitalo deleted the test-doc-blocks branch May 21, 2025 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0