Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
33 changes: 27 additions & 6 deletions src/gleeunit/internal/reporting.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,49 @@ pub fn test_skipped(state: State, module: String, function: String) -> State {
State(..state, skipped: state.skipped + 1)
}

@external(erlang, "gleeunit_ffi", "getenv")
fn getenv(name: String) -> Result(String, Nil)

fn no_color_env_set() -> Bool {
case getenv("NO_COLOR") {
Ok(_) -> True
Error(_) ->
case getenv("NO_COLOUR") {
Ok(_) -> True
Error(_) -> False
}
}
}

fn color(start: String, end: String, text: String) -> String {
case no_color_env_set() {
True -> text
False -> start <> text <> end
}
}

fn bold(text: String) -> String {
"\u{001b}[1m" <> text <> "\u{001b}[22m"
color("\u{001b}[1m", "\u{001b}[22m", text)
}

fn cyan(text: String) -> String {
"\u{001b}[36m" <> text <> "\u{001b}[39m"
color("\u{001b}[36m", "\u{001b}[39m", text)
}

fn yellow(text: String) -> String {
"\u{001b}[33m" <> text <> "\u{001b}[39m"
color("\u{001b}[33m", "\u{001b}[39m", text)
}

fn green(text: String) -> String {
"\u{001b}[32m" <> text <> "\u{001b}[39m"
color("\u{001b}[32m", "\u{001b}[39m", text)
}

fn red(text: String) -> String {
"\u{001b}[31m" <> text <> "\u{001b}[39m"
color("\u{001b}[31m", "\u{001b}[39m", text)
}

fn grey(text: String) -> String {
"\u{001b}[90m" <> text <> "\u{001b}[39m"
color("\u{001b}[90m", "\u{001b}[39m", text)
}

@external(erlang, "file", "read_file")
Expand Down
7 changes: 6 additions & 1 deletion src/gleeunit_ffi.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-module(gleeunit_ffi).

-export([find_files/2, run_eunit/2]).
-export([find_files/2, run_eunit/2, getenv/1]).

find_files(Pattern, In) ->
Results = filelib:wildcard(binary_to_list(Pattern), binary_to_list(In)),
Expand All @@ -19,3 +19,8 @@ run_eunit(Tests, Options) ->
end
end.

getenv(Name) ->
case os:getenv(binary_to_list(Name)) of
false -> {error, nil};
Value -> {ok, list_to_binary(Value)}
end.