Skip to content
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

Args replacement for Argu #303

Merged
merged 8 commits into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions Expecto.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ let tests =

[<Tests>]
let expecto =

let testArgs i o = Expect.equal (Args.parseOptions options i) o "testArgs"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider sequence equal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's comparing a Result<args list,string list> so a bit more tricky.


testList "expecto" [
testList "Setup & teardown 2" [
// just demoing how you can use a higher-order function as setup/teardown
Expand Down Expand Up @@ -294,6 +297,156 @@ let expecto =
Expect.isNone test ""
]

testList "args" [
testAsync "empty" {
testArgs [||] (Ok [])
}
testAsync "one" {
testArgs [|"--sequenced"|] (Ok [Sequenced])
}
testAsync "two" {
testArgs [|"--parallel";"--sequenced"|]
(Ok [Parallel;Sequenced])
}
testAsync "three" {
testArgs [|"--sequenced";"--stress";"1.2";"--parallel"|]
(Ok [Sequenced;Stress 1.2;Parallel;])
}
testAsync "int" {
testArgs [|"--parallel-workers";"3"|]
(Ok [Parallel_Workers 3])
}
testAsync "int error" {
testArgs [|"--fscheck-end-size";"1.2"|]
(Result.Error ["--fscheck-end-size cannot parse parameter '1.2'"])
}
testAsync "float" {
testArgs [|"--stress-memory-limit";"3"|]
(Ok [Stress_Memory_Limit 3.0])
}
testAsync "float error" {
testArgs [|"--stress-memory-limit";"3sd"|]
(Result.Error ["--stress-memory-limit cannot parse parameter '3sd'"])
}
testAsync "missing string" {
testArgs [|"--log-name";"--sequenced"|]
(Result.Error ["--log-name requires a parameter"])
}
testAsync "missing int" {
testArgs [|"--fscheck-max-tests";"--parallel"|]
(Result.Error ["--fscheck-max-tests requires a parameter"])
}
testAsync "many" {
testArgs [|"--run";"one";"two";"three"|]
(Ok [Run ["one";"two";"three"]])
}
testAsync "many end" {
testArgs [|"--run";"one";"two";"three";"--parallel"|]
(Ok [Run ["one";"two";"three"];Parallel])
}
testAsync "unknown start" {
testArgs [|"hello";"--parallel";"--sequenced"|]
(Result.Error ["unknown options: hello"])
}
testAsync "unknown middle" {
testArgs [|"--parallel";"hello";"--sequenced"|]
(Result.Error ["unknown options: hello"])
}
testAsync "unknown end" {
testArgs [|"--parallel";"--sequenced";"hello"|]
(Result.Error ["unknown options: hello"])
}
testAsync "unknown all" {
testArgs [|"one";"--parallel";"two";"--fscheck-max-tests";"42";"three"|]
(Result.Error ["unknown options: one two three"])
}
testAsync "help" {
testArgs [|"--help"|]
(Result.Error [])
}
testAsync "help start" {
testArgs [|"--help";"--sequenced"|]
(Result.Error [])
}
testAsync "help end" {
testArgs [|"--sequenced";"--help"|]
(Result.Error [])
}
testAsync "help middle" {
testArgs [|"--sequenced";"--help";"--parallel"|]
(Result.Error [])
}
testAsync "help and unknown" {
testArgs [|"one";"--sequenced";"two";"--help";"three";"--parallel";"four"|]
(Result.Error ["unknown options: one two three four"])
}
testAsync "two errors" {
testArgs [|"one";"--filter"|]
(Result.Error ["--filter requires a parameter";"unknown options: one"])
}
testAsync "three errors" {
testArgs [|"--fscheck-start-size";"bb";"one";"--filter"|]
(Result.Error [
"--fscheck-start-size cannot parse parameter 'bb'"
"--filter requires a parameter"
"unknown options: one"
])
}
testAsync "lots" {
let args = [|
"--sequenced"
"--parallel"
"--parallel-workers"; "3"
"--stress"; "0.1"
"--stress-timeout"; "100.1"
"--stress-memory-limit"; "128"
"--fail-on-focused-tests"
"--debug"
"--log-name"; "fred"
"--filter"; "phil"
"--filter-test-list"; "f list"
"--filter-test-case"; "f case"
"--run"; "a"; "b"; "c"
"--list-tests"
"--summary"
"--version"
"--summary-location"
"--fscheck-max-tests"; "5"
"--fscheck-start-size"; "10"
"--fscheck-end-size"; "20"
"--my-spirit-is-weak"
"--allow-duplicate-names"
"--no-spinner"
|]
let ok = [
Sequenced
Parallel
Parallel_Workers 3
Stress 0.1
Stress_Timeout 100.1
Stress_Memory_Limit 128.0
Fail_On_Focused_Tests
Debug
Log_Name "fred"
Filter "phil"
Filter_Test_List "f list"
Filter_Test_Case "f case"
Run ["a";"b";"c"]
List_Tests
Summary
Version
Summary_Location
FsCheck_Max_Tests 5
FsCheck_Start_Size 10
FsCheck_End_Size 20
My_Spirit_Is_Weak
Allow_Duplicate_Names
No_Spinner
]
testArgs args (Ok ok)
}
]

testList "parse args" [
testCase "default" <| fun _ ->
match ExpectoConfig.fillFromArgs defaultConfig [||] with
Expand Down
Loading