Skip to content

Commit ee9f68e

Browse files
committed
Fix test detection
1 parent e06c404 commit ee9f68e

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

test/gleeunit.gleam

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import gleam/list
2+
import gleam/result
23
import gleam/string
34

45
/// Find and run all test functions for the current project using Erlang's EUnit
@@ -34,10 +35,19 @@ fn do_main() -> Nil {
3435
fn halt(a: Int) -> Nil
3536

3637
fn gleam_to_erlang_module_name(path: String) -> String {
37-
path
38-
|> string.replace(".gleam", "")
39-
|> string.replace(".erl", "")
40-
|> string.replace("/", "@")
38+
case string.ends_with(path, ".gleam") {
39+
True ->
40+
path
41+
|> string.replace(".gleam", "")
42+
|> string.replace("/", "@")
43+
44+
False ->
45+
path
46+
|> string.split("/")
47+
|> list.last
48+
|> result.unwrap(path)
49+
|> string.replace(".erl", "")
50+
}
4151
}
4252

4353
@external(erlang, "gleeunit_ffi", "find_files")

test/gleeunit_ffi.erl

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
11
-module(gleeunit_ffi).
22

3-
-export([find_files/2, should_equal/2, should_not_equal/2, should_be_ok/1,
4-
should_be_error/1, run_eunit/2]).
5-
6-
-include_lib("eunit/include/eunit.hrl").
3+
-export([find_files/2, run_eunit/2]).
74

85
find_files(Pattern, In) ->
96
Results = filelib:wildcard(binary_to_list(Pattern), binary_to_list(In)),
107
lists:map(fun list_to_binary/1, Results).
118

12-
should_equal(Actual, Expected) ->
13-
?assertEqual(Expected, Actual),
14-
nil.
15-
should_not_equal(Actual, Expected) ->
16-
?assertNotEqual(Expected, Actual),
17-
nil.
18-
should_be_ok(A) ->
19-
?assertMatch({ok, _}, A),
20-
element(2, A).
21-
should_be_error(A) ->
22-
?assertMatch({error, _}, A),
23-
element(2, A).
24-
259
run_eunit(Tests, Options) ->
2610
case eunit:test(Tests, Options) of
2711
ok -> {ok, nil};

test/gleeunit_progress.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ handle_end(test, Data, State) ->
4848
?reporting:test_failed(State, Module, Function, Exception)
4949
end.
5050

51-
handle_cancel(_test_or_group, _data, State) ->
52-
State.
51+
handle_cancel(_test_or_group, Data, State) ->
52+
?reporting:test_failed(State, <<"gleeunit">>, <<"main">>, Data).
5353

5454
terminate({ok, _Data}, State) ->
5555
?reporting:finished(State),

0 commit comments

Comments
 (0)