Git Product home page Git Product logo

fsharp-test-runner's Introduction

Exercism F# test runner

A test runner automatically verifies if a submission passes all the tests.

This repository contains the F# test runner, which implements the test runner interface.

Running the tests

To run a solution's tests, follow these steps:

  1. Open a command prompt in the root directory.
  2. Run ./run.ps1 <exercise> <input-directory> <output-directory>. This script will:
    1. Make sure all tests run (no skipped tests) for the solution found in <input-directory>.
    2. Run all the tests.
    3. Once the script has completed, the test results will be written to <output-directory>/results.json.

Running the tests using Docker

To run a solution's tests using a Docker container, follow these steps:

  1. Open a command prompt in the root directory.
  2. Run ./run-in-docker.ps1 <exercise> <input-directory> <output-directory>. This script will:
    1. Make sure all tests run (no skipped tests) for the solution found in <input-directory>.
    2. Run all the tests.
    3. Once the script has completed, the test results will be written to <output-directory>/results.json.

Scripts

The scripts in this repository are written in PowerShell. As PowerShell is cross-platform nowadays, you can also install it on Linux and macOS.

fsharp-test-runner's People

Contributors

angelikatyborska avatar dependabot[bot] avatar erikschierboom avatar exercism-bot avatar faisalafroz avatar ihid avatar kytrinyx avatar marlonjrbm avatar mattnewport avatar umaranis avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fsharp-test-runner's Issues

Allow running tests that are defined in a class

Most tests are defined as standalone functions. Some are defined in a class though (e.g. for cleanup purposes). This currently breaks the test runner, as the code to capture console output creates a class for the existing code. We should detect if a class is used in the tests and update the rewriting code accordingly.

The master branch will be renamed to main

In line with our new org-wide policy, the master branch of this repo will be renamed to main. All open PRs will be automatically repointed.

GitHub will show you a notification about this when you look at this repo after renaming:

Screenshot 2021-01-27 at 15 31 45

In case it doesn't, this is the command it suggests:

git branch -m master main
git fetch origin
git branch -u origin/main main

You may like to update the primary branch on your forks too, which you can do under Settings->Branches and clicking the pencil icon on the right-hand-side under Default Branch:

Screenshot 2021-01-27 at 18 50 08

We will post a comment below when this is done. We expect it to happen within the next 12 hours.

Having issue runing test for F# 'Accumulate' exercise

Hi, I think there is an issue with F# online editor test.

I've already submitted a bug using the 'Rpeort a bug' function on the editor, apology for the duplication, but I didn't receive any confirmation of the bug I submitted. So I decided to submit the bug report again here as it's easier for me to follow up and see the progress of the bug.

When I am running tests, it always gives me the error message "An ERROR OCCURED" without details:
image

I can't tell if there is any issue with the code, which is relatively simple, and it runs fine inside Visual Studio 2022, so I assume it's a bug in the online editor test runner.

Here is my code if it helps:

module Accumulate

let rec accumulate (func: 'a -> 'b) (input: 'a list): 'b list = 
    match input with
    | [] -> []
    | h :: t -> (func h) :: (accumulate func t)


`Ledger` tests run differently locally and on the test runner

My solution passes all tests (un-skipped, unmodified) locally. On the test runner, only 1 test passes. And on the test runner, I get different results (only 2 failures) if I .Trim() the header line of the ledger. But the remaining failures have weird whitespace differences still on various lines. I'm not sure what the differences are, but it seems like there are different whitespace expectations on the test runner than on the unit tests file.

Want to help

Hi,

I am a mentor for F# track and want to help building the test runner.

Upgrade to version 2 spec

We've recently updated the test runner interface specification to allow for two types of test runners, identified via a new version property in the results.json file (see the spec for the version property):

  1. version: 1 test runners are quite basic, and only detect if either all tests passed or not. These test runners capture the console output of the test runner and output that. They do not include details on individual tests passing/failing
  2. version: 2 test runners contain detailed information on individual tests passing/failing. We've recently added a required field named test_code, which contains the code the test ran to verify the behavior (see the spec for the test_code property).

The test runner's output is currently what I refer to as version 1.5: it contains the individual test information, but does not yet contain the test_code key. If possible, the test runner should be updated to also include the test code, in which case the version property should also be added with 2 as its value.

You are completely free on how you want to extract the test code, either via the AST or via finding the test code in the source code text via string manipulation.

Let me know if there are any questions.

'Grep` test run fails without error message

Similar to Daimond but this does not use property testing. It is using the test as members of a type which is unusual. Could the rewrite affect that?

Checked with a student whose tests pass locally and then with my existing submitted solution.

Missing packages for Rest API

Some use Newtonsoft.Json but the majority of solutions use FSharp.Data/FSharp.Data.JsonExtensions or FSharp.Json and there might be other standard libraries.

These should be added to the TestRunner default packages.

Consider changing to NUnit to easily allow capturing console output

Capturing console output in xUnit 2 is annoying, as you have to work with test classes and constructor injection. Writing the code to support this is annoying, complex and brittle. An option might be to use NUnit as the test framework.
See https://stackoverflow.com/questions/46405753/how-do-i-get-nunit3-console-to-output-my-debug-to-screen-on-a-windows-box

Side note: due to us using FsUnit, the actual test code might not even change much.

AnnalynsInfiltration: tests time out consistently

Running locally, the tests generally need <80 ms, never more than 300 ms on multiple machines and OSs. Hard to know why they won't run on your server? The code has no loops, no recursion.

module AnnalynsInfiltration

let canFastAttack (knightIsAwake: bool): bool = not knightIsAwake

let canSpy (knightIsAwake: bool) (archerIsAwake: bool) (prisonerIsAwake: bool): bool =
    knightIsAwake || archerIsAwake || prisonerIsAwake

let canSignalPrisoner (archerIsAwake: bool) (prisonerIsAwake: bool): bool =
    prisonerIsAwake && not archerIsAwake

let canFreePrisoner (knightIsAwake: bool) (archerIsAwake: bool) (prisonerIsAwake: bool) (petDogIsPresent: bool): bool =
    (petDogIsPresent && not archerIsAwake) || 
    (prisonerIsAwake && not knightIsAwake && not archerIsAwake)

The master branch will be renamed to main

In line with our new org-wide policy, the master branch of this repo will be renamed to main. All open PRs will be automatically repointed.

GitHub will show you a notification about this when you look at this repo after renaming:

Screenshot 2021-01-27 at 15 31 45

In case it doesn't, this is the command it suggests:

git branch -m master main
git fetch origin
git branch -u origin/main main

You may like to update the primary branch on your forks too, which you can do under Settings->Branches and clicking the pencil icon on the right-hand-side under Default Branch:

Screenshot 2021-01-27 at 18 50 08

We will post a comment below when this is done. We expect it to happen within the next 12 hours.

Tests frequently appear to timeout on code that later passes with no functional changes

I frequently find that when I submit code for F# exercises that passes all tests locally in a few ms, the tests will timeout on Exercism and I have to resubmit with changes to the source that have no functional impact but bypass the check on exercism submit that the code is not identical. This doesn't seem to happen nearly as frequently with any other languages in my experience.

Upgrade to version 2 spec

We've recently updated the test runner interface specification to allow for two types of test runners, identified via a new version property in the results.json file (see the spec for the version property):

  1. version: 1 test runners are quite basic, and only detect if either all tests passed or not. These test runners capture the console output of the test runner and output that. They do not include details on individual tests passing/failing
  2. version: 2 test runners contain detailed information on individual tests passing/failing. We've recently added a required field named test_code, which contains the code the test ran to verify the behavior (see the spec for the test_code property).

The test runner's output is currently what I refer to as version 1.5: it contains the individual test information, but does not yet contain the test_code key. If possible, the test runner should be updated to also include the test code, in which case the version property should also be added with 2 as its value.

You are completely free on how you want to extract the test code, either via the AST or via finding the test code in the source code text via string manipulation.

Let me know if there are any questions.

Test runner failing for big test files

Test runner fails with the following error if the test file is big in size.

{
  "status": "error",
  "message": "BeerSongTest.fs(99,1): error FS0010: Incomplete structured construct at or before this point in expression. Expected ']' or other token. \nBeerSongTest.fs(71,9): error FS0598: Unmatched '[' \nBeerSongTest.fs(70,5): error FS0588: The block following this 'let' is unfinished. Every code block is an expression and must have a result. 'let' cannot be the final code element in a block. Consider giving this block an explicit result. \nBeerSongTest.fs(98,11): error FS0514: End of file in string begun at or before here",
  "tests": []
}

To produce, try running it for beer-song exercise.

'Diamond' test run fails without error message

For the Diamond exercise in F#, the submission below fails with an empty error message, stating only "We received the following error when we ran your code", but no actual reason.

image

Looking at the dev console in my browser, I see multiple calls to the "test_run_ endpoint returning

{"test_run":null}

with status 304. If I modify my submission slightly by defining

let space = '.' // instead of let space = ' '

then I receive a "test_run" response with status 200 and some expected test failure messages (after some empty 304s as above).

The code submission:

module Diamond

let alphabet = [|'A'..'Z'|]
let space = ' '

let createUpperHalfRow row size =
    let center = size / 2
    if row = 0 then
        Array.init size (fun i -> if i = center then alphabet.[row] else space)
    else
        Array.init size (fun i -> if i = center - row || i = center + row then alphabet.[row] else space)


let createUpperHalf size =
    Array.init (size / 2 + 1) (fun i -> createUpperHalfRow i size)

let mirrorLowerHalf upperHalf =
    let length = Array.length upperHalf
    Array.init (length - 1) (fun i -> upperHalf.[length - i - 2])

let make letter = 
    let size = (Array.findIndex ((=) letter) alphabet) * 2 + 1
    let upperHalf = createUpperHalf size
    let lowerHalf = mirrorLowerHalf upperHalf

    lowerHalf
    |> Array.append upperHalf
    |> Array.map System.String
    |> String.concat System.Environment.NewLine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.