diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 6bfb3cad4f..1c26d03f9d 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -1188,6 +1188,51 @@ mod cli_run { out.assert_stdout_ends_with(expected_ending); } } + + #[test] + #[cfg_attr(windows, ignore)] + fn run_packages_unoptimized() { + build_platform_host(); + + let expected_ending = + "Hello, World! This text came from a package! This text came from a CSV package!\n"; + let runner = cli_utils::helpers::Run::new_roc() + .arg(CMD_RUN) + .arg(from_root("crates/cli/tests/fixtures/packages", "app.roc").as_path()); + + if ALLOW_VALGRIND { + let out = runner.run_with_valgrind(); + out.assert_clean_success(); + out.assert_stdout_ends_with(expected_ending); + } else { + let out = runner.run(); + out.assert_clean_success(); + out.assert_stdout_ends_with(expected_ending); + } + } + + #[test] + #[cfg_attr(windows, ignore)] + fn run_packages_optimized() { + build_platform_host(); + + let expected_ending = + "Hello, World! This text came from a package! This text came from a CSV package!\n"; + let runner = cli_utils::helpers::Run::new_roc() + .arg(CMD_RUN) + .arg(OPTIMIZE_FLAG) + .arg(from_root("crates/cli/tests/fixtures/packages", "app.roc").as_path()); + + if ALLOW_VALGRIND { + let out = runner.run_with_valgrind(); + out.assert_clean_success(); + out.assert_stdout_ends_with(expected_ending); + } else { + let out = runner.run(); + out.assert_clean_success(); + out.assert_stdout_ends_with(expected_ending); + } + } } // TODO not sure if this cfg should still be here: #[cfg(not(debug_assertions))] @@ -1458,36 +1503,6 @@ mod cli_run { } } - #[test] - #[serial(multi_dep_thunk)] - #[cfg_attr(windows, ignore)] - fn run_packages_unoptimized() { - test_roc_app( - from_root("crates/cli/tests/fixtures/packages", "app.roc").as_path(), - vec![], - &[], - vec![], - "Hello, World! This text came from a package! This text came from a CSV package!\n", - UseValgrind::Yes, - TestCliCommands::Run, - ); - } - - #[test] - #[serial(multi_dep_thunk)] - #[cfg_attr(windows, ignore)] - fn run_packages_optimized() { - test_roc_app( - from_root("crates/cli/tests/fixtures/packages", "app.roc").as_path(), - vec![OPTIMIZE_FLAG], - &[], - vec![], - "Hello, World! This text came from a package! This text came from a CSV package!\n", - UseValgrind::Yes, - TestCliCommands::Run, - ); - } - #[test] #[serial(multi_dep_thunk)] #[cfg_attr(windows, ignore)] diff --git a/crates/cli/tests/fixtures/multi-dep-str/Dep1.roc b/crates/cli/tests/fixtures/multi-dep-str/Dep1.roc index c903b76dce..27d078d39e 100644 --- a/crates/cli/tests/fixtures/multi-dep-str/Dep1.roc +++ b/crates/cli/tests/fixtures/multi-dep-str/Dep1.roc @@ -1,4 +1,6 @@ -interface Dep1 exposes [str1] imports [Dep2] +module [str1] + +import Dep2 str1 : Str str1 = Dep2.str2 diff --git a/crates/cli/tests/fixtures/multi-dep-str/Dep2.roc b/crates/cli/tests/fixtures/multi-dep-str/Dep2.roc index b4f446c079..cb2c1eca4d 100644 --- a/crates/cli/tests/fixtures/multi-dep-str/Dep2.roc +++ b/crates/cli/tests/fixtures/multi-dep-str/Dep2.roc @@ -1,4 +1,4 @@ -interface Dep2 exposes [str2] imports [] +module [str2] str2 : Str str2 = "I am Dep2.str2" diff --git a/crates/cli/tests/fixtures/multi-dep-str/Main.roc b/crates/cli/tests/fixtures/multi-dep-str/Main.roc index 68b60ec5e8..58e378ed1d 100644 --- a/crates/cli/tests/fixtures/multi-dep-str/Main.roc +++ b/crates/cli/tests/fixtures/multi-dep-str/Main.roc @@ -1,7 +1,6 @@ -app "multi-dep-str" - packages { pf: "../../test-platform-simple-zig/main.roc" } - imports [Dep1] - provides [main] to pf +app [main] { pf: platform "../../test-platform-simple-zig/main.roc" } + +import Dep1 main : Str main = Dep1.str1 diff --git a/crates/cli/tests/fixtures/multi-dep-thunk/Dep1.roc b/crates/cli/tests/fixtures/multi-dep-thunk/Dep1.roc index b52416c426..a975704b4f 100644 --- a/crates/cli/tests/fixtures/multi-dep-thunk/Dep1.roc +++ b/crates/cli/tests/fixtures/multi-dep-thunk/Dep1.roc @@ -1,4 +1,6 @@ -interface Dep1 exposes [value1] imports [Dep2] +module [value1] + +import Dep2 value1 : {} -> Str value1 = \_ -> Dep2.value2 {} diff --git a/crates/cli/tests/fixtures/multi-dep-thunk/Dep2.roc b/crates/cli/tests/fixtures/multi-dep-thunk/Dep2.roc index 71b19dd775..c75c645283 100644 --- a/crates/cli/tests/fixtures/multi-dep-thunk/Dep2.roc +++ b/crates/cli/tests/fixtures/multi-dep-thunk/Dep2.roc @@ -1,4 +1,4 @@ -interface Dep2 exposes [value2] imports [] +module [value2] value2 : {} -> Str value2 = \_ -> "I am Dep2.value2" diff --git a/crates/cli/tests/fixtures/multi-dep-thunk/Main.roc b/crates/cli/tests/fixtures/multi-dep-thunk/Main.roc index 82f33c7dcf..00fb7fd151 100644 --- a/crates/cli/tests/fixtures/multi-dep-thunk/Main.roc +++ b/crates/cli/tests/fixtures/multi-dep-thunk/Main.roc @@ -1,7 +1,6 @@ -app "multi-dep-thunk" - packages { pf: "../../test-platform-simple-zig/main.roc" } - imports [Dep1] - provides [main] to pf +app [main] { pf: platform "../../test-platform-simple-zig/main.roc" } + +import Dep1 main : Str main = Dep1.value1 {} diff --git a/crates/cli/tests/fixtures/multi-dep-thunk/platform/host.zig b/crates/cli/tests/fixtures/multi-dep-thunk/platform/host.zig deleted file mode 100644 index 3859fd9015..0000000000 --- a/crates/cli/tests/fixtures/multi-dep-thunk/platform/host.zig +++ /dev/null @@ -1,119 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const str = @import("glue").str; -const RocStr = str.RocStr; -const testing = std.testing; -const expectEqual = testing.expectEqual; -const expect = testing.expect; - -const mem = std.mem; -const Allocator = mem.Allocator; - -extern fn roc__mainForHost_1_exposed_generic(*RocStr) void; - -const Align = 2 * @alignOf(usize); -extern fn malloc(size: usize) callconv(.C) ?*anyopaque; -extern fn realloc(c_ptr: [*]align(@alignOf(u128)) u8, size: usize) callconv(.C) ?*anyopaque; -extern fn free(c_ptr: [*]align(@alignOf(u128)) u8) callconv(.C) void; -extern fn memcpy(dst: [*]u8, src: [*]u8, size: usize) callconv(.C) void; -extern fn memset(dst: [*]u8, value: i32, size: usize) callconv(.C) void; - -export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*anyopaque { - _ = alignment; - return malloc(size); -} - -export fn roc_realloc(c_ptr: *anyopaque, new_size: usize, old_size: usize, alignment: u32) callconv(.C) ?*anyopaque { - _ = old_size; - _ = alignment; - return realloc(@as([*]align(Align) u8, @alignCast(@ptrCast(c_ptr))), new_size); -} - -export fn roc_dealloc(c_ptr: *anyopaque, alignment: u32) callconv(.C) void { - _ = alignment; - free(@as([*]align(Align) u8, @alignCast(@ptrCast(c_ptr)))); -} - -export fn roc_memset(dst: [*]u8, value: i32, size: usize) callconv(.C) void { - return memset(dst, value, size); -} - -export fn roc_panic(msg: *RocStr, tag_id: u32) callconv(.C) void { - const stderr = std.io.getStdErr().writer(); - switch (tag_id) { - 0 => { - stderr.print("Roc standard library crashed with message\n\n {s}\n\nShutting down\n", .{msg.asSlice()}) catch unreachable; - }, - 1 => { - stderr.print("Application crashed with message\n\n {s}\n\nShutting down\n", .{msg.asSlice()}) catch unreachable; - }, - else => unreachable, - } - std.process.exit(1); -} - -export fn roc_dbg(loc: *RocStr, msg: *RocStr, src: *RocStr) callconv(.C) void { - const stderr = std.io.getStdErr().writer(); - stderr.print("[{s}] {s} = {s}\n", .{ loc.asSlice(), src.asSlice(), msg.asSlice() }) catch unreachable; -} - -extern fn kill(pid: c_int, sig: c_int) c_int; -extern fn shm_open(name: *const i8, oflag: c_int, mode: c_uint) c_int; -extern fn mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) *anyopaque; -extern fn getppid() c_int; - -fn roc_getppid() callconv(.C) c_int { - return getppid(); -} - -fn roc_getppid_windows_stub() callconv(.C) c_int { - return 0; -} - -fn roc_shm_open(name: *const i8, oflag: c_int, mode: c_uint) callconv(.C) c_int { - return shm_open(name, oflag, mode); -} -fn roc_mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) callconv(.C) *anyopaque { - return mmap(addr, length, prot, flags, fd, offset); -} - -comptime { - if (builtin.os.tag == .macos or builtin.os.tag == .linux) { - @export(roc_getppid, .{ .name = "roc_getppid", .linkage = .Strong }); - @export(roc_mmap, .{ .name = "roc_mmap", .linkage = .Strong }); - @export(roc_shm_open, .{ .name = "roc_shm_open", .linkage = .Strong }); - } - - if (builtin.os.tag == .windows) { - @export(roc_getppid_windows_stub, .{ .name = "roc_getppid", .linkage = .Strong }); - } -} - -const Unit = extern struct {}; - -pub export fn main() i32 { - const stdout = std.io.getStdOut().writer(); - const stderr = std.io.getStdErr().writer(); - - var timer = std.time.Timer.start() catch unreachable; - - // actually call roc to populate the callresult - var callresult = RocStr.empty(); - roc__mainForHost_1_exposed_generic(&callresult); - - const nanos = timer.read(); - const seconds = (@as(f64, @floatFromInt(nanos)) / 1_000_000_000.0); - - // stdout the result - stdout.print("{s}\n", .{callresult.asSlice()}) catch unreachable; - - callresult.decref(); - - stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable; - - return 0; -} - -fn to_seconds(tms: std.os.timespec) f64 { - return @as(f64, @floatFromInt(tms.tv_sec)) + (@as(f64, @floatFromInt(tms.tv_nsec)) / 1_000_000_000.0); -} diff --git a/crates/cli/tests/fixtures/multi-dep-thunk/platform/main.roc b/crates/cli/tests/fixtures/multi-dep-thunk/platform/main.roc deleted file mode 100644 index ad427260fa..0000000000 --- a/crates/cli/tests/fixtures/multi-dep-thunk/platform/main.roc +++ /dev/null @@ -1,9 +0,0 @@ -platform "multi-dep-thunk" - requires {}{ main : Str } - exposes [] - packages {} - imports [] - provides [mainForHost] - -mainForHost : Str -mainForHost = main diff --git a/crates/cli/tests/fixtures/packages/app.roc b/crates/cli/tests/fixtures/packages/app.roc index 22918325c9..12487fb128 100644 --- a/crates/cli/tests/fixtures/packages/app.roc +++ b/crates/cli/tests/fixtures/packages/app.roc @@ -1,6 +1,10 @@ -app "packages-test" - packages { pf: "platform/main.roc", json: "json/main.roc", csv: "csv/main.roc" } - imports [json.JsonParser, csv.Csv] - provides [main] to pf +app [main] { + pf: platform "../../test-platform-simple-zig/main.roc", + json: "json/main.roc", + csv: "csv/main.roc", +} + +import json.JsonParser +import csv.Csv main = "Hello, World! $(JsonParser.example) $(Csv.example)" diff --git a/crates/cli/tests/fixtures/packages/csv/Csv.roc b/crates/cli/tests/fixtures/packages/csv/Csv.roc index bc71f776d4..ce5afa7f4e 100644 --- a/crates/cli/tests/fixtures/packages/csv/Csv.roc +++ b/crates/cli/tests/fixtures/packages/csv/Csv.roc @@ -1,6 +1,4 @@ -interface Csv - exposes [example] - imports [] +module [example] example : Str -example = "This text came from a CSV package!" \ No newline at end of file +example = "This text came from a CSV package!" diff --git a/crates/cli/tests/fixtures/packages/json/JsonParser.roc b/crates/cli/tests/fixtures/packages/json/JsonParser.roc index 2ebd6b1a62..1ff99b4540 100644 --- a/crates/cli/tests/fixtures/packages/json/JsonParser.roc +++ b/crates/cli/tests/fixtures/packages/json/JsonParser.roc @@ -1,6 +1,4 @@ -interface JsonParser - exposes [example] - imports [] +module [example] example : Str -example = "This text came from a package!" \ No newline at end of file +example = "This text came from a package!" diff --git a/crates/cli/tests/fixtures/packages/platform/host.zig b/crates/cli/tests/fixtures/packages/platform/host.zig deleted file mode 100644 index 029a3ea4ed..0000000000 --- a/crates/cli/tests/fixtures/packages/platform/host.zig +++ /dev/null @@ -1,119 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const str = @import("glue").str; -const RocStr = str.RocStr; -const testing = std.testing; -const expectEqual = testing.expectEqual; -const expect = testing.expect; - -const mem = std.mem; -const Allocator = mem.Allocator; - -extern fn roc__mainForHost_1_exposed_generic(*RocStr) void; - -const Align = 2 * @alignOf(usize); -extern fn malloc(size: usize) callconv(.C) ?*align(Align) anyopaque; -extern fn realloc(c_ptr: [*]align(Align) u8, size: usize) callconv(.C) ?*anyopaque; -extern fn free(c_ptr: [*]align(Align) u8) callconv(.C) void; -extern fn memcpy(dst: [*]u8, src: [*]u8, size: usize) callconv(.C) void; -extern fn memset(dst: [*]u8, value: i32, size: usize) callconv(.C) void; - -export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*anyopaque { - _ = alignment; - return malloc(size); -} - -export fn roc_realloc(c_ptr: *anyopaque, new_size: usize, old_size: usize, alignment: u32) callconv(.C) ?*anyopaque { - _ = old_size; - _ = alignment; - return realloc(@as([*]align(Align) u8, @alignCast(@ptrCast(c_ptr))), new_size); -} - -export fn roc_dealloc(c_ptr: *anyopaque, alignment: u32) callconv(.C) void { - _ = alignment; - free(@as([*]align(Align) u8, @alignCast(@ptrCast(c_ptr)))); -} - -export fn roc_memset(dst: [*]u8, value: i32, size: usize) callconv(.C) void { - return memset(dst, value, size); -} - -export fn roc_panic(msg: *RocStr, tag_id: u32) callconv(.C) void { - const stderr = std.io.getStdErr().writer(); - switch (tag_id) { - 0 => { - stderr.print("Roc standard library crashed with message\n\n {s}\n\nShutting down\n", .{msg.asSlice()}) catch unreachable; - }, - 1 => { - stderr.print("Application crashed with message\n\n {s}\n\nShutting down\n", .{msg.asSlice()}) catch unreachable; - }, - else => unreachable, - } - std.process.exit(1); -} - -export fn roc_dbg(loc: *RocStr, msg: *RocStr, src: *RocStr) callconv(.C) void { - const stderr = std.io.getStdErr().writer(); - stderr.print("[{s}] {s} = {s}\n", .{ loc.asSlice(), src.asSlice(), msg.asSlice() }) catch unreachable; -} - -extern fn kill(pid: c_int, sig: c_int) c_int; -extern fn shm_open(name: *const i8, oflag: c_int, mode: c_uint) c_int; -extern fn mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) *anyopaque; -extern fn getppid() c_int; - -fn roc_getppid() callconv(.C) c_int { - return getppid(); -} - -fn roc_getppid_windows_stub() callconv(.C) c_int { - return 0; -} - -fn roc_shm_open(name: *const i8, oflag: c_int, mode: c_uint) callconv(.C) c_int { - return shm_open(name, oflag, mode); -} -fn roc_mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) callconv(.C) *anyopaque { - return mmap(addr, length, prot, flags, fd, offset); -} - -comptime { - if (builtin.os.tag == .macos or builtin.os.tag == .linux) { - @export(roc_getppid, .{ .name = "roc_getppid", .linkage = .Strong }); - @export(roc_mmap, .{ .name = "roc_mmap", .linkage = .Strong }); - @export(roc_shm_open, .{ .name = "roc_shm_open", .linkage = .Strong }); - } - - if (builtin.os.tag == .windows) { - @export(roc_getppid_windows_stub, .{ .name = "roc_getppid", .linkage = .Strong }); - } -} - -const Unit = extern struct {}; - -pub export fn main() i32 { - const stdout = std.io.getStdOut().writer(); - const stderr = std.io.getStdErr().writer(); - - var timer = std.time.Timer.start() catch unreachable; - - // actually call roc to populate the callresult - var callresult = RocStr.empty(); - roc__mainForHost_1_exposed_generic(&callresult); - - const nanos = timer.read(); - const seconds = (@as(f64, @floatFromInt(nanos)) / 1_000_000_000.0); - - // stdout the result - stdout.print("{s}\n", .{callresult.asSlice()}) catch unreachable; - - callresult.decref(); - - stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable; - - return 0; -} - -fn to_seconds(tms: std.os.timespec) f64 { - return @as(f64, @floatFromInt(tms.tv_sec)) + (@as(f64, @floatFromInt(tms.tv_nsec)) / 1_000_000_000.0); -} diff --git a/crates/cli/tests/fixtures/packages/platform/main.roc b/crates/cli/tests/fixtures/packages/platform/main.roc deleted file mode 100644 index edc3368f93..0000000000 --- a/crates/cli/tests/fixtures/packages/platform/main.roc +++ /dev/null @@ -1,9 +0,0 @@ -platform "multi-module" - requires {}{ main : Str } - exposes [] - packages {} - imports [] - provides [mainForHost] - -mainForHost : Str -mainForHost = main