-
Notifications
You must be signed in to change notification settings - Fork 81
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
Review how tests are registered #126
Comments
One potential issue here is that if tests are spread out over multiple files, either (1) the files have to still be referenced from somewhere to be linked, or (2) we need to tell users to pass |
I'd like to suggest a design for adding to the 'automatic list of things to test'. In the below hypothetical code snippet I will use the test suite shown in the readme example: https://github.com/mirage/alcotest/blob/main/README.md#examples Alcotest.suite "Utils" begin fun group ->
group "string-case" begin fun case ->
case "Lower case" begin fun () ->
Alcotest.(check string) "same string" "hello!" (To_test.lowercase "hELLO!")
end;
case "Capitalization" begin fun () ->
Alcotest.(check string) "same string" "World." (To_test.capitalize "world.")
end;
end;
group "string-concat" begin fun case ->
case "String mashing" begin fun () ->
Alcotest.(check string) "same string" "foobar" (To_test.str_concat ["foo"; "bar"])
end;
end;
group "list-concat" begin fun case ->
case ~speed:`Slow "List mashing" begin fun () ->
Alcotest.(check (list int)) "same lists" [1; 2; 3] (To_test.list_concat [1] [2; 3])
end;
end;
end The idea of this style is that Alcotest calls the given test suites and groups with functions which have been already set up internally with |
I quite like @yawaramin's approach; it looks (and feels) a lot more like the RSpec / Jest style tests that I've been used to over the years from other languages and environments. (In fact, I think Jest even used to provide both styles of API, with the |
Hey, yeah, I had something like Ruby on my mind for this. To make it easy for people to compare, pretending for a second that the module was written in Ruby, here's part of it translated to RSpec: RSpec.describe Utils, "Utils" do
context "string-case" do
it "Lower case" do
expect(To_test.lowercase("hEllO!")).to eq "hello!"
end
it "Capitalization" do
expect(To_test.capitalize("world.")).to eq "World."
end
end
end |
Alternative design: let () =
let open Alcotest in
run "Utils" [
group "string-case" [
case "Lower case" begin fun () ->
check string "same string" "hello!" (To_test.lowercase "hELLO!")
end;
case "Capitalization" begin fun () ->
check string "same string" "World." (To_test.capitalize "world.")
end;
];
group "string-concat" [
case "String mashing" begin fun () ->
check string "same string" "foobar" (To_test.str_concat ["foo"; "bar"])
end;
];
group "list-concat" [
case ~speed:`Slow "List mashing" begin fun () ->
check (list int) "same lists" [1; 2; 3] (To_test.list_concat [1] [2; 3])
end;
];
] The idea is that instead of messing around with tuples we provide constructors of the correct types. Then we say that an Alcotest suite contains a list of groups, and a group contains a list of cases. |
Any updates on this and #393? |
Few users have expressed the fact that listing all the tests is error prone (as you could easily forget to add a test if you don't have error-as-warning + an empty mli to guide you).
Maybe we expose a combinator like crowbar where tests are automatically added to a global list of things to test.
The text was updated successfully, but these errors were encountered: