Skip to content
Open
2 changes: 1 addition & 1 deletion compiler/test/input/memoryBase/asserts.gr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let doTest = () => {
use WasmI32.{ (==), (>), (<) }
assert typeMetadata() == 0x110008n
assert heapStart() > 0x110008n
assert heapStart() < 0x110308n
assert heapStart() < 0x110808n
}

doTest()
3 changes: 2 additions & 1 deletion compiler/test/runner.re
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,12 @@ let makeStdlibRunner = (test, ~code=0, name) => {
});
};

let makeRuntimeRunner = (test, ~code=0, name) => {
let makeRuntimeRunner = (test, ~code=0, ~elide_type_info=false, name) => {
test(name, ({expect}) => {
Config.preserve_all_configs(() => {
// Run stdlib suites in release mode
Config.profile := Some(Release);
Config.elide_type_info := elide_type_info;
let infile = runtimefile(name);
let outfile = wasmfile(name);
ignore @@ compile_file(~link=true, infile, outfile);
Expand Down
17 changes: 17 additions & 0 deletions compiler/test/runtime/doc.test.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module DocTest

from "runtime/doc" include Doc

// Regression test of engine mode behavior
let makeTestTree = kind => {
use Doc.Builder.{ (++) }
Doc.Builder.group(
Doc.Builder.string("a")
++ Doc.Builder.breakableSpace
++ Doc.Builder.string("b"),
kind=kind
)
}
assert Doc.Engine.toString(Doc.LF, 80, makeTestTree(Doc.Auto)) == "a b"
assert Doc.Engine.toString(Doc.LF, 80, makeTestTree(Doc.FitGroups)) == "a b"
assert Doc.Engine.toString(Doc.LF, 80, makeTestTree(Doc.FitAll)) == "a b"
412 changes: 412 additions & 0 deletions compiler/test/runtime/toString.test.gr

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions compiler/test/runtime/toStringNoTypeInfo.test.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module ToStringNoTypeInfoTest

from "runtime/toString" include ToString
use ToString.{ toString }

record Record_ {
value: Number,
}
assert toString({ value: 1, }) == "{ <unknown field>: 1, }"
enum Enum {
Empty,
Tuple(Number),
Record{ value: Number, },
}
assert toString(Empty) == "<unknown variant>"
assert toString(Tuple(1)) == "<unknown variant>(1)"
// NOTE: Records are printed as tuples when type info is elided
assert toString(Record{ value: 1 }) == "<unknown variant>(1)"

// Builtins
module Builtins {
// List
assert toString([1, 2, 3]) == "[1, 2, 3]"
// Range
assert toString({ rangeStart: 1, rangeEnd: 2 })
== "{ rangeStart: 1, rangeEnd: 2 }"
// Option
assert toString(None) == "None"
assert toString(Some(1)) == "Some(1)"
// Result
assert toString(Ok(1)) == "Ok(1)"
assert toString(Err(2)) == "Err(2)"
// Box
assert toString(box(1)) == "box(1)"
}
2 changes: 1 addition & 1 deletion compiler/test/suites/arrays.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("arrays", ({test, testSkip}) => {
let assertWarning = makeWarningRunner(test);

assertRun("array1", "print([> 1, 2, 3])", "[> 1, 2, 3]\n");
assertRun("array2", "print([>])", "[> ]\n");
assertRun("array2", "print([>])", "[>]\n");
assertSnapshot("array3", "[>\n1, 2, 3]");
assertCompileError("array_error", "[> 1, false, 2]", "has type Bool but");
assertSnapshot("array_access", "let x = [> 1, 2, 3]; x[0]");
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/suites/basic_functionality.re
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,6 @@ describe("basic functionality", ({test, testSkip}) => {
~config_fn=smallestFileConfig,
"smallest_grain_program",
"",
329,
410,
);
});
84 changes: 4 additions & 80 deletions compiler/test/suites/cycles.re
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("cyclic references", ({test, testSkip}) => {
x.a = Some(x)
print(x)
|},
"<1> {\n a: Some(<cycle to <1>>)\n}\n",
"<1> { a: Some(<cycle to <1>>), }\n",
);
assertRun(
"cycles2",
Expand All @@ -36,7 +36,7 @@ describe("cyclic references", ({test, testSkip}) => {

print([x, y])
|},
"[<1> {\n val: 1,\n a: Some({\n val: 2,\n a: Some(<cycle to <1>>)\n })\n}, <2> {\n val: 2,\n a: Some(<1> {\n val: 1,\n a: Some(<cycle to <2>>)\n })\n}]\n",
"[\n <1> { val: 1, a: Some({ val: 2, a: Some(<cycle to <1>>) }) },\n <2> { val: 2, a: Some(<1> { val: 1, a: Some(<cycle to <2>>) }) },\n]\n",
);
assertRun(
"cycles3",
Expand All @@ -55,83 +55,7 @@ describe("cyclic references", ({test, testSkip}) => {
a.next = e
print([aOpt, b, c, d, e])
|},
{|[Some(<1> {
val: 1,
next: Some({
val: 5,
next: Some({
val: 4,
next: Some({
val: 3,
next: Some({
val: 2,
next: Some(<cycle to <1>>)
})
})
})
})
}), Some(<2> {
val: 2,
next: Some(<1> {
val: 1,
next: Some({
val: 5,
next: Some({
val: 4,
next: Some({
val: 3,
next: Some(<cycle to <2>>)
})
})
})
})
}), Some(<3> {
val: 3,
next: Some(<2> {
val: 2,
next: Some(<1> {
val: 1,
next: Some({
val: 5,
next: Some({
val: 4,
next: Some(<cycle to <3>>)
})
})
})
})
}), Some(<4> {
val: 4,
next: Some(<3> {
val: 3,
next: Some(<2> {
val: 2,
next: Some(<1> {
val: 1,
next: Some({
val: 5,
next: Some(<cycle to <4>>)
})
})
})
})
}), Some(<5> {
val: 5,
next: Some(<4> {
val: 4,
next: Some(<3> {
val: 3,
next: Some(<2> {
val: 2,
next: Some(<1> {
val: 1,
next: Some(<cycle to <5>>)
})
})
})
})
})]
|},
"[\n <1> Some(\n { \n val: 1,\n next: Some(\n { \n val: 5,\n next: Some(\n { \n val: 4,\n next: Some(\n { val: 3, next: Some({ val: 2, next: <cycle to <1>> }) },\n ),\n },\n ),\n },\n ),\n },\n ),\n <2> Some(\n { \n val: 2,\n next: <1> Some(\n { \n val: 1,\n next: Some(\n { \n val: 5,\n next: Some(\n { val: 4, next: Some({ val: 3, next: <cycle to <2>> }) },\n ),\n },\n ),\n },\n ),\n },\n ),\n <3> Some(\n { \n val: 3,\n next: <2> Some(\n { \n val: 2,\n next: <1> Some(\n { \n val: 1,\n next: Some(\n { val: 5, next: Some({ val: 4, next: <cycle to <3>> }) },\n ),\n },\n ),\n },\n ),\n },\n ),\n <4> Some(\n { \n val: 4,\n next: <3> Some(\n { \n val: 3,\n next: <2> Some(\n { \n val: 2,\n next: <1> Some(\n { val: 1, next: Some({ val: 5, next: <cycle to <4>> }) },\n ),\n },\n ),\n },\n ),\n },\n ),\n <5> Some(\n { \n val: 5,\n next: <4> Some(\n { \n val: 4,\n next: <3> Some(\n { \n val: 3,\n next: <2> Some(\n { val: 2, next: <1> Some({ val: 1, next: <cycle to <5>> }) },\n ),\n },\n ),\n },\n ),\n },\n ),\n]\n",
);
assertRun(
"cycles4",
Expand All @@ -146,7 +70,7 @@ describe("cyclic references", ({test, testSkip}) => {
print(a)
print(unbox(a))
|},
"<1> box(Some(Rec(<cycle to <1>>)))\nSome(Rec(<1> box(Some(Rec(<cycle to <1>>)))))\n",
"<1> box(Some(Rec(<cycle to <1>>)))\n<1> Some(Rec(box(<cycle to <1>>)))\n",
);
assertRun(
"cycles5",
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/suites/enums.re
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("enums", ({test, testSkip}) => {
print(r == Rec{ x: 2, y: 2 })
print(Tup(1, 2, 3))
|},
"Rec{\n x: 1,\n y: 2\n}\nRec{\n x: 11,\n y: 12\n}\ntrue\nfalse\nTup(1, 2, 3)\n",
"Rec{ x: 1, y: 2 }\nRec{ x: 11, y: 12 }\ntrue\nfalse\nTup(1, 2, 3)\n",
);
assertCompileError(
"enum_inline_record_2",
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("enums", ({test, testSkip}) => {
let b = Rec{ x }
print(b)
|},
"Rec{\n x: 1\n}\n",
"Rec{ x: 1, }\n",
);
assertRun(
"deeply_nested_enum",
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/suites/exceptions.re
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("exceptions", ({test, testSkip}) => {
assertRun(
"record_exception_1",
{|exception Foo { msg: String, bar: Number }; print(Foo{msg: "Oops", bar: 1})|},
"Foo{\n msg: \"Oops\",\n bar: 1\n}\n",
"Foo{ msg: \"Oops\", bar: 1 }\n",
);
assertRunError(
"record_exception_2",
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/suites/includes.re
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ describe("includes", ({test, testSkip}) => {
assertRun(
"reprovide_type2",
"from \"reprovideContents\" include ReprovideContents; use ReprovideContents.{ type OtherT as TT, val }; print(val); print({ x: 2 })",
"{\n x: 1\n}\n{\n x: 2\n}\n",
"{ x: 1, }\n{ x: 2, }\n",
);
assertRun(
"reprovide_type3",
"from \"reprovideContents\" include ReprovideContents; use ReprovideContents.{ type OtherT as Other }; print({ x: 1 }: Other)",
"{\n x: 1\n}\n",
"{ x: 1, }\n",
);
/* Duplicate imports */
test("dedupe_includes", ({expect}) => {
Expand Down
8 changes: 4 additions & 4 deletions compiler/test/suites/print.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ describe("print", ({test, testSkip}) => {
~config_fn=() => {Grain_utils.Config.elide_type_info := true},
"elided_type_info_1",
"enum Foo { Foo }; print(Foo)",
"<enum value>\n",
"<unknown variant>\n",
);
assertRun(
~config_fn=() => {Grain_utils.Config.elide_type_info := true},
"elided_type_info_2",
"record Foo { foo: String }; print({ foo: \"foo\" })",
"<record value>\n",
"{ <unknown field>: \"foo\", }\n",
);
assertRun(
"print_int64_large",
Expand All @@ -32,12 +32,12 @@ describe("print", ({test, testSkip}) => {
assertRun(
"print_nested_records",
"record Foo { foo: Number }; record Bar { bar: Foo }; print({ bar: { foo: 1 } })",
"{\n bar: {\n foo: 1\n }\n}\n",
"{ bar: { foo: 1, }, }\n",
);
assertRun(
"print_nested_records_multiple",
"record Foo { foo: Number }; record Bar { bar: Foo }; print({ bar: { foo: 1 } }); print({ bar: { foo: 1 } }); print({ bar: { foo: 1 } })",
"{\n bar: {\n foo: 1\n }\n}\n{\n bar: {\n foo: 1\n }\n}\n{\n bar: {\n foo: 1\n }\n}\n",
"{ bar: { foo: 1, }, }\n{ bar: { foo: 1, }, }\n{ bar: { foo: 1, }, }\n",
);
assertRun(
"print_issue892_1",
Expand Down
10 changes: 5 additions & 5 deletions compiler/test/suites/records.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ describe("records", ({test, testSkip}) => {
assertRun(
"record_1",
"record Rec {foo: Number}; print({foo: 4})",
"{\n foo: 4\n}\n",
"{ foo: 4, }\n",
);
assertRun(
"record_2",
"provide record Rec {foo: Number}; print({foo: 4})",
"{\n foo: 4\n}\n",
"{ foo: 4, }\n",
);
assertRun(
"record_multiple",
"provide record Rec {foo: Number, bar: String, baz: Bool}; print({foo: 4, bar: \"boo\", baz: true})",
"{\n foo: 4,\n bar: \"boo\",\n baz: true\n}\n",
"{ foo: 4, bar: \"boo\", baz: true }\n",
);
assertSnapshot(
"record_pun",
Expand Down Expand Up @@ -188,13 +188,13 @@ describe("records", ({test, testSkip}) => {
provide enum Bar { Baz(Foo<Number>) }
print(Baz({ bar: 1 }))
|},
"Baz({\n bar: 1\n})\n",
"Baz({ bar: 1, })\n",
);
// record spread
assertRun(
"record_spread_1",
"record Rec {foo: Number, bar: Number, mut baz: Number}; let a = {foo: 1, bar: 2, baz: 3}; let b = {...a, bar: 3}; b.baz = 5; print(b); print(a)",
"{\n foo: 1,\n bar: 3,\n baz: 5\n}\n{\n foo: 1,\n bar: 2,\n baz: 3\n}\n",
"{ foo: 1, bar: 3, baz: 5 }\n{ foo: 1, bar: 2, baz: 3 }\n",
);
assertSnapshot(
"record_spread_2",
Expand Down
4 changes: 4 additions & 0 deletions compiler/test/suites/runtime.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ describe("runtime", ({test, testSkip}) => {
assertRuntime("unsafe/wasmi32.test");
assertRuntime("unsafe/wasmi64.test");
assertRuntime("unsafe/wasmref.test");

assertRuntime("doc.test");
assertRuntime("toString.test");
assertRuntime(~elide_type_info=true, "toStringNoTypeInfo.test");
});
4 changes: 2 additions & 2 deletions compiler/test/suites/strings.re
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ bar", 1))|},
);
assertRun(
"bytes_literal_long",
{|print(b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefg")|},
{|print(b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgh")|},
"<bytes: 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 61 62 63 64 65 66...>\n",
);
assertCompileError(
Expand All @@ -413,6 +413,6 @@ bar", 1))|},
assertRun(
"range_printing",
{|print({ rangeStart: 1, rangeEnd: 2 })|},
"{\n rangeStart: 1,\n rangeEnd: 2\n}\n",
"{ rangeStart: 1, rangeEnd: 2 }\n",
);
});
2 changes: 1 addition & 1 deletion compiler/test/suites/types.re
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ describe("recursive types", ({test, testSkip}) => {
type T = T
print({ x: 1 }: T)
|},
"{\n x: 1\n}\n",
"{ x: 1, }\n",
);
});

Expand Down
10 changes: 5 additions & 5 deletions compiler/test/suites/wasi_args.re
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ describe("wasi args and env", ({test, testSkip}) => {
~extra_args=[|"--", "a", "b"|],
"print_args1",
print_wasi_info,
"[> \"a\", \"b\"]\n[> ]\n",
"[> \"a\", \"b\"]\n[>]\n",
);
assertRun(
~extra_args=[|"a", "b"|],
"print_args2",
print_wasi_info,
"[> ]\n[> ]\n",
"[>]\n[>]\n",
);
assertRun(
~extra_args=[|"--env=FOO=bar", "a", "b"|],
"print_args3",
print_wasi_info,
"[> ]\n[> \"FOO=bar\"]\n",
"[>]\n[> \"FOO=bar\"]\n",
);
assertRun(
~extra_args=[|"--env", "FOO=bar", "BAR=baz", "BAZ"|],
"print_args4",
print_wasi_info,
"[> ]\n[> \"FOO=bar\", \"BAR=baz\", \"BAZ=\"]\n",
"[>]\n[> \"FOO=bar\", \"BAR=baz\", \"BAZ=\"]\n",
);
assertRun(
~extra_args=[|"--env", "FOO=bar", "--", "a", "b"|],
Expand All @@ -56,6 +56,6 @@ describe("wasi args and env", ({test, testSkip}) => {
~extra_args=[|"--", "a", "b", "--env", "FOO=bar"|],
"print_args6",
print_wasi_info,
"[> \"a\", \"b\", \"--env\", \"FOO=bar\"]\n[> ]\n",
"[> \"a\", \"b\", \"--env\", \"FOO=bar\"]\n[>]\n",
);
});
Loading
Loading