Giter Site home page Giter Site logo

Proposal: Test framework about phel-lang HOT 9 CLOSED

phel-lang avatar phel-lang commented on May 18, 2024 4
Proposal: Test framework

from phel-lang.

Comments (9)

jenshaase avatar jenshaase commented on May 18, 2024 8

This is now completed! All test of the core library can now be executed by ./vendor/bin/phel test

from phel-lang.

jenshaase avatar jenshaase commented on May 18, 2024 3

I updated the Report section. What do you think?

from phel-lang.

jenshaase avatar jenshaase commented on May 18, 2024 2

Since (deftest) is the same as (defn) which is the same as (def) why can't we add (deftest) macro in the core and thus avoid adding :refer to the (ns)?

I see the :refer not only useful for this case. It can also be quite useful for library developers to extend Phel with some nice APIs. For example an if anyone whats to define a routing library, he can define a defroute macro like this:

(defroute "/my/route/:id" [request]
  "hello world")

Could we add a command for vendor/bin/phel test namespace/file/test-name?

Sure!

from phel-lang.

paullaffitte avatar paullaffitte commented on May 18, 2024 1

I really like the idea of using ., F or E and to print the detailed output at the end. I think that most test libraries do like this and it produce a good and readable output.

I think it would be pretty useful to print the expected value on test failure. It would help developers to understand what is going on without having to manually print the test's parameters. Quasi-quotation could help here.

Here is an example of what I'm thinking about:

(defmacro assertt
  [test label]
  `(assert ,test (str ,label ", Expected: " ,(print-str test)))
)

(assertt (= 1 2) "Test case")

And the output of this would be e Test case, Expected: (= 1 2).

Then I have a question about run-tests, we would have to pass as parameters all tests that we want to execute right? Maybe auto-discovery of the tests cases (just like phpunit does) would be nice. Then you don't have to worry about forgetting to add one of your tests to the list. And then (again, just like phpunit), we could add a flag or something similar to run only tests that match a pattern, are in some namespace, or even eventually in a test suite (this would require to add something like deftestsuite btw).

from phel-lang.

jenshaase avatar jenshaase commented on May 18, 2024 1

@paullaffitte Thanks for your input. I will add more details in the report section, on how failure and error message should look like (with examples).

Regarding run-tests. This function is the base for running all tests. It's a good idea to add auto-discovery. That can be build on top of run-tests. I thinks this can be done with the vendor/bin/phel test command. If no namespace is provided all test should run.

from phel-lang.

mabasic avatar mabasic commented on May 18, 2024 1

Great work! Really loving how the language is turning out. Sorry I can't contribute more to the code. I have my hands full atm... but testing and experimenting is what I love to do in the morning, so I will give it a go and report back.

from phel-lang.

mabasic avatar mabasic commented on May 18, 2024

Looks very useful and simple, but I have some questions/suggestions.

Since (deftest) is the same as (defn) which is the same as (def) why can't we add (deftest) macro in the core and thus avoid adding :refer to the (ns)?

As an alternative, why not just use (defn) and tell people to add metadata @{:test true} for writing tests?

Could we add a command for vendor/bin/phel test namespace/file/test-name?

from phel-lang.

mabasic avatar mabasic commented on May 18, 2024

I see. Makes sense now. Thank you for explaining the use case a little bit more.

from phel-lang.

jenshaase avatar jenshaase commented on May 18, 2024

Current Status:

  • I implemented the framework as described above
  • I updated the old tests to the new test framework
  • I added the test framework documentation on the website

What is left:

  • Autodiscovery of all tests
  • ./vendor/bin/phel test command

from phel-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.