Remove source-level `void` uses from tests
f08c3877343d0aee66240a5b013ce5719e3bfc774c49b94a8758bbd66eb04e21
1 parent
d5d7f927
lib/std/lang/parser/tests.rad
+23 -24
| 173 | 173 | try testing::expect(sign == expectedSign); |
|
| 174 | 174 | } |
|
| 175 | 175 | ||
| 176 | 176 | /// Extract a union variant and verify its name and index. |
|
| 177 | 177 | /// Returns the payload's fields slice for further checking with `expectField`. |
|
| 178 | - | fn expectVariant(varNode: *ast::Node, name: *[u8], index: u32) -> *mut [*ast::Node] |
|
| 178 | + | fn expectVariant(varNode: *ast::Node, name: *[u8], index: u32) -> ?*mut [*ast::Node] |
|
| 179 | 179 | throws (testing::TestError) |
|
| 180 | 180 | { |
|
| 181 | 181 | let case ast::NodeValue::UnionDeclVariant(v) = varNode.value |
|
| 182 | 182 | else throw testing::TestError::Failed; |
|
| 183 | 183 | try expectIdent(v.name, name); |
|
| 184 | 184 | try testing::expect(v.index == index); |
|
| 185 | 185 | try testing::expect(v.value == nil); |
|
| 186 | 186 | ||
| 187 | - | let payloadType = v.type else throw testing::TestError::Failed; |
|
| 187 | + | let payloadType = v.type else return nil; |
|
| 188 | 188 | let case ast::NodeValue::TypeSig(sig) = payloadType.value |
|
| 189 | 189 | else throw testing::TestError::Failed; |
|
| 190 | 190 | let case ast::TypeSig::Record { fields, .. } = sig |
|
| 191 | 191 | else throw testing::TestError::Failed; |
|
| 192 | 192 |
| 887 | 887 | try expectNumber(length, "4"); |
|
| 888 | 888 | } |
|
| 889 | 889 | ||
| 890 | 890 | /// Test parsing a named record declaration without derives. |
|
| 891 | 891 | @test fn testParseRecordDecl() throws (testing::TestError) { |
|
| 892 | - | let node = try! parseStmtStr("record R { x: void, y: bool }"); |
|
| 892 | + | let node = try! parseStmtStr("record R { x: bool, y: i32 }"); |
|
| 893 | 893 | let case ast::NodeValue::RecordDecl(decl) = node.value |
|
| 894 | 894 | else throw testing::TestError::Failed; |
|
| 895 | 895 | ||
| 896 | 896 | try expectIdent(decl.name, "R"); |
|
| 897 | 897 | try testing::expect(decl.derives.len == 0); |
|
| 898 | 898 | try testing::expect(decl.fields.len == 2); |
|
| 899 | 899 | ||
| 900 | - | try expectFieldSig(decl.fields, 0, "x", ast::TypeSig::Void); |
|
| 901 | - | try expectFieldSig(decl.fields, 1, "y", ast::TypeSig::Bool); |
|
| 900 | + | try expectFieldSig(decl.fields, 0, "x", ast::TypeSig::Bool); |
|
| 901 | + | try expectFieldSig(decl.fields, 1, "y", ast::TypeSig::Integer { |
|
| 902 | + | width: 4, |
|
| 903 | + | sign: ast::Signedness::Signed, |
|
| 904 | + | }); |
|
| 902 | 905 | } |
|
| 903 | 906 | ||
| 904 | 907 | /// Test parsing a record declaration with derives. |
|
| 905 | 908 | @test fn testParseRecordDeclDerives() throws (testing::TestError) { |
|
| 906 | 909 | let node = try! parseStmtStr("record R: Eq + Debug { field: i32 }"); |
| 940 | 943 | try testing::expect(flagValue); |
|
| 941 | 944 | } |
|
| 942 | 945 | ||
| 943 | 946 | /// Test parsing an unlabeled record declaration. |
|
| 944 | 947 | @test fn testParseTupleRecordDecl() throws (testing::TestError) { |
|
| 945 | - | let node = try! parseStmtStr("record Pair(void, bool);"); |
|
| 948 | + | let node = try! parseStmtStr("record Pair(bool, i32);"); |
|
| 946 | 949 | let case ast::NodeValue::RecordDecl(decl) = node.value |
|
| 947 | 950 | else throw testing::TestError::Failed; |
|
| 948 | 951 | ||
| 949 | 952 | try expectIdent(decl.name, "Pair"); |
|
| 950 | 953 | try testing::expect(not decl.labeled); |
|
| 951 | 954 | try testing::expect(decl.derives.len == 0); |
|
| 952 | 955 | try testing::expect(decl.fields.len == 2); |
|
| 953 | 956 | ||
| 954 | - | try expectFieldSig(decl.fields, 0, nil, ast::TypeSig::Void); |
|
| 955 | - | try expectFieldSig(decl.fields, 1, nil, ast::TypeSig::Bool); |
|
| 957 | + | try expectFieldSig(decl.fields, 0, nil, ast::TypeSig::Bool); |
|
| 958 | + | try expectFieldSig(decl.fields, 1, nil, ast::TypeSig::Integer { |
|
| 959 | + | width: 4, |
|
| 960 | + | sign: ast::Signedness::Signed, |
|
| 961 | + | }); |
|
| 956 | 962 | } |
|
| 957 | 963 | ||
| 958 | 964 | /// Test parsing a single-field unlabeled record. |
|
| 959 | 965 | @test fn testParseTupleRecordSingleField() throws (testing::TestError) { |
|
| 960 | 966 | let node = try! parseStmtStr("record R(bool);"); |
| 1083 | 1089 | } |
|
| 1084 | 1090 | } |
|
| 1085 | 1091 | ||
| 1086 | 1092 | /// Test parsing a function declaration with a throws clause. |
|
| 1087 | 1093 | @test fn testParseFnDeclThrows() throws (testing::TestError) { |
|
| 1088 | - | let node = try! parseStmtStr("fn handle() -> void throws (Error, Crash) {}"); |
|
| 1094 | + | let node = try! parseStmtStr("fn handle() throws (Error, Crash) {}"); |
|
| 1089 | 1095 | let case ast::NodeValue::FnDecl(decl) = node.value |
|
| 1090 | 1096 | else throw testing::TestError::Failed; |
|
| 1091 | 1097 | ||
| 1092 | 1098 | try expectIdent(decl.name, "handle"); |
|
| 1093 | - | ||
| 1094 | - | let returnType = decl.sig.returnType |
|
| 1095 | - | else throw testing::TestError::Failed; |
|
| 1096 | - | try expectType(returnType, ast::TypeSig::Void); |
|
| 1099 | + | try testing::expect(decl.sig.returnType == nil); |
|
| 1097 | 1100 | ||
| 1098 | 1101 | try testing::expect(decl.sig.throwList.len == 2); |
|
| 1099 | 1102 | try expectTypeIdent(decl.sig.throwList[0], "Error"); |
|
| 1100 | 1103 | try expectTypeIdent(decl.sig.throwList[1], "Crash"); |
|
| 1101 | 1104 |
| 1148 | 1151 | @test fn testParseTypeBool() throws (testing::TestError) { |
|
| 1149 | 1152 | let node = try! parseTypeStr("bool"); |
|
| 1150 | 1153 | try expectType(node, ast::TypeSig::Bool); |
|
| 1151 | 1154 | } |
|
| 1152 | 1155 | ||
| 1153 | - | /// Test parsing the `void` type. |
|
| 1154 | - | @test fn testParseTypeVoid() throws (testing::TestError) { |
|
| 1155 | - | let node = try! parseTypeStr("void"); |
|
| 1156 | - | try expectType(node, ast::TypeSig::Void); |
|
| 1157 | - | } |
|
| 1158 | 1156 | ||
| 1159 | 1157 | /// Test parsing an unsigned integer type. |
|
| 1160 | 1158 | @test fn testParseTypeUnsigned() throws (testing::TestError) { |
|
| 1161 | 1159 | let node = try! parseTypeStr("u8"); |
|
| 1162 | 1160 | try expectType(node, ast::TypeSig::Integer { |
| 2470 | 2468 | try expectIdent(var2.name, "Pending"); |
|
| 2471 | 2469 | try testing::expect(var2.index == 2); |
|
| 2472 | 2470 | try testing::expect(var2.value != nil); |
|
| 2473 | 2471 | } |
|
| 2474 | 2472 | ||
| 2475 | - | /// Test parsing a union with payload types. |
|
| 2473 | + | /// Test parsing a union with payload and tag-only variants. |
|
| 2476 | 2474 | @test fn testParseEnumWithPayloads() throws (testing::TestError) { |
|
| 2477 | - | let node = try! parseStmtStr("union Result { Ok(bool), Error(void) }"); |
|
| 2475 | + | let node = try! parseStmtStr("union Result { Ok(bool), Error }"); |
|
| 2478 | 2476 | let case ast::NodeValue::UnionDecl(decl) = node.value |
|
| 2479 | 2477 | else throw testing::TestError::Failed; |
|
| 2480 | 2478 | ||
| 2481 | 2479 | try expectIdent(decl.name, "Result"); |
|
| 2482 | 2480 | try testing::expect(decl.variants.len == 2); |
|
| 2483 | 2481 | ||
| 2484 | - | let okFields = try expectVariant(decl.variants[0], "Ok", 0); |
|
| 2482 | + | let okFields = try expectVariant(decl.variants[0], "Ok", 0) |
|
| 2483 | + | else throw testing::TestError::Failed; |
|
| 2485 | 2484 | try testing::expect(okFields.len == 1); |
|
| 2486 | 2485 | try expectFieldSig(okFields, 0, nil, ast::TypeSig::Bool); |
|
| 2487 | 2486 | ||
| 2488 | 2487 | let errFields = try expectVariant(decl.variants[1], "Error", 1); |
|
| 2489 | - | try testing::expect(errFields.len == 1); |
|
| 2490 | - | try expectFieldSig(errFields, 0, nil, ast::TypeSig::Void); |
|
| 2488 | + | try testing::expect(errFields == nil); |
|
| 2491 | 2489 | } |
|
| 2492 | 2490 | ||
| 2493 | 2491 | /// Test parsing a union with derives. |
|
| 2494 | 2492 | @test fn testParseEnumWithDerives() throws (testing::TestError) { |
|
| 2495 | 2493 | let node = try! parseStmtStr("union Option: Debug + Eq { None, Some(i32) }"); |
| 2744 | 2742 | let arrNode = try! parseExprStr("[1, 2, 3,]"); |
|
| 2745 | 2743 | let case ast::NodeValue::ArrayLit(items) = arrNode.value else throw testing::TestError::Failed; |
|
| 2746 | 2744 | try testing::expect(items.len == 3); |
|
| 2747 | 2745 | ||
| 2748 | 2746 | // Function type parameters. |
|
| 2749 | - | let fnType = try! parseTypeStr("fn (i32, bool,) -> void"); |
|
| 2747 | + | let fnType = try! parseTypeStr("fn (i32, bool,)"); |
|
| 2750 | 2748 | let case ast::NodeValue::TypeSig(sigValue) = fnType.value else throw testing::TestError::Failed; |
|
| 2751 | 2749 | let case ast::TypeSig::Fn(sig) = sigValue else throw testing::TestError::Failed; |
|
| 2752 | 2750 | try testing::expect(sig.params.len == 2); |
|
| 2751 | + | try testing::expect(sig.returnType == nil); |
|
| 2753 | 2752 | ||
| 2754 | 2753 | // Throws lists. |
|
| 2755 | 2754 | let throwsNode = try! parseStmtStr("fn handle() throws (Error, Other,) {}"); |
|
| 2756 | 2755 | let case ast::NodeValue::FnDecl(throwsDecl) = throwsNode.value else throw testing::TestError::Failed; |
|
| 2757 | 2756 | try testing::expect(throwsDecl.sig.throwList.len == 2); |
lib/std/lang/resolver/tests.rad
+0 -7
| 2870 | 2870 | try resolveAndExpectConstExpr("@sizeOf(u8)", 1); |
|
| 2871 | 2871 | try resolveAndExpectConstExpr("@sizeOf(u16)", 2); |
|
| 2872 | 2872 | try resolveAndExpectConstExpr("@sizeOf(u32)", 4); |
|
| 2873 | 2873 | try resolveAndExpectConstExpr("@sizeOf(i32)", 4); |
|
| 2874 | 2874 | try resolveAndExpectConstExpr("@sizeOf(bool)", 1); |
|
| 2875 | - | try resolveAndExpectConstExpr("@sizeOf(void)", 0); |
|
| 2876 | 2875 | try resolveAndExpectConstExpr("@sizeOf(*u32)", 8); |
|
| 2877 | 2876 | try resolveAndExpectConstExpr("@sizeOf([u8; 10])", 10); |
|
| 2878 | 2877 | try resolveAndExpectConstExpr("@sizeOf(*[u32])", 16); |
|
| 2879 | 2878 | try resolveAndExpectConstExpr("@sizeOf(?u8)", 2); |
|
| 2880 | 2879 | try resolveAndExpectConstExpr("@sizeOf(?u16)", 4); |
| 2898 | 2897 | try resolveAndExpectConstExpr("@alignOf(u8)", 1); |
|
| 2899 | 2898 | try resolveAndExpectConstExpr("@alignOf(u16)", 2); |
|
| 2900 | 2899 | try resolveAndExpectConstExpr("@alignOf(u32)", 4); |
|
| 2901 | 2900 | try resolveAndExpectConstExpr("@alignOf(i32)", 4); |
|
| 2902 | 2901 | try resolveAndExpectConstExpr("@alignOf(bool)", 1); |
|
| 2903 | - | try resolveAndExpectConstExpr("@alignOf(void)", 0); |
|
| 2904 | 2902 | try resolveAndExpectConstExpr("@alignOf(*u8)", 8); |
|
| 2905 | 2903 | try resolveAndExpectConstExpr("@alignOf(*u16)", 8); |
|
| 2906 | 2904 | try resolveAndExpectConstExpr("@alignOf(*u32)", 8); |
|
| 2907 | 2905 | try resolveAndExpectConstExpr("@alignOf(*opaque)", 8); |
|
| 2908 | 2906 | try resolveAndExpectConstExpr("@alignOf([u8; 8])", 1); |
| 2980 | 2978 | } { |
|
| 2981 | 2979 | let mut a = testResolver(); |
|
| 2982 | 2980 | let program = "fn voidFn() {} let x = voidFn();"; |
|
| 2983 | 2981 | let result = try resolveProgramStr(&mut a, program); |
|
| 2984 | 2982 | try expectErrorKind(&result, super::ErrorKind::CannotAssignVoid); |
|
| 2985 | - | } { |
|
| 2986 | - | let mut a = testResolver(); |
|
| 2987 | - | let program = "fn voidFn() {} let x: void = voidFn();"; |
|
| 2988 | - | let result = try resolveProgramStr(&mut a, program); |
|
| 2989 | - | try expectErrorKind(&result, super::ErrorKind::CannotAssignVoid); |
|
| 2990 | 2983 | } |
|
| 2991 | 2984 | } |
|
| 2992 | 2985 | ||
| 2993 | 2986 | // |
|
| 2994 | 2987 | // Module Declaration Tests |
lib/std/testing.rad
+3 -3
| 16 | 16 | ||
| 17 | 17 | /// Descriptor for a single test case, holding its module path, name, and entry point. |
|
| 18 | 18 | pub record TestInfo { |
|
| 19 | 19 | module: *[u8], |
|
| 20 | 20 | name: *[u8], |
|
| 21 | - | func: fn() -> void throws (TestError), |
|
| 21 | + | func: fn() throws (TestError), |
|
| 22 | 22 | } |
|
| 23 | 23 | ||
| 24 | 24 | /// Construct a [`TestInfo`]. Used by the compiler's synthetic test harness. |
|
| 25 | - | pub fn test(module: *[u8], name: *[u8], func: fn() -> void throws (TestError)) -> TestInfo { |
|
| 25 | + | pub fn test(module: *[u8], name: *[u8], func: fn() throws (TestError)) -> TestInfo { |
|
| 26 | 26 | return TestInfo { module, name, func }; |
|
| 27 | 27 | } |
|
| 28 | 28 | ||
| 29 | 29 | /// Run all tests and return `0` on success or `1` if any test failed. |
|
| 30 | 30 | pub fn runAllTests(tests: *[TestInfo]) -> i32 { |
| 47 | 47 | ||
| 48 | 48 | fn runTest( |
|
| 49 | 49 | ctx: *mut Ctx, |
|
| 50 | 50 | module: *[u8], |
|
| 51 | 51 | name: *[u8], |
|
| 52 | - | testFn: fn () -> void throws (TestError) |
|
| 52 | + | testFn: fn () throws (TestError) |
|
| 53 | 53 | ) { |
|
| 54 | 54 | io::print("test "); |
|
| 55 | 55 | io::print(module); |
|
| 56 | 56 | io::print("::"); |
|
| 57 | 57 | io::print(name); |
test/tests/builtin.size.align.rad
+0 -2
| 54 | 54 | assert @alignOf(*[u16]) == 8; |
|
| 55 | 55 | ||
| 56 | 56 | assert @sizeOf(*mut [u8]) == 16; |
|
| 57 | 57 | assert @alignOf(*mut [u8]) == 8; |
|
| 58 | 58 | ||
| 59 | - | assert @sizeOf(void) == 0; |
|
| 60 | - | assert @alignOf(void) == 0; |
|
| 61 | 59 | ||
| 62 | 60 | return 0; |
|
| 63 | 61 | } |
test/tests/call.tests.rad
+1 -1
| 24 | 24 | /// Calls nested helpers to build the final result. |
|
| 25 | 25 | fn callNested(x: i32, y: i32) -> i32 { |
|
| 26 | 26 | return add(inc(x), inc(y)); |
|
| 27 | 27 | } |
|
| 28 | 28 | ||
| 29 | - | /// Calls a void function and then returns a constant. |
|
| 29 | + | /// Calls a no-result function and then returns a constant. |
|
| 30 | 30 | fn callVoid() -> i32 { |
|
| 31 | 31 | doNothing(); |
|
| 32 | 32 | return 1; |
|
| 33 | 33 | } |
|
| 34 | 34 |
test/tests/record.ptr.mutate.rad
+1 -1
| 3 | 3 | record Point { |
|
| 4 | 4 | x: i32, |
|
| 5 | 5 | y: i32, |
|
| 6 | 6 | } |
|
| 7 | 7 | ||
| 8 | - | fn mutate(p: *mut Point) -> void { |
|
| 8 | + | fn mutate(p: *mut Point) { |
|
| 9 | 9 | p.x = 4; |
|
| 10 | 10 | p.y = 38; |
|
| 11 | 11 | } |
|
| 12 | 12 | ||
| 13 | 13 | @default fn main() -> i32 { |
test/tests/ref.mut.ptr.rad
+1 -1
| 1 | 1 | //! returns: 84 |
|
| 2 | 2 | //! Test mutable pointer references. |
|
| 3 | 3 | ||
| 4 | - | fn set(ptr: *mut i32) -> void { |
|
| 4 | + | fn set(ptr: *mut i32) { |
|
| 5 | 5 | *ptr = 42; |
|
| 6 | 6 | } |
|
| 7 | 7 | ||
| 8 | 8 | @default fn main() -> i32 { |
|
| 9 | 9 | let mut a: i32 = 0; |
test/tests/result.void.success.rad
+2 -2
| 1 | 1 | //! returns: 0 |
|
| 2 | - | //! Test that Result<void, E> success returns work correctly. |
|
| 2 | + | //! Test that no-result success returns work correctly. |
|
| 3 | 3 | ||
| 4 | 4 | union TestError { |
|
| 5 | 5 | Failed, |
|
| 6 | 6 | } |
|
| 7 | 7 |
| 15 | 15 | ||
| 16 | 16 | @default fn main() -> u32 { |
|
| 17 | 17 | // Place a guard variable on the stack. |
|
| 18 | 18 | let mut guard: u32 = 42; |
|
| 19 | 19 | ||
| 20 | - | // Call function returning Result<void, TestError> with success. |
|
| 20 | + | // Call no-result function with success. |
|
| 21 | 21 | try voidSuccess() catch { |
|
| 22 | 22 | return (1) - 42; |
|
| 23 | 23 | }; |
|
| 24 | 24 | ||
| 25 | 25 | // Guard should still be 42, not clobbered. |
test/tests/union.ctor.rad
+5 -5
| 1 | - | /// Void union. |
|
| 1 | + | /// Union with tag-only variants. |
|
| 2 | 2 | union Color { Red, Green, Blue } |
|
| 3 | 3 | ||
| 4 | - | /// Non-void union with and without payload variants. |
|
| 4 | + | /// Union with and without payload variants. |
|
| 5 | 5 | union MaybeInt { None, Some(i32) } |
|
| 6 | 6 | ||
| 7 | - | /// Builds a void union variant. |
|
| 7 | + | /// Builds a tag-only union variant. |
|
| 8 | 8 | fn makeRed() -> Color { |
|
| 9 | 9 | return Color::Red; |
|
| 10 | 10 | } |
|
| 11 | 11 | ||
| 12 | - | /// Builds a void union variant (different variant). |
|
| 12 | + | /// Builds a tag-only union variant (different variant). |
|
| 13 | 13 | fn makeBlue() -> Color { |
|
| 14 | 14 | return Color::Blue; |
|
| 15 | 15 | } |
|
| 16 | 16 | ||
| 17 | 17 | /// Builds a union variant with a payload. |
| 19 | 19 | return MaybeInt::Some(7); |
|
| 20 | 20 | } |
|
| 21 | 21 | ||
| 22 | 22 | /// Builds a union variant without a payload. |
|
| 23 | 23 | fn makeNone() -> MaybeInt { |
|
| 24 | - | return MaybeInt::None(); |
|
| 24 | + | return MaybeInt::None; |
|
| 25 | 25 | } |
test/tests/union.variant.access.rad
+5 -5
| 1 | - | /// Void union. |
|
| 1 | + | /// Union with tag-only variants. |
|
| 2 | 2 | union Color { Red, Green, Blue } |
|
| 3 | 3 | ||
| 4 | - | /// Non-void union with payload and non-payload variants. |
|
| 4 | + | /// Union with payload and tag-only variants. |
|
| 5 | 5 | union Option { None, Some(i32) } |
|
| 6 | 6 | ||
| 7 | - | /// Accesses a void union variant. |
|
| 7 | + | /// Accesses a tag-only union variant. |
|
| 8 | 8 | fn makeRed() -> Color { |
|
| 9 | 9 | return Color::Red; |
|
| 10 | 10 | } |
|
| 11 | 11 | ||
| 12 | - | /// Assigns a void union variant to a variable. |
|
| 12 | + | /// Assigns a tag-only union variant to a variable. |
|
| 13 | 13 | fn assignGreen() -> Color { |
|
| 14 | 14 | let c: Color = Color::Green; |
|
| 15 | 15 | return c; |
|
| 16 | 16 | } |
|
| 17 | 17 | ||
| 18 | - | /// Accesses a non-void union variant directly without calling as function. |
|
| 18 | + | /// Accesses a tag-only variant directly without calling as function. |
|
| 19 | 19 | fn makeNone() -> Option { |
|
| 20 | 20 | return Option::None; |
|
| 21 | 21 | } |
|
| 22 | 22 | ||
| 23 | 23 | /// Accesses a variant with payload for comparison. |
test/tests/void.throw.rad
+3 -3
| 1 | - | /// Throwing void function without explicit return should return success implicitly. |
|
| 1 | + | /// Throwing no-result function without explicit return should return success implicitly. |
|
| 2 | 2 | union Error { Boom } |
|
| 3 | 3 | ||
| 4 | - | fn fallible(flag: bool) -> void throws (Error) { |
|
| 4 | + | fn fallible(flag: bool) throws (Error) { |
|
| 5 | 5 | if flag { |
|
| 6 | 6 | throw Error::Boom(); |
|
| 7 | 7 | } |
|
| 8 | 8 | } |
|
| 9 | 9 | ||
| 10 | - | fn caller(flag: bool) -> void throws (Error) { |
|
| 10 | + | fn caller(flag: bool) throws (Error) { |
|
| 11 | 11 | try fallible(flag); |
|
| 12 | 12 | } |