Skip to content

Commit

Permalink
Add tests and support for v2 of elm-explorations/test (#118)
Browse files Browse the repository at this point in the history
* Add tests

* Flesh out tests

* tweak .gitignore wrt. coverage

* Rename test directory

* Add kitchensink test

Why: to see how multiple coverage reports interact (newlines and all)

* Change elm-explorations/test dep to 2.0.0 preemptively

* Remove turboMaCk/queue dependency from elm.json

* Rename `coverage` to `distribution`

* Update elm-test-runner dep to verion 6.0.0

* Update elm-test-rs to v3.0.0 (fuzz distributions support)

* Update changelog with info about v3.0

Co-authored-by: Matthieu Pizenberg <[email protected]>
  • Loading branch information
Janiczek and mpizenberg authored Oct 11, 2022
1 parent 527020c commit d8a08a7
Show file tree
Hide file tree
Showing 41 changed files with 605 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pids
lib-cov

# Coverage directory used by tools like istanbul
coverage
/coverage
*.lcov

# nyc test coverage
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ All notable changes to this project will be documented in this file.
#### Fixed


## [3.0.0] - (2022-10-11) [(diff)][diff-3.0.0]

#### Changed

- This version now supports the new `elm-explorations/test` v2.
- The reporters have been updated by `@Janiczek` to support the new fuzzer API
with information and checks about the random distributions.
More info about those changes in [that library changelog](https://github.com/elm-explorations/test/blob/master/CHANGELOG.md#changes-in-200).


## [2.0.2] - (2022-10-03) [(diff)][diff-2.0.2]

#### Changed
Expand Down Expand Up @@ -281,6 +291,7 @@ All notable changes to this project will be documented in this file.
- `.gitmodules` git submodules.
- `.github/workflows/` CI to automatically build and test on pull requests.

[3.0.0]: https://github.com/mpizenberg/elm-test-rs/releases/tag/v3.0
[2.0.2]: https://github.com/mpizenberg/elm-test-rs/releases/tag/v2.0.2
[2.0.1]: https://github.com/mpizenberg/elm-test-rs/releases/tag/v2.0.1
[2.0.0]: https://github.com/mpizenberg/elm-test-rs/releases/tag/v2.0
Expand All @@ -299,7 +310,7 @@ All notable changes to this project will be documented in this file.
[0.2.0]: https://github.com/mpizenberg/elm-test-rs/releases/tag/v0.2
[0.1.1]: https://github.com/mpizenberg/elm-test-rs/releases/tag/v0.1.1
[0.1.0]: https://github.com/mpizenberg/elm-test-rs/releases/tag/v0.1
[diff-unreleased]: https://github.com/mpizenberg/elm-test-rs/compare/v2.0.2...master
[diff-unreleased]: https://github.com/mpizenberg/elm-test-rs/compare/v3.0...master
[diff-2.0.2]: https://github.com/mpizenberg/elm-test-rs/compare/v2.0.1...v2.0.2
[diff-2.0.1]: https://github.com/mpizenberg/elm-test-rs/compare/v2.0...v2.0.1
[diff-2.0.0]: https://github.com/mpizenberg/elm-test-rs/compare/v1.2.2...v2.0
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "elm-test-rs"
version = "2.0.2"
version = "3.0.0"
authors = ["Matthieu Pizenberg <[email protected]>", "Harry Sarson <[email protected]>"]
edition = "2021"
description = "Simple and fast Rust alternative to node-test-runner to run elm tests"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ For `mdgriffith/elm-ui` for example, it will give the following.
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"elm/virtual-dom": "1.0.2",
"elm-explorations/test": "1.2.2",
"mpizenberg/elm-test-runner": "4.0.3"
"elm-explorations/test": "2.0.0",
"mpizenberg/elm-test-runner": "6.0.0"
},
"indirect": {
"elm/random": "1.0.0",
Expand All @@ -182,8 +182,8 @@ While if you run `elm-test-rs -vv --dependencies oldest`, you will get those.
"elm/html": "1.0.0",
"elm/json": "1.0.0",
"elm/virtual-dom": "1.0.0",
"elm-explorations/test": "1.2.2",
"mpizenberg/elm-test-runner": "4.0.3"
"elm-explorations/test": "2.0.0",
"mpizenberg/elm-test-runner": "6.0.0"
},
"indirect": {
"elm/random": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
.join("packages")
.join("mpizenberg")
.join("elm-test-runner")
.join("5.0.0");
.join("6.0.0");
let elm_stuff = Path::new("elm").join("elm-stuff");
std::fs::remove_dir_all(&elm_stuff)
.unwrap_or_else(|_| println!("Error removing elm/elm-stuff"));
Expand Down
4 changes: 2 additions & 2 deletions src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn solve<P: AsRef<Path>>(
}

fn supported_testlib_range() -> Range<SemVer> {
Range::between((1, 0, 0), (2, 0, 0))
Range::between((2, 0, 0), (3, 0, 0))
}

fn check_testlib_present(all_deps: &Map<Pkg, Range<SemVer>>) -> anyhow::Result<()> {
Expand Down Expand Up @@ -262,7 +262,7 @@ fn solve_helper<P: AsRef<Path>>(
let mut deps = direct_deps;
deps.insert(
Pkg::new("mpizenberg", "elm-test-runner"),
Range::exact((5, 0, 0)),
Range::exact((6, 0, 0)),
);
// Add elm/json to the deps since it's used in Runner.elm and Reporter.elm.
// TODO: maybe not the best way to handle but should work most of the time.
Expand Down
2 changes: 1 addition & 1 deletion tests/example-projects/failing/debug-log/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
},
"test-dependencies": {
"elm/json": "1.1.3 <= v < 2.0.0",
"elm-explorations/test": "1.2.2 <= v < 2.0.0"
"elm-explorations/test": "2.0.0 <= v < 3.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "package",
"name": "mpizenberg/elm-placeholder-pkg",
"summary": "An empty placeholder package",
"license": "MPL-2.0",
"version": "1.0.0",
"elm-version": "0.19.0 <= v < 0.20.0",
"exposed-modules": [
"EmptyPlaceholderModule"
],
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {
"elm/json": "1.1.3 <= v < 2.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Question exposing (answer)


answer : String -> Int
answer question =
let
_ =
Debug.log "The question was" question
in
if question == "What is the Answer to the Ultimate Question of Life, The Universe, and Everything?" then
43

else
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Tests exposing (..)

import Expect
import Fuzz
import Question
import Test exposing (Test)
import Test.Distribution


suite : Test
suite =
Test.fuzzWith
{ runs = 100
, distribution =
Test.expectDistribution
[ ( Test.Distribution.atLeast 4, "low", \n -> n == 1 )
, ( Test.Distribution.atLeast 4, "high", \n -> n == 20 )
, ( Test.Distribution.atLeast 80, "in between", \n -> n > 1 && n < 20 )
, ( Test.Distribution.zero, "outside", \n -> n < 1 || n > 20 )
, ( Test.Distribution.zero, "one", \n -> n == 1 )
]
}
(Fuzz.intRange 1 20)
"Will fail because of distribution demands not met"
(\n -> Expect.pass)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "package",
"name": "mpizenberg/elm-placeholder-pkg",
"summary": "An empty placeholder package",
"license": "MPL-2.0",
"version": "1.0.0",
"elm-version": "0.19.0 <= v < 0.20.0",
"exposed-modules": [
"EmptyPlaceholderModule"
],
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {
"elm/json": "1.1.3 <= v < 2.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Question exposing (answer)


answer : String -> Int
answer question =
let
_ =
Debug.log "The question was" question
in
if question == "What is the Answer to the Ultimate Question of Life, The Universe, and Everything?" then
43

else
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Tests exposing (..)

import Expect
import Fuzz
import Question
import Test exposing (Test)
import Test.Distribution


suite : Test
suite =
Test.fuzzWith
{ runs = 100
, distribution =
Test.expectDistribution
[ ( Test.Distribution.atLeast 4, "low", \n -> n == 1 )
, ( Test.Distribution.atLeast 4, "high", \n -> n == 20 )
, ( Test.Distribution.atLeast 80, "in between", \n -> n > 1 && n < 20 )
, ( Test.Distribution.zero, "outside", \n -> n < 1 || n > 20 )
, ( Test.Distribution.moreThanZero, "one", \n -> n == 1 )
]
}
(Fuzz.intRange 1 20)
"Will fail because of distribution demands not met"
(\n -> Expect.fail "This test should fail")
18 changes: 18 additions & 0 deletions tests/example-projects/failing/distribution-not-met/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "package",
"name": "mpizenberg/elm-placeholder-pkg",
"summary": "An empty placeholder package",
"license": "MPL-2.0",
"version": "1.0.0",
"elm-version": "0.19.0 <= v < 0.20.0",
"exposed-modules": [
"EmptyPlaceholderModule"
],
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {
"elm/json": "1.1.3 <= v < 2.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Question exposing (answer)


answer : String -> Int
answer question =
let
_ =
Debug.log "The question was" question
in
if question == "What is the Answer to the Ultimate Question of Life, The Universe, and Everything?" then
43

else
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Tests exposing (..)

import Expect
import Fuzz
import Question
import Test exposing (Test)
import Test.Distribution


suite : Test
suite =
Test.fuzzWith
{ runs = 100
, distribution =
Test.expectDistribution
[ ( Test.Distribution.atLeast 4, "low", \n -> n == 1 )
, ( Test.Distribution.atLeast 4, "high", \n -> n == 20 )
, ( Test.Distribution.atLeast 80, "in between", \n -> n > 1 && n < 20 )
, ( Test.Distribution.zero, "outside", \n -> n < 1 || n > 20 )
, ( Test.Distribution.zero, "one", \n -> n == 1 )
]
}
(Fuzz.intRange 1 20)
"Will fail because of distribution demands not met"
(\n -> Expect.pass)
18 changes: 18 additions & 0 deletions tests/example-projects/failing/distribution-of-failing/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "package",
"name": "mpizenberg/elm-placeholder-pkg",
"summary": "An empty placeholder package",
"license": "MPL-2.0",
"version": "1.0.0",
"elm-version": "0.19.0 <= v < 0.20.0",
"exposed-modules": [
"EmptyPlaceholderModule"
],
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {
"elm/json": "1.1.3 <= v < 2.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Question exposing (answer)


answer : String -> Int
answer question =
let
_ =
Debug.log "The question was" question
in
if question == "What is the Answer to the Ultimate Question of Life, The Universe, and Everything?" then
43

else
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Tests exposing (..)

import Expect
import Fuzz
import Question
import Test exposing (Test)


suite : Test
suite =
Test.fuzzWith
{ runs = 100
, distribution =
Test.reportDistribution
[ ( "low", \n -> n == 1 )
, ( "high", \n -> n == 20 )
, ( "in between", \n -> n > 1 && n < 20 )
, ( "outside", \n -> n < 1 || n > 20 )
]
}
(Fuzz.intRange 1 20)
"Failing test with distribution report"
(\n -> Expect.fail "Test fails no matter what")
18 changes: 18 additions & 0 deletions tests/example-projects/failing/distribution-report/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "package",
"name": "mpizenberg/elm-placeholder-pkg",
"summary": "An empty placeholder package",
"license": "MPL-2.0",
"version": "1.0.0",
"elm-version": "0.19.0 <= v < 0.20.0",
"exposed-modules": [
"EmptyPlaceholderModule"
],
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {
"elm/json": "1.1.3 <= v < 2.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Question exposing (answer)


answer : String -> Int
answer question =
let
_ =
Debug.log "The question was" question
in
if question == "What is the Answer to the Ultimate Question of Life, The Universe, and Everything?" then
43

else
0
Loading

0 comments on commit d8a08a7

Please sign in to comment.