WIP upgrade cli test packages fixture tests

This commit is contained in:
Luke Boswell 2024-08-16 12:10:22 +10:00
parent 0767115414
commit 804cb6e067
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
14 changed files with 71 additions and 310 deletions

View file

@ -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)]

View file

@ -1,4 +1,6 @@
interface Dep1 exposes [str1] imports [Dep2]
module [str1]
import Dep2
str1 : Str
str1 = Dep2.str2

View file

@ -1,4 +1,4 @@
interface Dep2 exposes [str2] imports []
module [str2]
str2 : Str
str2 = "I am Dep2.str2"

View file

@ -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

View file

@ -1,4 +1,6 @@
interface Dep1 exposes [value1] imports [Dep2]
module [value1]
import Dep2
value1 : {} -> Str
value1 = \_ -> Dep2.value2 {}

View file

@ -1,4 +1,4 @@
interface Dep2 exposes [value2] imports []
module [value2]
value2 : {} -> Str
value2 = \_ -> "I am Dep2.value2"

View file

@ -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 {}

View file

@ -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);
}

View file

@ -1,9 +0,0 @@
platform "multi-dep-thunk"
requires {}{ main : Str }
exposes []
packages {}
imports []
provides [mainForHost]
mainForHost : Str
mainForHost = main

View file

@ -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)"

View file

@ -1,6 +1,4 @@
interface Csv
exposes [example]
imports []
module [example]
example : Str
example = "This text came from a CSV package!"
example = "This text came from a CSV package!"

View file

@ -1,6 +1,4 @@
interface JsonParser
exposes [example]
imports []
module [example]
example : Str
example = "This text came from a package!"
example = "This text came from a package!"

View file

@ -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);
}

View file

@ -1,9 +0,0 @@
platform "multi-module"
requires {}{ main : Str }
exposes []
packages {}
imports []
provides [mainForHost]
mainForHost : Str
mainForHost = main