-
Notifications
You must be signed in to change notification settings - Fork 672
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
WIP: Slimmed-down expecto runner #54
base: fsharp
Are you sure you want to change the base?
Conversation
I haven't forgotten this; just need to make some time to pull it down and take a look. Overall, I do like the idea of a slimmed-down runner, and have always preferred the idea of keeping the koans as simple as possible in terms of potentially-confusing syntax like the Koan attribute. It's been a while, but there was an original version of the koan runner that had some of those features before we replaced it with the current version (written by Ryan Riley). That version had some other downsides, though, so hopefully this ends up being the best of both worlds! |
FSharpKoans/Asserts.fs
Outdated
[<AutoOpen>] | ||
module Asserts = | ||
|
||
let inline __<'a> : 'a = failwith "fill in the __" |
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.
these all needed to be inline so that exceptions/test failures don't report this line, rather the line in the test file that uses these to throw.
FSharpKoans/AboutAsserts.fs
Outdated
let expected_value = 1 + 1 | ||
let actual_value = __ //start by changing this line | ||
|
||
let actual_value = 2 //start by changing this line |
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 need to not check-in actual values :D also see below.
FSharpKoans/AboutAsserts.fs
Outdated
let AssertExpectation() = | ||
let tests = | ||
testList "teaching about assertions" [ | ||
testCase "assert expectation" <| fun () -> |
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'd be curious to see if there are other ways to arrange these tests. I like assembling the list and enforcing order, but at the same time the forced indentation and wall of tests can be intimidating to a new user. Maybe separate functions, assembled to a list at the very bottom of the module?
…paket is handling things
Ok, I finally got around to finishing the port of these tests over to expecto. I'd also like to take a look at a conversion to the new SDK/.net core, as I've done that several times already. The big win there is using |
@baronfel how do you the conversion to new SDK/.net core? Is the some automatization or plain manual work? Just curious. |
It's really simple for simple projects like these, especially thanks to paket. The final fsproj will look like something very close to:
so basically a glorified list of files. Paket handles adding the correct |
The other way to do it would be to run |
…e order they are read
Thanks. So it's basically how I've done it before with a few of my hobby projects - |
Sorry that I've been so bad about replying to this sooner. I did test this branch out, and I noticed that all of the tests seem to run in reverse. For example, in AboutAsserts, the "fill in values" koan executes before "assert expectation". I'd also like to find a way to clean up the syntax of the koans a little bit. I think it's great that this removes the need for the
With the current syntax, the reader has to parse the Now for the Expecto syntax:
Here the reader no longer needs to parse the However, I think that it would be ideal to find a syntax that could also hide some of the other "koan framework" elements and "advanced" F# syntax. One of the pieces of feedback that I often received from teaching F# to newcomers was that they were overwhelmed by the number of symbols used in F#, and I think that this syntax might be less approachable than the current syntax for those folks. On the other hand, I really like how this PR massively simplifies the overall solution, eliminates the need for the |
I don't think it'd be hard to go back to a simpler attribute-style way of working, honestly. Expecto helps here by encapsulating the work of scraping the current assembly for tests, so most of the work would go into making sure the order is correct. If those thoughts prove to be true, then we should get the best of both worlds: simpler test syntax and simpler runner infrastructure. |
Yeah, I definitely think that's one route forward. I just didn't want to dismiss all the progress you made/work you did without explaining my thought process. I'm totally open to suggestions if you have other thoughts, though. |
how does this look to you:
Attributes are a little odd with expecto, because you'd end up with something like this:
or something very much like that with a |
a little bit of regex magic later and we're back to good. Now I've got the ordering corrected again, too. F# Linked list order sometimes flips depending on the processing... |
I like this syntax much better, though it'd be nice if we could find a way to clean up the syntax at the top of the file a little bit:
Ideally it would just be just one line- something like The only other concern that I have with this new-and-improved-syntax is that it makes me a little nervous to run everything inside a computation expression. I can't think of any concrete reasons for this, but I'm just going to take a quick run through of the koans myself to make sure that nothing funny/confusing happens when running them inside a computation expression. |
The only one that seemed to do anything different was the looping with while construct one, because the test builder CE doesn't implement while. I was going to open a PR over on expecto for that. But really the CE is very lightweight here and just replaces the function pipe form of the test case function. I totally agree on the duplication at the top of the modules, I'm wracking my brain trying to figure out how to reduce that.... |
I noticed a couple other of things from running them.
|
@baronfel hey, I found a issue while trying this. In About stock example you will required to put test case inside test list. Else And also need to List.Rev all testlist so they will appear in correct order. And in
Thanks for putting it on dotnet core. Make it easier for people who don't have or don't want to install VS. |
@baronfel Same test list issue there in |
I thought I might take a stab at removing some of the reflection magic and making the koans more simple using expecto. I've started the process of translating some of the tests so that we'd have a realistic-ish idea of what such a transformation might look like.
I was able to remove the two support projects, using only a light two-file runner wrapper that delegates to expecto to actually run the tests.
The tests are defined per-module as before, we just aggregate together the test lists in the
PathToEnlightenment.fs
file.I've also added some files that enable CMD+B and F5 build and debugging for the project, so taht cross-platform users have a nicer onboarding session.
I also switched the package management over to paket, which is a completely not-user-impacting change, but lets us more easily do the restore as part of the build. That minimizes the number of commands a new user should have to run.
I've taken care to keep the output as similar as possible too.
Do you think there's value in this?
An example of the output from a run is:
It's important to have the
--debug
on the mono invocation to get the line number on the stack trace :)