How to run fsharp test on Mac from terminal?

I want to learn fsharp. So, I look at exercism.io

In their readme, they instruct you to use Xamarin Studio to run the http://exercism.io/languages/fsharp/tests test

But I would just like to run tests from the terminal. Exercise exercises include only one F # file, for example. HelloWorldTest.fs .

This answer Running tests on a Mac OS X console using the mono / nunit-console / 4 nunit-console allows you to run nunit-console using a .csproj or .dll file, but these files are not present in the exercise files. Therefore, I do not understand what to do.

I have mono using homegrown. How to run a NUnit test from a terminal in OSX?

+5
source share
2 answers

I figured out how to do this:

1. install dotnet as described https://www.microsoft.com/net/core#macos

2. In the exercise launch folder

 dotnet new --lang f# 

3. Rename Program.fs name of the exercise, for example. HelloWorld.fs

4. Change project.json to

 { "version": "1.0.0-*", "buildOptions": { "debugType": "portable", "emitEntryPoint": true, "compilerName": "fsc", "compile": { "includeFiles": [ "HelloWorld.fs", "HelloWorldTest.fs" ] } }, "dependencies": { "NUnit": "3.4.1", "dotnet-test-nunit": "3.4.0-beta-2" }, "tools": { "dotnet-compile-fsc": "1.0.0-preview2-*" }, "frameworks": { "netcoreapp1.0": { "imports": "portable-net45+win8", "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.1" }, "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-160629" } } }, "testRunner": "nunit" } 

This includes a nunit dependency.

Note includeFiles , this should include the source code file for the exercise and the test file. e.g. HelloWorld.fs and HelloWorldTest.fs

5. Install the necessary packages by running

 dotnet restore 

6. Add your code to a previously renamed source file, for example. HelloWorld.fs

7. Finally, run the test by running

  dotnet test 
0
source

You may need to use xbuild on the command line to compile the fsproj file, after which the resulting dll can be executed using nunit on the command line as well.

If you don't have fsproj, you can directly use fsharpc in the file and then call nunit, remembering to use mono to execute nunit.

fsharpc HelloWorldTest.fs

mono nunit-console.exe HelloWorldTest.exe

Sorry, I canโ€™t verify this, but there should be something like this.

0
source

Source: https://habr.com/ru/post/1257721/


All Articles