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
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
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)"
}
12 changes: 6 additions & 6 deletions compiler/test/suites/arrays.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe("arrays", ({test, testSkip}) => {
let assertParse = makeParseRunner(test);
let assertWarning = makeWarningRunner(test);

assertRun("array1", "print([> 1, 2, 3])", "[> 1, 2, 3]\n");
assertRun("array2", "print([>])", "[> ]\n");
assertRun("array1", "print([> 1, 2, 3])", "[>1, 2, 3]\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 Expand Up @@ -71,22 +71,22 @@ describe("arrays", ({test, testSkip}) => {
assertRun(
"array_set",
"let x = [> 1, 2, 3]; x[0] = 4; print(x)",
"[> 4, 2, 3]\n",
"[>4, 2, 3]\n",
);
assertRun(
"array_set2",
"let x = [> 1, 2, 3]; x[-2] = 4; print(x)",
"[> 1, 4, 3]\n",
"[>1, 4, 3]\n",
);
assertRun(
"array_set3",
"let x = [> 1, 2, 3]; x[0] += 1; print(x)",
"[> 2, 2, 3]\n",
"[>2, 2, 3]\n",
);
assertRun(
"array_set4",
"let x = [> 1, 2, 3]; let mut c = 0; let getC = () => {c += 1; c}; x[getC()] += 1; print(x)",
"[> 1, 3, 3]\n",
"[>1, 3, 3]\n",
);
assertCompileError(
"array_set_err",
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,
);
});
86 changes: 5 additions & 81 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 All @@ -160,6 +84,6 @@ describe("cyclic references", ({test, testSkip}) => {
a[0] = Some(b)
print(a)
|},
"<1> [> Some(Rec(<cycle to <1>>))]\n",
"<1> [>Some(Rec(<cycle to <1>>))]\n",
);
});
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
2 changes: 1 addition & 1 deletion compiler/test/suites/modules.re
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe("modules", ({test, testSkip}) => {
assertFileRun(
"nested_and_reprovided_modules",
"nestedModules",
"hello from foo\nhello from bar\n[2, 3, 4]\n9\n[> 2, 3, 4]\nfalse\nfoo\n",
"hello from foo\nhello from bar\n[2, 3, 4]\n9\n[>2, 3, 4]\nfalse\nfoo\n",
);
assertSnapshot(
"reprovided_module",
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
3 changes: 3 additions & 0 deletions compiler/test/suites/runtime.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ describe("runtime", ({test, testSkip}) => {
assertRuntime("unsafe/wasmi32.test");
assertRuntime("unsafe/wasmi64.test");
assertRuntime("unsafe/wasmref.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
Loading
Loading