-
Notifications
You must be signed in to change notification settings - Fork 94
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
Added support for try-with and try-finally (fixes #241). #242
Conversation
@6a Great work! Yes, add a test please, I think in https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/tests/BasicGenerativeProvisionTests.fs
As comprehensive as possible please, always better. |
I just had a look at BasicGenerativeProvisionTests.fs, and it looks like they mostly test for support of specific platforms. There are no tests that ensure the code generation is correct, which is what the snippet I included above does. To me, the best thing we could do for testing, is add more tests that actually use the provider (sort of like we have in examples, but strictly for testing. Are you ok with me setting up a separate project for this, or will it get refused no matter what? For example, a test about a type provider could contain a We can even use MSBuild and after-build targets to run the scripts automatically after compilation in order to ensure everything works fine. Edit: GenerativeEnumsProvisionTests does something closer to what I had imagined, but there is still a lot of boilerplate every time a provider must be invoked. I think we should at least make a function, ie [<Fact>]
let ``some type provider works``() =
let provider = makeTypeProvider <| fun config -> MyTypeProvider config
let providedType = provider.Namespaces.[0].GetTypes().[0] // could make a util function for this too
let typ = provider.ApplyStaticArguments(providedType, "TypeName", [| ... |])
let asm = buildAssembly provider type.Assembly // returns an Assembly
// do your tests
Assert.NotEqual(asm, null) Update: I can't get any test loading. For some reason, |
Also note the current tests are not instantiating the correct type providers.
Theres a PR to fix this here also. |
Alright, I created a repository that specifically tests for the |
@6a Sorry for the delay, I've been on vacation
We do need to add some kind of testing with this PR, even if it means it's the first testing of expressions |
No problem. If I do add tests for expressions, are you fine with me adding a new project similar to the one I linked above? The existing tests focus on the correctness of the inner workings of the It's a personal opinion though, so if you believe it is better to keep going as is, then I'll try to get new tests working in the existing test project. |
Yes, adding an additional test project like the one above would be ok, thanks! |
Looks like the tests cannot run, probably because of #244. I don't really know what to do at this point. I tried a few different fixes I found, but none worked (using |
@6a I'll look now, thanks |
@6a I've cherry-picked the support for try/finally into #258 since I hit the need while working on "for" (which has an implicit try/finally) I've also included some fixes regarding labels (needed to use DefineLabel/MarkLabel) so there will be conflicts when we integrate back here. I've not included your testing yet: we need to sort through that, but I have added a test that generates code (as part of a "for") though doesn't actually run it. |
Alright, I'm glad it got merged one way or another! I'll keep an eye out for updates. |
This adds support for
Expr.TryFinally
andExpr.TryWith
, as well as support for exception blocks in theILGenerator
.The following provider was used to test the try blocks:
The following script was used to test the provider:
Output:
Edit: Two questions: