exercism / elm-test-runner

GNU Affero General Public License v3.0
3 stars 5 forks source link

Support let expressions in describe and test functions #30

Open ceddlyburge opened 2 years ago

ceddlyburge commented 2 years ago

The test runner cannot currently handle a let expression used inside a describe or test function, like below and in #29

tests : Test
tests =
    describe "RobotSimulator"
        [ describe "init"
            (let
                robot =
                    defaultRobot
             in  
             [ test "coordinates" <|
                \() -> Expect.equal { x = 0, y = 0 } robot.coordinates
             , test "bearing" <|
                \() -> Expect.equal North robot.bearing
             ]   
            ) 
        , ...
jiegillet commented 2 years ago

I wrote some code that can traverse complex code and grab tests along the way. It might be a bit too general for our use case, but it works. It's not pushed anywhere yet.

Along the way, it grabs all the describe descriptions and the test description. So at the end I have something like ["description 1", "description 2", "should work at night"] so I can build the final name. We could use this to check for a specific description related to tasks, if we require a specific description format like "task 1".

Another idea is to create an alias function

task : Int -> String ->  List Test -> Test
task _ = describe

that I could also parse along the way, but that's a bit more convoluted.

Oh, I just remembered @mpizenberg has already implemented something like that on his fork.

Anyway, plenty of options, we should take this opportunity to extract the task ID and add a "task_id":1 field to the final json.

Thoughts?

mpizenberg commented 2 years ago

Oh, the name of that repo might be confusing you @jiegillet sorry. This repo is not actually a fork of exercism/elm-test-runner. It's the Elm part (an elm package: https://package.elm-lang.org/packages/mpizenberg/elm-test-runner/latest/) of mpizenberg/elm-test-rs, my rust test runner, which already has the ability to report tasks when they are numbered. The only thing needed to bring it to exercism/elm-test-runner is to update in it the version of elm-test-rs. Is it clearer?

But all this is unrelated to the code here having an issue with let expressions.

jiegillet commented 2 years ago

Oh, I see, yes, I got confused by the name. So getting the task number is just a matter of updating elm-test-rs. I guess that should be its own issue.