SwensenSoftware / unquote

Write F# unit test assertions as quoted expressions, get step-by-step failure messages for free
http://www.swensensoftware.com/unquote
Apache License 2.0
285 stars 26 forks source link

Support .NET Core #126

Closed enricosada closed 7 years ago

enricosada commented 7 years ago

Add .NET Core 1.0 RTM support (netstandard1.6) using .NET Core SDK preview2

The build.bat now add netstandard to package, if env var UNQUOTE_NETCORE is 1 if .net core sdk is installed ( the dotnet --info return exit code 0) IMPORTANT change version inside Unquote/project.json before of the build, so is the same number as built process

How to try it:

First restore

dotnet restore

After that

dotnet test UnquoteTests

this will build Unquote, and run UnquoteTests tests Same for VerifyNunit3Support, VerifyXunit2Support

The VerifyNonFrameworkSupport is a console app, so instead

cd VerifyNonFrameworkSupport
dotnet run
stephen-swensen commented 7 years ago

@enricosada this is great, thank you! Looking forward to digging in.

enricosada commented 7 years ago

I'll check appveyor failure.

Btw @stephen-swensen any issue, feel free to ping me or #dotnetcore fsharp.org slack channel

enricosada commented 7 years ago

sry, locally i have an error with portable profile with msbuild (maybe i need something installed, dunno)

e:\github\unquote\Unquote.Profile259\unknown(1,1): error FS0078: Unable to find the file 'System.Runtime.InteropService
s.dll' in any of C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259
 e:\github\unquote\Unquote.Profile259 C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETCore\3.259.3.1
[e:\github\unquote\Unquote.Profile259\Unquote.Profile259.fsproj]

so when fixing f# 3 conditionals (instead of f# 4), i didnt see the error.

i always tried locally with build.bat (works for me, create the package).

stephen-swensen commented 7 years ago

@enricosada I'm not all up-to-date on .NET Core / Standard so excuse my ignorance, but according to Don's comment at https://github.com/fsprojects/FsProjectsAdmin/issues/10#issuecomment-237898162 , PCL 259 can be referenced from a .NET Core / Standard project... Unquote supports PCL 259 so I am wondering what the point of additionally supporting .NET Core / Standard is (may be totally misunderstanding everything)?

enricosada commented 7 years ago

@stephen-swensen sry for late reply, i was in vacation :P

you can import the pcl, but there are some issue currently. I got these errors trying to use imported unquote pcl from others dotnetcore project (Argu for example).

I think there is an issue because unquote is referencing FSharp.Core from gac (net40), not only pcl assemblies.

If create a console app, add the import of pcl, the app restore and build correctly, but at runtime:

Unhandled Exception: Swensen.Unquote.AssertionFailedException: Test failed:

([3; 2; 1; 0] |> List.map ((+) 1)) = [1 + 3..1 + 0]
System.TypeInitializationException: The type initializer for '<StartupCode$Unquote>.$Swensen.Unquote.DynamicOperators' threw an exception. ---> System.TypeLoadException: Could not load type 'System.Numerics.BigInteger' from assembly 'FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at <StartupCode$Unquote>.$Swensen.Unquote.DynamicOperators..cctor()
   --- End of inner exception stack trace ---
   at Swensen.Unquote.Evaluation.eval(FSharpList`1 env, FSharpExpr expr)
   at Swensen.Unquote.Reduction.reduce(FSharpList`1 env, FSharpExpr expr)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
   at Swensen.Unquote.Reduction.reduce(FSharpList`1 env, FSharpExpr expr)
   at Swensen.Unquote.Reduction.loop@126(FSharpList`1 env, FSharpExpr expr, FSharpList`1 acc)

Also imports doesnt work using dotnet sdk tools (the tools section) but i dont think that an issue for unquote, because is used in tests.

Last, netstandard1.6 it's another target profile, so additional assemblies who doesnt mess with other users of your library, but unlock the projects who are trying to convert the test suite to dotnetcore.

More info about pcl and netstandard from docs and for libs

enricosada commented 7 years ago

if you need i can gist you the code with imported pcl of unquote 3.1.2, if you think can be useful to fix that error

stephen-swensen commented 7 years ago

@enricosada yes that would be helpful. Wondering if we can just massage Unquote's PCL build so that it is sufficient for use by other projects without creating another profile.

enricosada commented 7 years ago

in theory, pcl 259 is netstandard1.0 so should work, but..

anyway the example https://gist.github.com/enricosada/a639815605b32840fa3423235c9dfbe9

dotnet restore
dotnet run

i know is another profile, but the netstandard is the way forward for multitargeting, and improve the pcl (for example library author can choose the minimal api surface, fsharp.core should lower netstandard1.6 to 1.3 i think) so newer or different platform can be supported (pcl restrict the platform to a subset)

if you want to try a new pcl nuget package:

and

dotnet restore -f dir/to/new/pkg
dotnet run
neoeinstein commented 7 years ago

Note that I have posted up another conversion to .NET Core at https://github.com/neoeinstein/unquote/tree/netcore. I also have published it as a package on my personal MyGet feed here: https://www.myget.org/F/neoeinstein/api/v3/index.json

tomasaschan commented 7 years ago

Is there any update on this, now that .NET Core tooling is 1.0? Is there anything I could do to help and/or test?

@neoeinstein I tried to install Unquote from your personal feed, but the package isn't listed there... :(

stephen-swensen commented 7 years ago

@tlycken Hi - my update is this: i have been hesitant to consider .NET Core up until now because of the instability (e.g. JSON vs. MSBUILD project formats)... it looks like that is settling down and it is now on my radar for real. Not sure yet about time line, but I am thinking there will be a Unquote 4.0 release that targets .NET 45 and .NET Core (whatever) while deprecating PCL and .NET 40 builds...

Any thoughts welcome, it's difficult to keep a solid grasp of the prominent .NET build profiles from year-to-year...

(thanks, any nudge helps me, and I appreciate the offer for help!)

tomasaschan commented 7 years ago

@stephen-swensen I feel you - I sort-of gave up on keeping track of the tooling when they announced they were ditching project.json, and decided to wait for RTM. But that was released last week, so we can probably expect it to have stabilized now :)

There's a decent tutorial on microsoft.com that I found worked very well when following it exactly, but stumbled onto some subtleties when I tried to apply it to port a project of mine. I guess with some effort it shouldn't be a problem. Either way, I think that - and similar resources - is a good start for porting this library too.

Since this PR uses the preview2 version of the tooling, we'd probably have to re-do some of the work here. Perhaps @enricosada is better posed to know which changes here can be re-used?

neoeinstein commented 7 years ago

@tlycken The version of unquote that you need to use for my feed is 3.1.3-alpha-170218.

enricosada commented 7 years ago

@stephen-swensen @tlycken @neoeinstein i'll finish this, converting to fsproj.

@stephen-swensen now tooling is stable and rtm. Tooling was ok in preview2 too, source code changes will be the same, but now is expected to stay stable for quite a bit.

as a note, project.json (preview2) -> fsproj (1.0 rtm) tutorial is in the wiki https://github.com/dotnet/netcorecli-fsc/wiki/How-to-migrate-preview2-projects-to-1.0

enricosada commented 7 years ago

Sry @neoeinstein didnt see your branch. I'll integrate your changes in my PR, i think here there is also tests and build script done.

enricosada commented 7 years ago

Sorry another time @neoeinstein , seems i was a bit too optimistic about my free time for do this. I'll close, if someone want to continue branch continue to exists