Skip to content

Commit e88f9ad

Browse files
committed
refactor: replace @target with external fallbacks
1 parent cd35256 commit e88f9ad

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/unitest.gleam

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,11 +1458,7 @@ fn start_module_pool(
14581458
workers: Int,
14591459
) -> Nil
14601460

1461-
@target(erlang)
1461+
@external(javascript, "./unitest_ffi.mjs", "yieldThen")
14621462
fn yield_then(next: fn() -> Nil) -> Nil {
14631463
next()
14641464
}
1465-
1466-
@target(javascript)
1467-
@external(javascript, "./unitest_ffi.mjs", "yieldThen")
1468-
fn yield_then(next: fn() -> Nil) -> Nil

src/unitest/internal/discovery.gleam

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ const gleam_extension = ".gleam"
1111

1212
const test_directory = "test"
1313

14-
@target(erlang)
15-
const current_target = "erlang"
16-
17-
@target(javascript)
18-
const current_target = "javascript"
14+
@external(javascript, "../../unitest_ffi.mjs", "currentTarget")
15+
fn current_target() -> String {
16+
"erlang"
17+
}
1918

2019
pub type LineSpan {
2120
LineSpan(start_line: Int, end_line: Int)
@@ -137,7 +136,7 @@ fn tests_from_contents(
137136
}
138137

139138
pub fn parse_module(source: String) -> Result(List(ParsedTest), glance.Error) {
140-
parse_module_for_target(source, current_target)
139+
parse_module_for_target(source, current_target())
141140
}
142141

143142
pub fn parse_module_for_target(

src/unitest_ffi.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ export function nowMs() {
101101
return Math.round(performance.now());
102102
}
103103

104+
export function currentTarget() {
105+
return "javascript";
106+
}
107+
104108
export function halt(code) {
105109
if (runtime === "node") {
106110
process.exitCode = code;

0 commit comments

Comments
 (0)