authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-16 16:02:35-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-16 16:02:35-04:00
logaf536ac343564e5120f99cbf3b7fc9efa984eb93
tree42a937bca75d34e2d3b4fc7d44ebafa66d8bd55b
parent329457bb4f714a8392153dfecfabd6f356144688

introduce new test syntax

* remove setFnTest builtin * add test "name" { ... } syntax * remove --check-unused argument. functions are always lazy now.

58 files changed, 617 insertions(+), 880 deletions(-)

doc/langref.md+3-1
...@@ -5,7 +5,9 @@...@@ -5,7 +5,9 @@
5```5```
6Root = many(TopLevelItem) "EOF"6Root = many(TopLevelItem) "EOF"
77
8TopLevelItem = ErrorValueDecl | Block | TopLevelDecl8TopLevelItem = ErrorValueDecl | Block | TopLevelDecl | TestDecl
9
10TestDecl = "test" String Block
911
10TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | TypeDecl | UseDecl)12TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | TypeDecl | UseDecl)
1113
doc/vim/syntax/zig.vim+1-1
...@@ -15,7 +15,7 @@ syn keyword zigConditional if else switch try...@@ -15,7 +15,7 @@ syn keyword zigConditional if else switch try
15syn keyword zigRepeat while for15syn keyword zigRepeat while for
1616
17syn keyword zigConstant null undefined this17syn keyword zigConstant null undefined this
18syn keyword zigKeyword fn use18syn keyword zigKeyword fn use test
19syn keyword zigType bool f32 f64 void Unreachable type error19syn keyword zigType bool f32 f64 void Unreachable type error
20syn keyword zigType i8 u8 i16 u16 i32 u32 i64 u64 isize usize20syn keyword zigType i8 u8 i16 u16 i32 u32 i64 u64 isize usize
21syn keyword zigType c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_long_double21syn keyword zigType c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_long_double
src/all_types.hpp+12-10
...@@ -311,6 +311,7 @@ enum NodeType {...@@ -311,6 +311,7 @@ enum NodeType {
311 NodeTypeVariableDeclaration,311 NodeTypeVariableDeclaration,
312 NodeTypeTypeDecl,312 NodeTypeTypeDecl,
313 NodeTypeErrorValueDecl,313 NodeTypeErrorValueDecl,
314 NodeTypeTestDecl,
314 NodeTypeBinOpExpr,315 NodeTypeBinOpExpr,
315 NodeTypeUnwrapErrorExpr,316 NodeTypeUnwrapErrorExpr,
316 NodeTypeNumberLiteral,317 NodeTypeNumberLiteral,
...@@ -435,6 +436,14 @@ struct AstNodeErrorValueDecl {...@@ -435,6 +436,14 @@ struct AstNodeErrorValueDecl {
435 ErrorTableEntry *err;436 ErrorTableEntry *err;
436};437};
437438
439struct AstNodeTestDecl {
440 // always invalid if it's not VisibModPrivate but can be parsed that way
441 VisibMod visib_mod;
442 Buf *name;
443
444 AstNode *body;
445};
446
438enum BinOpType {447enum BinOpType {
439 BinOpTypeInvalid,448 BinOpTypeInvalid,
440 BinOpTypeAssign,449 BinOpTypeAssign,
...@@ -781,6 +790,7 @@ struct AstNode {...@@ -781,6 +790,7 @@ struct AstNode {
781 AstNodeVariableDeclaration variable_declaration;790 AstNodeVariableDeclaration variable_declaration;
782 AstNodeTypeDecl type_decl;791 AstNodeTypeDecl type_decl;
783 AstNodeErrorValueDecl error_value_decl;792 AstNodeErrorValueDecl error_value_decl;
793 AstNodeTestDecl test_decl;
784 AstNodeBinOpExpr bin_op_expr;794 AstNodeBinOpExpr bin_op_expr;
785 AstNodeUnwrapErrorExpr unwrap_err_expr;795 AstNodeUnwrapErrorExpr unwrap_err_expr;
786 AstNodePrefixOpExpr prefix_op_expr;796 AstNodePrefixOpExpr prefix_op_expr;
...@@ -1091,7 +1101,7 @@ enum FnInline {...@@ -1091,7 +1101,7 @@ enum FnInline {
1091struct FnTableEntry {1101struct FnTableEntry {
1092 LLVMValueRef llvm_value;1102 LLVMValueRef llvm_value;
1093 AstNode *proto_node;1103 AstNode *proto_node;
1094 AstNode *fn_def_node;1104 AstNode *body_node;
1095 ScopeFnDef *fndef_scope; // parent should be the top level decls or container decls1105 ScopeFnDef *fndef_scope; // parent should be the top level decls or container decls
1096 Scope *child_scope; // parent is scope for last parameter1106 Scope *child_scope; // parent is scope for last parameter
1097 ScopeBlock *def_scope; // parent is child_scope1107 ScopeBlock *def_scope; // parent is child_scope
...@@ -1161,7 +1171,6 @@ enum BuiltinFnId {...@@ -1161,7 +1171,6 @@ enum BuiltinFnId {
1161 BuiltinFnIdTruncate,1171 BuiltinFnIdTruncate,
1162 BuiltinFnIdIntType,1172 BuiltinFnIdIntType,
1163 BuiltinFnIdUnreachable,1173 BuiltinFnIdUnreachable,
1164 BuiltinFnIdSetFnTest,
1165 BuiltinFnIdSetFnVisible,1174 BuiltinFnIdSetFnVisible,
1166 BuiltinFnIdSetDebugSafety,1175 BuiltinFnIdSetDebugSafety,
1167 BuiltinFnIdAlloca,1176 BuiltinFnIdAlloca,
...@@ -1411,8 +1420,8 @@ struct CodeGen {...@@ -1411,8 +1420,8 @@ struct CodeGen {
1411 ZigList<const char *> lib_dirs;1420 ZigList<const char *> lib_dirs;
14121421
1413 uint32_t test_fn_count;1422 uint32_t test_fn_count;
1423 TypeTableEntry *test_fn_type;
14141424
1415 bool check_unused;
1416 bool each_lib_rpath;1425 bool each_lib_rpath;
14171426
1418 ZigList<AstNode *> error_decls;1427 ZigList<AstNode *> error_decls;
...@@ -1630,7 +1639,6 @@ enum IrInstructionId {...@@ -1630,7 +1639,6 @@ enum IrInstructionId {
1630 IrInstructionIdTypeOf,1639 IrInstructionIdTypeOf,
1631 IrInstructionIdToPtrType,1640 IrInstructionIdToPtrType,
1632 IrInstructionIdPtrTypeChild,1641 IrInstructionIdPtrTypeChild,
1633 IrInstructionIdSetFnTest,
1634 IrInstructionIdSetFnVisible,1642 IrInstructionIdSetFnVisible,
1635 IrInstructionIdSetDebugSafety,1643 IrInstructionIdSetDebugSafety,
1636 IrInstructionIdArrayType,1644 IrInstructionIdArrayType,
...@@ -1973,12 +1981,6 @@ struct IrInstructionPtrTypeChild {...@@ -1973,12 +1981,6 @@ struct IrInstructionPtrTypeChild {
1973 IrInstruction *value;1981 IrInstruction *value;
1974};1982};
19751983
1976struct IrInstructionSetFnTest {
1977 IrInstruction base;
1978
1979 IrInstruction *fn_value;
1980};
1981
1982struct IrInstructionSetFnVisible {1984struct IrInstructionSetFnVisible {
1983 IrInstruction base;1985 IrInstruction base;
19841986
src/analyze.cpp+106-50
...@@ -130,7 +130,6 @@ Scope *create_loop_scope(AstNode *node, Scope *parent) {...@@ -130,7 +130,6 @@ Scope *create_loop_scope(AstNode *node, Scope *parent) {
130}130}
131131
132ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry) {132ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry) {
133 assert(!node || node->type == NodeTypeFnDef);
134 ScopeFnDef *scope = allocate<ScopeFnDef>(1);133 ScopeFnDef *scope = allocate<ScopeFnDef>(1);
135 init_scope(&scope->base, ScopeIdFnDef, node, parent);134 init_scope(&scope->base, ScopeIdFnDef, node, parent);
136 scope->fn_entry = fn_entry;135 scope->fn_entry = fn_entry;
...@@ -1756,7 +1755,8 @@ FnTableEntry *create_fn(AstNode *proto_node) {...@@ -1756,7 +1755,8 @@ FnTableEntry *create_fn(AstNode *proto_node) {
1756 FnTableEntry *fn_entry = create_fn_raw(inline_value, internal_linkage);1755 FnTableEntry *fn_entry = create_fn_raw(inline_value, internal_linkage);
17571756
1758 fn_entry->proto_node = proto_node;1757 fn_entry->proto_node = proto_node;
1759 fn_entry->fn_def_node = proto_node->data.fn_proto.fn_def_node;1758 fn_entry->body_node = (proto_node->data.fn_proto.fn_def_node == nullptr) ? nullptr :
1759 proto_node->data.fn_proto.fn_def_node->data.fn_def.body;
17601760
1761 return fn_entry;1761 return fn_entry;
1762}1762}
...@@ -1799,76 +1799,107 @@ static void typecheck_panic_fn(CodeGen *g) {...@@ -1799,76 +1799,107 @@ static void typecheck_panic_fn(CodeGen *g) {
1799 }1799 }
1800}1800}
18011801
1802static TypeTableEntry *get_test_fn_type(CodeGen *g) {
1803 if (g->test_fn_type)
1804 return g->test_fn_type;
1805
1806 FnTypeId fn_type_id = {0};
1807 fn_type_id.return_type = g->builtin_types.entry_void;
1808 g->test_fn_type = get_fn_type(g, &fn_type_id);
1809 return g->test_fn_type;
1810}
1811
1802static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {1812static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
1803 ImportTableEntry *import = tld_fn->base.import;1813 ImportTableEntry *import = tld_fn->base.import;
1804 AstNode *proto_node = tld_fn->base.source_node;1814 AstNode *source_node = tld_fn->base.source_node;
1805 assert(proto_node->type == NodeTypeFnProto);1815 if (source_node->type == NodeTypeFnProto) {
1806 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;1816 AstNodeFnProto *fn_proto = &source_node->data.fn_proto;
18071817
1808 AstNode *fn_def_node = fn_proto->fn_def_node;1818 AstNode *fn_def_node = fn_proto->fn_def_node;
18091819
1810 FnTableEntry *fn_table_entry = create_fn(tld_fn->base.source_node);1820 FnTableEntry *fn_table_entry = create_fn(source_node);
1811 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');1821 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
18121822
1813 tld_fn->fn_entry = fn_table_entry;1823 tld_fn->fn_entry = fn_table_entry;
18141824
1815 if (fn_table_entry->fn_def_node) {1825 if (fn_table_entry->body_node) {
1816 fn_table_entry->fndef_scope = create_fndef_scope(1826 fn_table_entry->fndef_scope = create_fndef_scope(
1817 fn_table_entry->fn_def_node, tld_fn->base.parent_scope, fn_table_entry);1827 fn_table_entry->body_node, tld_fn->base.parent_scope, fn_table_entry);
18181828
1819 for (size_t i = 0; i < fn_proto->params.length; i += 1) {1829 for (size_t i = 0; i < fn_proto->params.length; i += 1) {
1820 AstNode *param_node = fn_proto->params.at(i);1830 AstNode *param_node = fn_proto->params.at(i);
1821 assert(param_node->type == NodeTypeParamDecl);1831 assert(param_node->type == NodeTypeParamDecl);
1822 if (buf_len(param_node->data.param_decl.name) == 0) {1832 if (buf_len(param_node->data.param_decl.name) == 0) {
1823 add_node_error(g, param_node, buf_sprintf("missing parameter name"));1833 add_node_error(g, param_node, buf_sprintf("missing parameter name"));
1834 }
1824 }1835 }
1825 }1836 }
1826 }
18271837
1828 Scope *child_scope = fn_table_entry->fndef_scope ? &fn_table_entry->fndef_scope->base : tld_fn->base.parent_scope;1838 Scope *child_scope = fn_table_entry->fndef_scope ? &fn_table_entry->fndef_scope->base : tld_fn->base.parent_scope;
1829 fn_table_entry->type_entry = analyze_fn_type(g, proto_node, child_scope);1839 fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope);
18301840
1831 if (fn_table_entry->type_entry->id == TypeTableEntryIdInvalid) {1841 if (fn_table_entry->type_entry->id == TypeTableEntryIdInvalid) {
1832 tld_fn->base.resolution = TldResolutionInvalid;1842 tld_fn->base.resolution = TldResolutionInvalid;
1833 return;1843 return;
1834 }1844 }
18351845
1836 if (!fn_table_entry->type_entry->data.fn.is_generic) {1846 if (!fn_table_entry->type_entry->data.fn.is_generic) {
1837 g->fn_protos.append(fn_table_entry);1847 g->fn_protos.append(fn_table_entry);
18381848
1839 if (fn_def_node)1849 if (fn_def_node)
1840 g->fn_defs.append(fn_table_entry);1850 g->fn_defs.append(fn_table_entry);
18411851
1842 if (import == g->root_import && scope_is_root_decls(tld_fn->base.parent_scope)) {1852 if (import == g->root_import && scope_is_root_decls(tld_fn->base.parent_scope)) {
1843 if (buf_eql_str(&fn_table_entry->symbol_name, "main")) {1853 if (buf_eql_str(&fn_table_entry->symbol_name, "main")) {
1844 g->main_fn = fn_table_entry;1854 g->main_fn = fn_table_entry;
18451855
1846 if (!g->link_libc && tld_fn->base.visib_mod != VisibModExport) {1856 if (!g->link_libc && tld_fn->base.visib_mod != VisibModExport) {
1847 TypeTableEntry *err_void = get_error_type(g, g->builtin_types.entry_void);1857 TypeTableEntry *err_void = get_error_type(g, g->builtin_types.entry_void);
1848 TypeTableEntry *actual_return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type;1858 TypeTableEntry *actual_return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type;
1849 if (actual_return_type != err_void) {1859 if (actual_return_type != err_void) {
1850 add_node_error(g, fn_proto->return_type,1860 add_node_error(g, fn_proto->return_type,
1851 buf_sprintf("expected return type of main to be '%%void', instead is '%s'",1861 buf_sprintf("expected return type of main to be '%%void', instead is '%s'",
1852 buf_ptr(&actual_return_type->name)));1862 buf_ptr(&actual_return_type->name)));
1863 }
1853 }1864 }
1865 } else if (buf_eql_str(&fn_table_entry->symbol_name, "panic")) {
1866 g->panic_fn = fn_table_entry;
1867 typecheck_panic_fn(g);
1868 }
1869 } else if (import->package == g->panic_package && scope_is_root_decls(tld_fn->base.parent_scope)) {
1870 if (buf_eql_str(&fn_table_entry->symbol_name, "panic")) {
1871 g->panic_fn = fn_table_entry;
1872 typecheck_panic_fn(g);
1854 }1873 }
1855 } else if (buf_eql_str(&fn_table_entry->symbol_name, "panic")) {
1856 g->panic_fn = fn_table_entry;
1857 typecheck_panic_fn(g);
1858 }
1859 } else if (import->package == g->panic_package && scope_is_root_decls(tld_fn->base.parent_scope)) {
1860 if (buf_eql_str(&fn_table_entry->symbol_name, "panic")) {
1861 g->panic_fn = fn_table_entry;
1862 typecheck_panic_fn(g);
1863 }1874 }
1864 }1875 }
1876 } else if (source_node->type == NodeTypeTestDecl) {
1877 FnTableEntry *fn_table_entry = create_fn_raw(FnInlineAuto, false);
1878
1879 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
1880
1881 tld_fn->fn_entry = fn_table_entry;
1882
1883 fn_table_entry->proto_node = source_node;
1884 fn_table_entry->fndef_scope = create_fndef_scope(source_node, tld_fn->base.parent_scope, fn_table_entry);
1885 fn_table_entry->type_entry = get_test_fn_type(g);
1886 fn_table_entry->body_node = source_node->data.test_decl.body;
1887 fn_table_entry->is_test = true;
1888 g->test_fn_count += 1;
1889
1890 g->fn_protos.append(fn_table_entry);
1891 g->fn_defs.append(fn_table_entry);
1892
1893 } else {
1894 zig_unreachable();
1865 }1895 }
1866}1896}
18671897
1868static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {1898static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
1869 if (g->check_unused || g->is_test_build || tld->visib_mod == VisibModExport ||1899 if (tld->visib_mod == VisibModExport ||
1870 (buf_eql_str(tld->name, "panic") &&1900 (buf_eql_str(tld->name, "panic") &&
1871 (decls_scope->import->package == g->panic_package || decls_scope->import == g->root_import)))1901 (decls_scope->import->package == g->panic_package || decls_scope->import == g->root_import)) ||
1902 (tld->id == TldIdVar && g->is_test_build))
1872 {1903 {
1873 g->resolve_queue.append(tld);1904 g->resolve_queue.append(tld);
1874 }1905 }
...@@ -1882,6 +1913,27 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {...@@ -1882,6 +1913,27 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
1882 }1913 }
1883}1914}
18841915
1916static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) {
1917 assert(node->type == NodeTypeTestDecl);
1918
1919 if (node->data.test_decl.visib_mod != VisibModPrivate) {
1920 add_node_error(g, node, buf_sprintf("tests require no visibility modifier"));
1921 }
1922
1923 if (!g->is_test_build)
1924 return;
1925
1926 ImportTableEntry *import = get_scope_import(&decls_scope->base);
1927 if (import->package != g->root_package)
1928 return;
1929
1930 Buf *test_name = node->data.test_decl.name;
1931
1932 TldFn *tld_fn = allocate<TldFn>(1);
1933 init_tld(&tld_fn->base, TldIdFn, test_name, VisibModPrivate, node, &decls_scope->base);
1934 g->resolve_queue.append(&tld_fn->base);
1935}
1936
1885static void preview_error_value_decl(CodeGen *g, AstNode *node) {1937static void preview_error_value_decl(CodeGen *g, AstNode *node) {
1886 assert(node->type == NodeTypeErrorValueDecl);1938 assert(node->type == NodeTypeErrorValueDecl);
18871939
...@@ -1975,6 +2027,9 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -1975,6 +2027,9 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
1975 // error value declarations do not depend on other top level decls2027 // error value declarations do not depend on other top level decls
1976 preview_error_value_decl(g, node);2028 preview_error_value_decl(g, node);
1977 break;2029 break;
2030 case NodeTypeTestDecl:
2031 preview_test_decl(g, node, decls_scope);
2032 break;
1978 case NodeTypeContainerDecl:2033 case NodeTypeContainerDecl:
1979 case NodeTypeParamDecl:2034 case NodeTypeParamDecl:
1980 case NodeTypeFnDecl:2035 case NodeTypeFnDecl:
...@@ -2650,7 +2705,8 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -2650,7 +2705,8 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
26502705
2651 fn_table_entry->anal_state = FnAnalStateProbing;2706 fn_table_entry->anal_state = FnAnalStateProbing;
26522707
2653 AstNode *return_type_node = fn_table_entry->proto_node->data.fn_proto.return_type;2708 AstNode *return_type_node = (fn_table_entry->proto_node != nullptr) ?
2709 fn_table_entry->proto_node->data.fn_proto.return_type : fn_table_entry->fndef_scope->base.source_node;
26542710
2655 assert(fn_table_entry->fndef_scope);2711 assert(fn_table_entry->fndef_scope);
2656 if (!fn_table_entry->child_scope)2712 if (!fn_table_entry->child_scope)
...@@ -2674,7 +2730,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -2674,7 +2730,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
2674 }2730 }
2675 if (g->verbose) {2731 if (g->verbose) {
2676 fprintf(stderr, "\n");2732 fprintf(stderr, "\n");
2677 ast_render(stderr, fn_table_entry->fn_def_node, 4);2733 ast_render(stderr, fn_table_entry->body_node, 4);
2678 fprintf(stderr, "\n{ // (IR)\n");2734 fprintf(stderr, "\n{ // (IR)\n");
2679 ir_print(stderr, &fn_table_entry->ir_executable, 4);2735 ir_print(stderr, &fn_table_entry->ir_executable, 4);
2680 fprintf(stderr, "}\n");2736 fprintf(stderr, "}\n");
src/ast_render.cpp+3
...@@ -170,6 +170,8 @@ static const char *node_type_str(NodeType node_type) {...@@ -170,6 +170,8 @@ static const char *node_type_str(NodeType node_type) {
170 return "TypeDecl";170 return "TypeDecl";
171 case NodeTypeErrorValueDecl:171 case NodeTypeErrorValueDecl:
172 return "ErrorValueDecl";172 return "ErrorValueDecl";
173 case NodeTypeTestDecl:
174 return "TestDecl";
173 case NodeTypeNumberLiteral:175 case NodeTypeNumberLiteral:
174 return "NumberLiteral";176 return "NumberLiteral";
175 case NodeTypeStringLiteral:177 case NodeTypeStringLiteral:
...@@ -915,6 +917,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -915,6 +917,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
915 case NodeTypeFnDecl:917 case NodeTypeFnDecl:
916 case NodeTypeParamDecl:918 case NodeTypeParamDecl:
917 case NodeTypeErrorValueDecl:919 case NodeTypeErrorValueDecl:
920 case NodeTypeTestDecl:
918 case NodeTypeStructField:921 case NodeTypeStructField:
919 case NodeTypeUse:922 case NodeTypeUse:
920 zig_panic("TODO more ast rendering");923 zig_panic("TODO more ast rendering");
src/codegen.cpp+1-7
...@@ -138,10 +138,6 @@ void codegen_set_verbose(CodeGen *g, bool verbose) {...@@ -138,10 +138,6 @@ void codegen_set_verbose(CodeGen *g, bool verbose) {
138 g->verbose = verbose;138 g->verbose = verbose;
139}139}
140140
141void codegen_set_check_unused(CodeGen *g, bool check_unused) {
142 g->check_unused = check_unused;
143}
144
145void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) {141void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) {
146 g->each_lib_rpath = each_lib_rpath;142 g->each_lib_rpath = each_lib_rpath;
147}143}
...@@ -323,7 +319,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {...@@ -323,7 +319,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
323 return get_di_scope(g, scope->parent);319 return get_di_scope(g, scope->parent);
324 unsigned line_number = fn_table_entry->proto_node->line + 1;320 unsigned line_number = fn_table_entry->proto_node->line + 1;
325 unsigned scope_line = line_number;321 unsigned scope_line = line_number;
326 bool is_definition = fn_table_entry->fn_def_node != nullptr;322 bool is_definition = fn_table_entry->body_node != nullptr;
327 unsigned flags = 0;323 unsigned flags = 0;
328 bool is_optimized = g->is_release_build;324 bool is_optimized = g->is_release_build;
329 ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,325 ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,
...@@ -2492,7 +2488,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -2492,7 +2488,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
2492 case IrInstructionIdToPtrType:2488 case IrInstructionIdToPtrType:
2493 case IrInstructionIdPtrTypeChild:2489 case IrInstructionIdPtrTypeChild:
2494 case IrInstructionIdFieldPtr:2490 case IrInstructionIdFieldPtr:
2495 case IrInstructionIdSetFnTest:
2496 case IrInstructionIdSetFnVisible:2491 case IrInstructionIdSetFnVisible:
2497 case IrInstructionIdSetDebugSafety:2492 case IrInstructionIdSetDebugSafety:
2498 case IrInstructionIdArrayType:2493 case IrInstructionIdArrayType:
...@@ -4054,7 +4049,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -4054,7 +4049,6 @@ static void define_builtin_fns(CodeGen *g) {
4054 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);4049 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
4055 create_builtin_fn(g, BuiltinFnIdIntType, "intType", 2);4050 create_builtin_fn(g, BuiltinFnIdIntType, "intType", 2);
4056 create_builtin_fn(g, BuiltinFnIdUnreachable, "unreachable", 0);4051 create_builtin_fn(g, BuiltinFnIdUnreachable, "unreachable", 0);
4057 create_builtin_fn(g, BuiltinFnIdSetFnTest, "setFnTest", 1);
4058 create_builtin_fn(g, BuiltinFnIdSetFnVisible, "setFnVisible", 2);4052 create_builtin_fn(g, BuiltinFnIdSetFnVisible, "setFnVisible", 2);
4059 create_builtin_fn(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2);4053 create_builtin_fn(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2);
4060 create_builtin_fn(g, BuiltinFnIdAlloca, "alloca", 2);4054 create_builtin_fn(g, BuiltinFnIdAlloca, "alloca", 2);
src/codegen.hpp-1
...@@ -19,7 +19,6 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target);...@@ -19,7 +19,6 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target);
19void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);19void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
20void codegen_set_is_release(CodeGen *codegen, bool is_release);20void codegen_set_is_release(CodeGen *codegen, bool is_release);
21void codegen_set_is_test(CodeGen *codegen, bool is_test);21void codegen_set_is_test(CodeGen *codegen, bool is_test);
22void codegen_set_check_unused(CodeGen *codegen, bool check_unused);
23void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath);22void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath);
2423
25void codegen_set_is_static(CodeGen *codegen, bool is_static);24void codegen_set_is_static(CodeGen *codegen, bool is_static);
src/ir.cpp+5-60
...@@ -282,10 +282,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrTypeChild *)...@@ -282,10 +282,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrTypeChild *)
282 return IrInstructionIdPtrTypeChild;282 return IrInstructionIdPtrTypeChild;
283}283}
284284
285static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFnTest *) {
286 return IrInstructionIdSetFnTest;
287}
288
289static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFnVisible *) {285static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFnVisible *) {
290 return IrInstructionIdSetFnVisible;286 return IrInstructionIdSetFnVisible;
291}287}
...@@ -1147,17 +1143,6 @@ static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstN...@@ -1147,17 +1143,6 @@ static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstN
1147 return &instruction->base;1143 return &instruction->base;
1148}1144}
11491145
1150static IrInstruction *ir_build_set_fn_test(IrBuilder *irb, Scope *scope, AstNode *source_node,
1151 IrInstruction *fn_value)
1152{
1153 IrInstructionSetFnTest *instruction = ir_build_instruction<IrInstructionSetFnTest>(irb, scope, source_node);
1154 instruction->fn_value = fn_value;
1155
1156 ir_ref_instruction(fn_value, irb->current_basic_block);
1157
1158 return &instruction->base;
1159}
1160
1161static IrInstruction *ir_build_set_fn_visible(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn_value,1146static IrInstruction *ir_build_set_fn_visible(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn_value,
1162 IrInstruction *is_visible)1147 IrInstruction *is_visible)
1163{1148{
...@@ -2287,13 +2272,6 @@ static IrInstruction *ir_instruction_ptrtypechild_get_dep(IrInstructionPtrTypeCh...@@ -2287,13 +2272,6 @@ static IrInstruction *ir_instruction_ptrtypechild_get_dep(IrInstructionPtrTypeCh
2287 }2272 }
2288}2273}
22892274
2290static IrInstruction *ir_instruction_setfntest_get_dep(IrInstructionSetFnTest *instruction, size_t index) {
2291 switch (index) {
2292 case 0: return instruction->fn_value;
2293 default: return nullptr;
2294 }
2295}
2296
2297static IrInstruction *ir_instruction_setfnvisible_get_dep(IrInstructionSetFnVisible *instruction, size_t index) {2275static IrInstruction *ir_instruction_setfnvisible_get_dep(IrInstructionSetFnVisible *instruction, size_t index) {
2298 switch (index) {2276 switch (index) {
2299 case 0: return instruction->fn_value;2277 case 0: return instruction->fn_value;
...@@ -2807,8 +2785,6 @@ static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t...@@ -2807,8 +2785,6 @@ static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t
2807 return ir_instruction_toptrtype_get_dep((IrInstructionToPtrType *) instruction, index);2785 return ir_instruction_toptrtype_get_dep((IrInstructionToPtrType *) instruction, index);
2808 case IrInstructionIdPtrTypeChild:2786 case IrInstructionIdPtrTypeChild:
2809 return ir_instruction_ptrtypechild_get_dep((IrInstructionPtrTypeChild *) instruction, index);2787 return ir_instruction_ptrtypechild_get_dep((IrInstructionPtrTypeChild *) instruction, index);
2810 case IrInstructionIdSetFnTest:
2811 return ir_instruction_setfntest_get_dep((IrInstructionSetFnTest *) instruction, index);
2812 case IrInstructionIdSetFnVisible:2788 case IrInstructionIdSetFnVisible:
2813 return ir_instruction_setfnvisible_get_dep((IrInstructionSetFnVisible *) instruction, index);2789 return ir_instruction_setfnvisible_get_dep((IrInstructionSetFnVisible *) instruction, index);
2814 case IrInstructionIdSetDebugSafety:2790 case IrInstructionIdSetDebugSafety:
...@@ -3810,15 +3786,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -3810,15 +3786,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
3810 return arg;3786 return arg;
3811 return ir_build_typeof(irb, scope, node, arg);3787 return ir_build_typeof(irb, scope, node, arg);
3812 }3788 }
3813 case BuiltinFnIdSetFnTest:
3814 {
3815 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
3816 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
3817 if (arg0_value == irb->codegen->invalid_instruction)
3818 return arg0_value;
3819
3820 return ir_build_set_fn_test(irb, scope, node, arg0_value);
3821 }
3822 case BuiltinFnIdSetFnVisible:3789 case BuiltinFnIdSetFnVisible:
3823 {3790 {
3824 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);3791 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
...@@ -5543,6 +5510,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -5543,6 +5510,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
5543 zig_panic("TODO IR gen NodeTypeErrorValueDecl");5510 zig_panic("TODO IR gen NodeTypeErrorValueDecl");
5544 case NodeTypeTypeDecl:5511 case NodeTypeTypeDecl:
5545 zig_panic("TODO IR gen NodeTypeTypeDecl");5512 zig_panic("TODO IR gen NodeTypeTypeDecl");
5513 case NodeTypeTestDecl:
5514 zig_panic("TODO IR gen NodeTypeTestDecl");
5546 }5515 }
5547 zig_unreachable();5516 zig_unreachable();
5548}5517}
...@@ -5633,10 +5602,7 @@ bool ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) {...@@ -5633,10 +5602,7 @@ bool ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) {
5633 assert(fn_entry);5602 assert(fn_entry);
56345603
5635 IrExecutable *ir_executable = &fn_entry->ir_executable;5604 IrExecutable *ir_executable = &fn_entry->ir_executable;
5636 AstNode *fn_def_node = fn_entry->fn_def_node;5605 AstNode *body_node = fn_entry->body_node;
5637 assert(fn_def_node->type == NodeTypeFnDef);
5638
5639 AstNode *body_node = fn_def_node->data.fn_def.body;
56405606
5641 assert(fn_entry->child_scope);5607 assert(fn_entry->child_scope);
56425608
...@@ -8180,7 +8146,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8180,7 +8146,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8180 result = entry->value;8146 result = entry->value;
8181 } else {8147 } else {
8182 // Analyze the fn body block like any other constant expression.8148 // Analyze the fn body block like any other constant expression.
8183 AstNode *body_node = fn_entry->fn_def_node->data.fn_def.body;8149 AstNode *body_node = fn_entry->body_node;
8184 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,8150 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,
8185 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,8151 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,
8186 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec);8152 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec);
...@@ -8219,7 +8185,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -8219,7 +8185,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
8219 FnTableEntry *impl_fn = create_fn(fn_proto_node);8185 FnTableEntry *impl_fn = create_fn(fn_proto_node);
8220 impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count);8186 impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count);
8221 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);8187 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);
8222 impl_fn->fndef_scope = create_fndef_scope(impl_fn->fn_def_node, parent_scope, impl_fn);8188 impl_fn->fndef_scope = create_fndef_scope(impl_fn->body_node, parent_scope, impl_fn);
8223 impl_fn->child_scope = &impl_fn->fndef_scope->base;8189 impl_fn->child_scope = &impl_fn->fndef_scope->base;
8224 FnTypeId inst_fn_type_id = {0};8190 FnTypeId inst_fn_type_id = {0};
8225 init_fn_type_id(&inst_fn_type_id, fn_proto_node, new_fn_arg_count);8191 init_fn_type_id(&inst_fn_type_id, fn_proto_node, new_fn_arg_count);
...@@ -9582,24 +9548,6 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,...@@ -9582,24 +9548,6 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
9582 return ira->codegen->builtin_types.entry_type;9548 return ira->codegen->builtin_types.entry_type;
9583}9549}
95849550
9585static TypeTableEntry *ir_analyze_instruction_set_fn_test(IrAnalyze *ira,
9586 IrInstructionSetFnTest *set_fn_test_instruction)
9587{
9588 IrInstruction *fn_value = set_fn_test_instruction->fn_value->other;
9589
9590 FnTableEntry *fn_entry = ir_resolve_fn(ira, fn_value);
9591 if (!fn_entry)
9592 return ira->codegen->builtin_types.entry_invalid;
9593
9594 if (!fn_entry->is_test) {
9595 fn_entry->is_test = true;
9596 ira->codegen->test_fn_count += 1;
9597 }
9598
9599 ir_build_const_from(ira, &set_fn_test_instruction->base);
9600 return ira->codegen->builtin_types.entry_void;
9601}
9602
9603static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,9551static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,
9604 IrInstructionSetFnVisible *set_fn_visible_instruction)9552 IrInstructionSetFnVisible *set_fn_visible_instruction)
9605{9553{
...@@ -12253,8 +12201,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -12253,8 +12201,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
12253 return ir_analyze_instruction_to_ptr_type(ira, (IrInstructionToPtrType *)instruction);12201 return ir_analyze_instruction_to_ptr_type(ira, (IrInstructionToPtrType *)instruction);
12254 case IrInstructionIdPtrTypeChild:12202 case IrInstructionIdPtrTypeChild:
12255 return ir_analyze_instruction_ptr_type_child(ira, (IrInstructionPtrTypeChild *)instruction);12203 return ir_analyze_instruction_ptr_type_child(ira, (IrInstructionPtrTypeChild *)instruction);
12256 case IrInstructionIdSetFnTest:
12257 return ir_analyze_instruction_set_fn_test(ira, (IrInstructionSetFnTest *)instruction);
12258 case IrInstructionIdSetFnVisible:12204 case IrInstructionIdSetFnVisible:
12259 return ir_analyze_instruction_set_fn_visible(ira, (IrInstructionSetFnVisible *)instruction);12205 return ir_analyze_instruction_set_fn_visible(ira, (IrInstructionSetFnVisible *)instruction);
12260 case IrInstructionIdSetGlobalAlign:12206 case IrInstructionIdSetGlobalAlign:
...@@ -12469,7 +12415,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -12469,7 +12415,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
12469 case IrInstructionIdCall:12415 case IrInstructionIdCall:
12470 case IrInstructionIdReturn:12416 case IrInstructionIdReturn:
12471 case IrInstructionIdUnreachable:12417 case IrInstructionIdUnreachable:
12472 case IrInstructionIdSetFnTest:
12473 case IrInstructionIdSetFnVisible:12418 case IrInstructionIdSetFnVisible:
12474 case IrInstructionIdSetDebugSafety:12419 case IrInstructionIdSetDebugSafety:
12475 case IrInstructionIdImport:12420 case IrInstructionIdImport:
src/ir_print.cpp-9
...@@ -339,12 +339,6 @@ static void ir_print_enum_field_ptr(IrPrint *irp, IrInstructionEnumFieldPtr *ins...@@ -339,12 +339,6 @@ static void ir_print_enum_field_ptr(IrPrint *irp, IrInstructionEnumFieldPtr *ins
339 fprintf(irp->f, ")");339 fprintf(irp->f, ")");
340}340}
341341
342static void ir_print_set_fn_test(IrPrint *irp, IrInstructionSetFnTest *instruction) {
343 fprintf(irp->f, "@setFnTest(");
344 ir_print_other_instruction(irp, instruction->fn_value);
345 fprintf(irp->f, ")");
346}
347
348static void ir_print_set_fn_visible(IrPrint *irp, IrInstructionSetFnVisible *instruction) {342static void ir_print_set_fn_visible(IrPrint *irp, IrInstructionSetFnVisible *instruction) {
349 fprintf(irp->f, "@setFnVisible(");343 fprintf(irp->f, "@setFnVisible(");
350 ir_print_other_instruction(irp, instruction->fn_value);344 ir_print_other_instruction(irp, instruction->fn_value);
...@@ -932,9 +926,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -932,9 +926,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
932 case IrInstructionIdEnumFieldPtr:926 case IrInstructionIdEnumFieldPtr:
933 ir_print_enum_field_ptr(irp, (IrInstructionEnumFieldPtr *)instruction);927 ir_print_enum_field_ptr(irp, (IrInstructionEnumFieldPtr *)instruction);
934 break;928 break;
935 case IrInstructionIdSetFnTest:
936 ir_print_set_fn_test(irp, (IrInstructionSetFnTest *)instruction);
937 break;
938 case IrInstructionIdSetFnVisible:929 case IrInstructionIdSetFnVisible:
939 ir_print_set_fn_visible(irp, (IrInstructionSetFnVisible *)instruction);930 ir_print_set_fn_visible(irp, (IrInstructionSetFnVisible *)instruction);
940 break;931 break;
src/main.cpp-5
...@@ -56,7 +56,6 @@ static int usage(const char *arg0) {...@@ -56,7 +56,6 @@ static int usage(const char *arg0) {
56 " -mmacosx-version-min [ver] (darwin only) set Mac OS X deployment target\n"56 " -mmacosx-version-min [ver] (darwin only) set Mac OS X deployment target\n"
57 " -mios-version-min [ver] (darwin only) set iOS deployment target\n"57 " -mios-version-min [ver] (darwin only) set iOS deployment target\n"
58 " -framework [name] (darwin only) link against framework\n"58 " -framework [name] (darwin only) link against framework\n"
59 " --check-unused perform semantic analysis on unused declarations\n"
60 " --linker-script [path] use a custom linker script\n"59 " --linker-script [path] use a custom linker script\n"
61 " -rpath [path] add directory to the runtime library search path\n"60 " -rpath [path] add directory to the runtime library search path\n"
62 " --each-lib-rpath add rpath for each used dynamic library\n"61 " --each-lib-rpath add rpath for each used dynamic library\n"
...@@ -141,7 +140,6 @@ int main(int argc, char **argv) {...@@ -141,7 +140,6 @@ int main(int argc, char **argv) {
141 bool rdynamic = false;140 bool rdynamic = false;
142 const char *mmacosx_version_min = nullptr;141 const char *mmacosx_version_min = nullptr;
143 const char *mios_version_min = nullptr;142 const char *mios_version_min = nullptr;
144 bool check_unused = false;
145 const char *linker_script = nullptr;143 const char *linker_script = nullptr;
146 ZigList<const char *> rpath_list = {0};144 ZigList<const char *> rpath_list = {0};
147 bool each_lib_rpath = false;145 bool each_lib_rpath = false;
...@@ -166,8 +164,6 @@ int main(int argc, char **argv) {...@@ -166,8 +164,6 @@ int main(int argc, char **argv) {
166 municode = true;164 municode = true;
167 } else if (strcmp(arg, "-rdynamic") == 0) {165 } else if (strcmp(arg, "-rdynamic") == 0) {
168 rdynamic = true;166 rdynamic = true;
169 } else if (strcmp(arg, "--check-unused") == 0) {
170 check_unused = true;
171 } else if (strcmp(arg, "--each-lib-rpath") == 0) {167 } else if (strcmp(arg, "--each-lib-rpath") == 0) {
172 each_lib_rpath = true;168 each_lib_rpath = true;
173 } else if (arg[1] == 'L' && arg[2] != 0) {169 } else if (arg[1] == 'L' && arg[2] != 0) {
...@@ -354,7 +350,6 @@ int main(int argc, char **argv) {...@@ -354,7 +350,6 @@ int main(int argc, char **argv) {
354 codegen_set_is_release(g, is_release_build);350 codegen_set_is_release(g, is_release_build);
355 codegen_set_is_test(g, cmd == CmdTest);351 codegen_set_is_test(g, cmd == CmdTest);
356 codegen_set_linker_script(g, linker_script);352 codegen_set_linker_script(g, linker_script);
357 codegen_set_check_unused(g, check_unused);
358 if (each_lib_rpath)353 if (each_lib_rpath)
359 codegen_set_each_lib_rpath(g, each_lib_rpath);354 codegen_set_each_lib_rpath(g, each_lib_rpath);
360355
src/parser.cpp+31-1
...@@ -2417,6 +2417,27 @@ static AstNode *ast_parse_error_value_decl(ParseContext *pc, size_t *token_index...@@ -2417,6 +2417,27 @@ static AstNode *ast_parse_error_value_decl(ParseContext *pc, size_t *token_index
2417 return node;2417 return node;
2418}2418}
24192419
2420/*
2421TestDecl = "test" String Block
2422*/
2423static AstNode *ast_parse_test_decl_node(ParseContext *pc, size_t *token_index, VisibMod visib_mod) {
2424 Token *first_token = &pc->tokens->at(*token_index);
2425
2426 if (first_token->id != TokenIdKeywordTest) {
2427 return nullptr;
2428 }
2429 *token_index += 1;
2430
2431 Token *name_tok = ast_eat_token(pc, token_index, TokenIdStringLiteral);
2432
2433 AstNode *node = ast_create_node(pc, NodeTypeTestDecl, first_token);
2434 node->data.test_decl.visib_mod = visib_mod;
2435 node->data.test_decl.name = token_buf(name_tok);
2436 node->data.test_decl.body = ast_parse_block(pc, token_index, true);
2437
2438 return node;
2439}
2440
2420/*2441/*
2421TypeDecl = "type" "Symbol" "=" TypeExpr ";"2442TypeDecl = "type" "Symbol" "=" TypeExpr ";"
2422*/2443*/
...@@ -2443,7 +2464,7 @@ static AstNode *ast_parse_type_decl(ParseContext *pc, size_t *token_index, Visib...@@ -2443,7 +2464,7 @@ static AstNode *ast_parse_type_decl(ParseContext *pc, size_t *token_index, Visib
2443}2464}
24442465
2445/*2466/*
2446TopLevelItem = ErrorValueDecl | Block | TopLevelDecl2467TopLevelItem = ErrorValueDecl | Block | TopLevelDecl | TestDecl
2447TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | TypeDecl | UseDecl)2468TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | TypeDecl | UseDecl)
2448*/2469*/
2449static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, ZigList<AstNode *> *top_level_decls) {2470static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, ZigList<AstNode *> *top_level_decls) {
...@@ -2491,6 +2512,12 @@ static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, Zig...@@ -2491,6 +2512,12 @@ static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, Zig
2491 continue;2512 continue;
2492 }2513 }
24932514
2515 AstNode *test_decl_node = ast_parse_test_decl_node(pc, token_index, visib_mod);
2516 if (test_decl_node) {
2517 top_level_decls->append(test_decl_node);
2518 continue;
2519 }
2520
2494 AstNode *type_decl_node = ast_parse_type_decl(pc, token_index, visib_mod);2521 AstNode *type_decl_node = ast_parse_type_decl(pc, token_index, visib_mod);
2495 if (type_decl_node) {2522 if (type_decl_node) {
2496 top_level_decls->append(type_decl_node);2523 top_level_decls->append(type_decl_node);
...@@ -2585,6 +2612,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -2585,6 +2612,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
2585 case NodeTypeErrorValueDecl:2612 case NodeTypeErrorValueDecl:
2586 // none2613 // none
2587 break;2614 break;
2615 case NodeTypeTestDecl:
2616 visit_field(&node->data.test_decl.body, visit, context);
2617 break;
2588 case NodeTypeBinOpExpr:2618 case NodeTypeBinOpExpr:
2589 visit_field(&node->data.bin_op_expr.op1, visit, context);2619 visit_field(&node->data.bin_op_expr.op1, visit, context);
2590 visit_field(&node->data.bin_op_expr.op2, visit, context);2620 visit_field(&node->data.bin_op_expr.op2, visit, context);
src/tokenizer.cpp+2
...@@ -133,6 +133,7 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -133,6 +133,7 @@ static const struct ZigKeyword zig_keywords[] = {
133 {"return", TokenIdKeywordReturn},133 {"return", TokenIdKeywordReturn},
134 {"struct", TokenIdKeywordStruct},134 {"struct", TokenIdKeywordStruct},
135 {"switch", TokenIdKeywordSwitch},135 {"switch", TokenIdKeywordSwitch},
136 {"test", TokenIdKeywordTest},
136 {"this", TokenIdKeywordThis},137 {"this", TokenIdKeywordThis},
137 {"true", TokenIdKeywordTrue},138 {"true", TokenIdKeywordTrue},
138 {"try", TokenIdKeywordTry},139 {"try", TokenIdKeywordTry},
...@@ -1508,6 +1509,7 @@ const char * token_name(TokenId id) {...@@ -1508,6 +1509,7 @@ const char * token_name(TokenId id) {
1508 case TokenIdKeywordReturn: return "return";1509 case TokenIdKeywordReturn: return "return";
1509 case TokenIdKeywordStruct: return "struct";1510 case TokenIdKeywordStruct: return "struct";
1510 case TokenIdKeywordSwitch: return "switch";1511 case TokenIdKeywordSwitch: return "switch";
1512 case TokenIdKeywordTest: return "test";
1511 case TokenIdKeywordThis: return "this";1513 case TokenIdKeywordThis: return "this";
1512 case TokenIdKeywordTrue: return "true";1514 case TokenIdKeywordTrue: return "true";
1513 case TokenIdKeywordTry: return "try";1515 case TokenIdKeywordTry: return "try";
src/tokenizer.hpp+1
...@@ -74,6 +74,7 @@ enum TokenId {...@@ -74,6 +74,7 @@ enum TokenId {
74 TokenIdKeywordReturn,74 TokenIdKeywordReturn,
75 TokenIdKeywordStruct,75 TokenIdKeywordStruct,
76 TokenIdKeywordSwitch,76 TokenIdKeywordSwitch,
77 TokenIdKeywordTest,
77 TokenIdKeywordThis,78 TokenIdKeywordThis,
78 TokenIdKeywordTrue,79 TokenIdKeywordTrue,
79 TokenIdKeywordTry,80 TokenIdKeywordTry,
std/compiler_rt.zig+3-9
...@@ -322,9 +322,7 @@ export fn __udivsi3(n: su_int, d: su_int) -> su_int {...@@ -322,9 +322,7 @@ export fn __udivsi3(n: su_int, d: su_int) -> su_int {
322 return q;322 return q;
323}323}
324324
325fn test_umoddi3() {325test "test_umoddi3" {
326 @setFnTest(this);
327
328 test_one_umoddi3(0, 1, 0);326 test_one_umoddi3(0, 1, 0);
329 test_one_umoddi3(2, 1, 0);327 test_one_umoddi3(2, 1, 0);
330 test_one_umoddi3(0x8000000000000000, 1, 0x0);328 test_one_umoddi3(0x8000000000000000, 1, 0x0);
...@@ -337,9 +335,7 @@ fn test_one_umoddi3(a: du_int, b: du_int, expected_r: du_int) {...@@ -337,9 +335,7 @@ fn test_one_umoddi3(a: du_int, b: du_int, expected_r: du_int) {
337 assert(r == expected_r);335 assert(r == expected_r);
338}336}
339337
340fn test_udivmoddi4() {338test "test_udivmoddi4" {
341 @setFnTest(this);
342
343 const cases = [][4]du_int {339 const cases = [][4]du_int {
344 []du_int{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},340 []du_int{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},
345 []du_int{0x0000000080000000, 0x0000000100000001, 0x0000000000000000, 0x0000000080000000},341 []du_int{0x0000000080000000, 0x0000000100000001, 0x0000000000000000, 0x0000000080000000},
...@@ -367,9 +363,7 @@ fn test_one_udivmoddi4(a: du_int, b: du_int, expected_q: du_int, expected_r: du_...@@ -367,9 +363,7 @@ fn test_one_udivmoddi4(a: du_int, b: du_int, expected_q: du_int, expected_r: du_
367 assert(r == expected_r);363 assert(r == expected_r);
368}364}
369365
370fn test_udivsi3() {366test "test_udivsi3" {
371 @setFnTest(this);
372
373 const cases = [][3]su_int {367 const cases = [][3]su_int {
374 []su_int{0x00000000, 0x00000001, 0x00000000},368 []su_int{0x00000000, 0x00000001, 0x00000000},
375 []su_int{0x00000000, 0x00000002, 0x00000000},369 []su_int{0x00000000, 0x00000002, 0x00000000},
std/cstr.zig+2-6
...@@ -140,9 +140,7 @@ pub const Buffer0 = struct {...@@ -140,9 +140,7 @@ pub const Buffer0 = struct {
140 }140 }
141};141};
142142
143fn testSimpleBuffer0() {143test "simple Buffer0" {
144 @setFnTest(this);
145
146 var buf = %%Buffer0.initEmpty(&debug.global_allocator);144 var buf = %%Buffer0.initEmpty(&debug.global_allocator);
147 assert(buf.len() == 0);145 assert(buf.len() == 0);
148 %%buf.appendCStr(c"hello");146 %%buf.appendCStr(c"hello");
...@@ -162,9 +160,7 @@ fn testSimpleBuffer0() {...@@ -162,9 +160,7 @@ fn testSimpleBuffer0() {
162 assert(buf.startsWithOther(&buf2));160 assert(buf.startsWithOther(&buf2));
163}161}
164162
165fn testCStrFns() {163test "cstr fns" {
166 @setFnTest(this);
167
168 comptime testCStrFnsImpl();164 comptime testCStrFnsImpl();
169 testCStrFnsImpl();165 testCStrFnsImpl();
170}166}
std/fmt.zig+3-9
...@@ -291,9 +291,7 @@ fn digitToChar(digit: u8, uppercase: bool) -> u8 {...@@ -291,9 +291,7 @@ fn digitToChar(digit: u8, uppercase: bool) -> u8 {
291 };291 };
292}292}
293293
294fn testBufPrintInt() {294test "testBufPrintInt" {
295 @setFnTest(this);
296
297 var buffer: [max_int_digits]u8 = undefined;295 var buffer: [max_int_digits]u8 = undefined;
298 const buf = buffer[0...];296 const buf = buffer[0...];
299 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));297 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));
...@@ -315,9 +313,7 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u...@@ -315,9 +313,7 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u
315 return buf[0...formatIntBuf(buf, value, base, uppercase, width)];313 return buf[0...formatIntBuf(buf, value, base, uppercase, width)];
316}314}
317315
318fn testParseU64DigitTooBig() {316test "testParseU64DigitTooBig" {
319 @setFnTest(this);
320
321 parseUnsigned(u64, "123a", 10) %% |err| {317 parseUnsigned(u64, "123a", 10) %% |err| {
322 if (err == error.InvalidChar) return;318 if (err == error.InvalidChar) return;
323 @unreachable();319 @unreachable();
...@@ -325,9 +321,7 @@ fn testParseU64DigitTooBig() {...@@ -325,9 +321,7 @@ fn testParseU64DigitTooBig() {
325 @unreachable();321 @unreachable();
326}322}
327323
328fn testParseUnsignedComptime() {324test "testParseUnsignedComptime" {
329 @setFnTest(this);
330
331 comptime {325 comptime {
332 assert(%%parseUnsigned(usize, "2", 10) == 2);326 assert(%%parseUnsigned(usize, "2", 10) == 2);
333 }327 }
std/hash_map.zig+1-3
...@@ -219,9 +219,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -219,9 +219,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
219 }219 }
220}220}
221221
222fn basicHashMapTest() {222test "basicHashMapTest" {
223 @setFnTest(this);
224
225 var map: HashMap(i32, i32, hash_i32, eql_i32) = undefined;223 var map: HashMap(i32, i32, hash_i32, eql_i32) = undefined;
226 map.init(&debug.global_allocator);224 map.init(&debug.global_allocator);
227 defer map.deinit();225 defer map.deinit();
std/list.zig+1-3
...@@ -64,9 +64,7 @@ pub fn List(comptime T: type) -> type{...@@ -64,9 +64,7 @@ pub fn List(comptime T: type) -> type{
64 }64 }
65}65}
6666
67fn basicListTest() {67test "basicListTest" {
68 @setFnTest(this);
69
70 var list = List(i32).init(&debug.global_allocator);68 var list = List(i32).init(&debug.global_allocator);
71 defer list.deinit();69 defer list.deinit();
7270
std/math.zig+1-3
...@@ -68,9 +68,7 @@ fn getReturnTypeForAbs(comptime T: type) -> type {...@@ -68,9 +68,7 @@ fn getReturnTypeForAbs(comptime T: type) -> type {
68 }68 }
69}69}
7070
71fn testMath() {71test "testMath" {
72 @setFnTest(this);
73
74 testMathImpl();72 testMathImpl();
75 comptime testMathImpl();73 comptime testMathImpl();
76}74}
std/mem.zig+3-9
...@@ -117,17 +117,13 @@ pub fn writeInt(buf: []u8, value: var, big_endian: bool) {...@@ -117,17 +117,13 @@ pub fn writeInt(buf: []u8, value: var, big_endian: bool) {
117 assert(bits == 0);117 assert(bits == 0);
118}118}
119119
120fn testStringEquality() {120test "testStringEquality" {
121 @setFnTest(this);
122
123 assert(eql(u8, "abcd", "abcd"));121 assert(eql(u8, "abcd", "abcd"));
124 assert(!eql(u8, "abcdef", "abZdef"));122 assert(!eql(u8, "abcdef", "abZdef"));
125 assert(!eql(u8, "abcdefg", "abcdef"));123 assert(!eql(u8, "abcdefg", "abcdef"));
126}124}
127125
128fn testReadInt() {126test "testReadInt" {
129 @setFnTest(this);
130
131 testReadIntImpl();127 testReadIntImpl();
132 comptime testReadIntImpl();128 comptime testReadIntImpl();
133}129}
...@@ -149,9 +145,7 @@ fn testReadIntImpl() {...@@ -149,9 +145,7 @@ fn testReadIntImpl() {
149 }145 }
150}146}
151147
152fn testWriteInt() {148test "testWriteInt" {
153 @setFnTest(this);
154
155 testWriteIntImpl();149 testWriteIntImpl();
156 comptime testWriteIntImpl();150 comptime testWriteIntImpl();
157}151}
std/rand.zig+3-9
...@@ -158,9 +158,7 @@ fn MersenneTwister(...@@ -158,9 +158,7 @@ fn MersenneTwister(
158 }158 }
159}159}
160160
161fn testFloat32() {161test "testFloat32" {
162 @setFnTest(this);
163
164 var r: Rand = undefined;162 var r: Rand = undefined;
165 r.init(42);163 r.init(42);
166164
...@@ -171,9 +169,7 @@ fn testFloat32() {...@@ -171,9 +169,7 @@ fn testFloat32() {
171 }}169 }}
172}170}
173171
174fn testMT19937_64() {172test "testMT19937_64" {
175 @setFnTest(this);
176
177 var rng: MT19937_64 = undefined;173 var rng: MT19937_64 = undefined;
178 rng.init(rand_test.mt64_seed);174 rng.init(rand_test.mt64_seed);
179 for (rand_test.mt64_data) |value| {175 for (rand_test.mt64_data) |value| {
...@@ -181,9 +177,7 @@ fn testMT19937_64() {...@@ -181,9 +177,7 @@ fn testMT19937_64() {
181 }177 }
182}178}
183179
184fn testMT19937_32() {180test "testMT19937_32" {
185 @setFnTest(this);
186
187 var rng: MT19937_32 = undefined;181 var rng: MT19937_32 = undefined;
188 rng.init(rand_test.mt32_seed);182 rng.init(rand_test.mt32_seed);
189 for (rand_test.mt32_data) |value| {183 for (rand_test.mt32_data) |value| {
std/sort.zig+2-6
...@@ -58,9 +58,7 @@ fn reverse(was: Cmp) -> Cmp {...@@ -58,9 +58,7 @@ fn reverse(was: Cmp) -> Cmp {
58// ---------------------------------------58// ---------------------------------------
59// tests59// tests
6060
61fn testSort() {61test "testSort" {
62 @setFnTest(this);
63
64 const u8cases = [][]const []const u8 {62 const u8cases = [][]const []const u8 {
65 [][]const u8{"", ""},63 [][]const u8{"", ""},
66 [][]const u8{"a", "a"},64 [][]const u8{"a", "a"},
...@@ -96,9 +94,7 @@ fn testSort() {...@@ -96,9 +94,7 @@ fn testSort() {
96 }94 }
97}95}
9896
99fn testSortDesc() {97test "testSortDesc" {
100 @setFnTest(this);
101
102 const rev_cases = [][]const []const i32 {98 const rev_cases = [][]const []const i32 {
103 [][]const i32{[]i32{}, []i32{}},99 [][]const i32{[]i32{}, []i32{}},
104 [][]const i32{[]i32{1}, []i32{1}},100 [][]const i32{[]i32{1}, []i32{1}},
test/cases/array.zig+6-18
...@@ -1,9 +1,7 @@...@@ -1,9 +1,7 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
2const mem = @import("std").mem;2const mem = @import("std").mem;
33
4fn arrays() {4test "arrays" {
5 @setFnTest(this);
6
7 var array : [5]u32 = undefined;5 var array : [5]u32 = undefined;
86
9 var i : u32 = 0;7 var i : u32 = 0;
...@@ -27,9 +25,7 @@ fn getArrayLen(a: []const u32) -> usize {...@@ -27,9 +25,7 @@ fn getArrayLen(a: []const u32) -> usize {
27 a.len25 a.len
28}26}
2927
30fn voidArrays() {28test "voidArrays" {
31 @setFnTest(this);
32
33 var array: [4]void = undefined;29 var array: [4]void = undefined;
34 array[0] = void{};30 array[0] = void{};
35 array[1] = array[2];31 array[1] = array[2];
...@@ -37,18 +33,14 @@ fn voidArrays() {...@@ -37,18 +33,14 @@ fn voidArrays() {
37 assert(array.len == 4);33 assert(array.len == 4);
38}34}
3935
40fn arrayLiteral() {36test "arrayLiteral" {
41 @setFnTest(this);
42
43 const hex_mult = []u16{4096, 256, 16, 1};37 const hex_mult = []u16{4096, 256, 16, 1};
4438
45 assert(hex_mult.len == 4);39 assert(hex_mult.len == 4);
46 assert(hex_mult[1] == 256);40 assert(hex_mult[1] == 256);
47}41}
4842
49fn arrayDotLenConstExpr() {43test "arrayDotLenConstExpr" {
50 @setFnTest(this);
51
52 assert(comptime {some_array.len == 4});44 assert(comptime {some_array.len == 4});
53}45}
5446
...@@ -58,9 +50,7 @@ const ArrayDotLenConstExpr = struct {...@@ -58,9 +50,7 @@ const ArrayDotLenConstExpr = struct {
58const some_array = []u8 {0, 1, 2, 3};50const some_array = []u8 {0, 1, 2, 3};
5951
6052
61fn nestedArrays() {53test "nestedArrays" {
62 @setFnTest(this);
63
64 const array_of_strings = [][]const u8 {"hello", "this", "is", "my", "thing"};54 const array_of_strings = [][]const u8 {"hello", "this", "is", "my", "thing"};
65 for (array_of_strings) |s, i| {55 for (array_of_strings) |s, i| {
66 if (i == 0) assert(mem.eql(u8, s, "hello"));56 if (i == 0) assert(mem.eql(u8, s, "hello"));
...@@ -79,9 +69,7 @@ const Sub = struct {...@@ -79,9 +69,7 @@ const Sub = struct {
79const Str = struct {69const Str = struct {
80 a: []Sub,70 a: []Sub,
81};71};
82fn setGlobalVarArrayViaSliceEmbeddedInStruct() {72test "setGlobalVarArrayViaSliceEmbeddedInStruct" {
83 @setFnTest(this);
84
85 var s = Str { .a = s_array[0...]};73 var s = Str { .a = s_array[0...]};
8674
87 s.a[0].b = 1;75 s.a[0].b = 1;
test/cases/atomics.zig+2-6
...@@ -1,16 +1,12 @@...@@ -1,16 +1,12 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn cmpxchg() {3test "cmpxchg" {
4 @setFnTest(this);
5
6 var x: i32 = 1234;4 var x: i32 = 1234;
7 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}5 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
8 assert(x == 5678);6 assert(x == 5678);
9}7}
108
11fn fence() {9test "fence" {
12 @setFnTest(this);
13
14 var x: i32 = 1234;10 var x: i32 = 1234;
15 @fence(AtomicOrder.SeqCst);11 @fence(AtomicOrder.SeqCst);
16 x = 5678;12 x = 5678;
test/cases/bool.zig+5-15
...@@ -1,15 +1,11 @@...@@ -1,15 +1,11 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn boolLiterals() {3test "boolLiterals" {
4 @setFnTest(this);
5
6 assert(true);4 assert(true);
7 assert(!false);5 assert(!false);
8}6}
97
10fn castBoolToInt() {8test "castBoolToInt" {
11 @setFnTest(this);
12
13 const t = true;9 const t = true;
14 const f = false;10 const f = false;
15 assert(i32(t) == i32(1));11 assert(i32(t) == i32(1));
...@@ -22,18 +18,14 @@ fn nonConstCastBoolToInt(t: bool, f: bool) {...@@ -22,18 +18,14 @@ fn nonConstCastBoolToInt(t: bool, f: bool) {
22 assert(i32(f) == i32(0));18 assert(i32(f) == i32(0));
23}19}
2420
25fn boolCmp() {21test "boolCmp" {
26 @setFnTest(this);
27
28 assert(testBoolCmp(true, false) == false);22 assert(testBoolCmp(true, false) == false);
29}23}
30fn testBoolCmp(a: bool, b: bool) -> bool {24fn testBoolCmp(a: bool, b: bool) -> bool {
31 a == b25 a == b
32}26}
3327
34fn shortCircuitAndOr() {28test "shortCircuitAndOr" {
35 @setFnTest(this);
36
37 var a = true;29 var a = true;
38 a &&= false;30 a &&= false;
39 assert(!a);31 assert(!a);
...@@ -49,9 +41,7 @@ const global_f = false;...@@ -49,9 +41,7 @@ const global_f = false;
49const global_t = true;41const global_t = true;
50const not_global_f = !global_f;42const not_global_f = !global_f;
51const not_global_t = !global_t;43const not_global_t = !global_t;
52fn compileTimeBoolnot() {44test "compileTimeBoolnot" {
53 @setFnTest(this);
54
55 assert(not_global_f);45 assert(not_global_f);
56 assert(!not_global_t);46 assert(!not_global_t);
57}47}
test/cases/cast.zig+3-9
...@@ -1,24 +1,18 @@...@@ -1,24 +1,18 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn intToPtrCast() {3test "intToPtrCast" {
4 @setFnTest(this);
5
6 const x = isize(13);4 const x = isize(13);
7 const y = (&u8)(x);5 const y = (&u8)(x);
8 const z = usize(y);6 const z = usize(y);
9 assert(z == 13);7 assert(z == 13);
10}8}
119
12fn numLitIntToPtrCast() {10test "numLitIntToPtrCast" {
13 @setFnTest(this);
14
15 const vga_mem = (&u16)(0xB8000);11 const vga_mem = (&u16)(0xB8000);
16 assert(usize(vga_mem) == 0xB8000);12 assert(usize(vga_mem) == 0xB8000);
17}13}
1814
19fn pointerReinterpretConstFloatToInt() {15test "pointerReinterpretConstFloatToInt" {
20 @setFnTest(this);
21
22 const float: f64 = 5.99999999999994648725e-01;16 const float: f64 = 5.99999999999994648725e-01;
23 const float_ptr = &float;17 const float_ptr = &float;
24 const int_ptr = (&i32)(float_ptr);18 const int_ptr = (&i32)(float_ptr);
test/cases/const_slice_child.zig+1-3
...@@ -2,9 +2,7 @@ const assert = @import("std").debug.assert;...@@ -2,9 +2,7 @@ const assert = @import("std").debug.assert;
22
3var argv: &const &const u8 = undefined;3var argv: &const &const u8 = undefined;
44
5fn constSliceChild() {5test "constSliceChild" {
6 @setFnTest(this);
7
8 const strs = ([]&const u8) {6 const strs = ([]&const u8) {
9 c"one",7 c"one",
10 c"two",8 c"two",
test/cases/defer.zig+2-6
...@@ -21,9 +21,7 @@ fn runSomeMaybeDefers(x: bool) -> ?bool {...@@ -21,9 +21,7 @@ fn runSomeMaybeDefers(x: bool) -> ?bool {
21 return if (x) x else null;21 return if (x) x else null;
22}22}
2323
24fn mixingNormalAndErrorDefers() {24test "mixingNormalAndErrorDefers" {
25 @setFnTest(this);
26
27 assert(%%runSomeErrorDefers(true));25 assert(%%runSomeErrorDefers(true));
28 assert(result[0] == 'c');26 assert(result[0] == 'c');
29 assert(result[1] == 'a');27 assert(result[1] == 'a');
...@@ -38,9 +36,7 @@ fn mixingNormalAndErrorDefers() {...@@ -38,9 +36,7 @@ fn mixingNormalAndErrorDefers() {
38 assert(result[2] == 'a');36 assert(result[2] == 'a');
39}37}
4038
41fn mixingNormalAndMaybeDefers() {39test "mixingNormalAndMaybeDefers" {
42 @setFnTest(this);
43
44 assert(??runSomeMaybeDefers(true));40 assert(??runSomeMaybeDefers(true));
45 assert(result[0] == 'c');41 assert(result[0] == 'c');
46 assert(result[1] == 'a');42 assert(result[1] == 'a');
test/cases/enum.zig+5-15
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn enumType() {3test "enumType" {
4 @setFnTest(this);
5
6 const foo1 = Foo.One {13};4 const foo1 = Foo.One {13};
7 const foo2 = Foo.Two { Point { .x = 1234, .y = 5678, }};5 const foo2 = Foo.Two { Point { .x = 1234, .y = 5678, }};
8 const bar = Bar.B;6 const bar = Bar.B;
...@@ -15,9 +13,7 @@ fn enumType() {...@@ -15,9 +13,7 @@ fn enumType() {
15 assert(@sizeOf(Bar) == 1);13 assert(@sizeOf(Bar) == 1);
16}14}
1715
18fn enumAsReturnValue () {16test "enumAsReturnValue" {
19 @setFnTest(this);
20
21 switch (returnAnInt(13)) {17 switch (returnAnInt(13)) {
22 Foo.One => |value| assert(value == 13),18 Foo.One => |value| assert(value == 13),
23 else => @unreachable(),19 else => @unreachable(),
...@@ -45,9 +41,7 @@ fn returnAnInt(x: i32) -> Foo {...@@ -45,9 +41,7 @@ fn returnAnInt(x: i32) -> Foo {
45}41}
4642
4743
48fn constantEnumWithPayload() {44test "constantEnumWithPayload" {
49 @setFnTest(this);
50
51 var empty = AnEnumWithPayload.Empty;45 var empty = AnEnumWithPayload.Empty;
52 var full = AnEnumWithPayload.Full {13};46 var full = AnEnumWithPayload.Full {13};
53 shouldBeEmpty(empty);47 shouldBeEmpty(empty);
...@@ -83,9 +77,7 @@ const Number = enum {...@@ -83,9 +77,7 @@ const Number = enum {
83 Four,77 Four,
84};78};
8579
86fn enumToInt() {80test "enumToInt" {
87 @setFnTest(this);
88
89 shouldEqual(Number.Zero, 0);81 shouldEqual(Number.Zero, 0);
90 shouldEqual(Number.One, 1);82 shouldEqual(Number.One, 1);
91 shouldEqual(Number.Two, 2);83 shouldEqual(Number.Two, 2);
...@@ -98,9 +90,7 @@ fn shouldEqual(n: Number, expected: usize) {...@@ -98,9 +90,7 @@ fn shouldEqual(n: Number, expected: usize) {
98}90}
9991
10092
101fn intToEnum() {93test "intToEnum" {
102 @setFnTest(this);
103
104 testIntToEnumEval(3);94 testIntToEnumEval(3);
105}95}
106fn testIntToEnumEval(x: i32) {96fn testIntToEnumEval(x: i32) {
test/cases/enum_with_members.zig+1-3
...@@ -14,9 +14,7 @@ const ET = enum {...@@ -14,9 +14,7 @@ const ET = enum {
14 }14 }
15};15};
1616
17fn enumWithMembers() {17test "enumWithMembers" {
18 @setFnTest(this);
19
20 const a = ET.SINT { -42 };18 const a = ET.SINT { -42 };
21 const b = ET.UINT { 42 };19 const b = ET.UINT { 42 };
22 var buf: [20]u8 = undefined;20 var buf: [20]u8 = undefined;
test/cases/error.zig+7-20
...@@ -15,9 +15,7 @@ pub fn baz() -> %i32 {...@@ -15,9 +15,7 @@ pub fn baz() -> %i32 {
15 return y + 1;15 return y + 1;
16}16}
1717
18fn errorWrapping() {18test "errorWrapping" {
19 @setFnTest(this);
20
21 assert(%%baz() == 15);19 assert(%%baz() == 15);
22}20}
2321
...@@ -26,8 +24,7 @@ fn gimmeItBroke() -> []const u8 {...@@ -26,8 +24,7 @@ fn gimmeItBroke() -> []const u8 {
26 @errorName(error.ItBroke)24 @errorName(error.ItBroke)
27}25}
2826
29fn errorName() {27test "errorName" {
30 @setFnTest(this);
31 assert(mem.eql(u8, @errorName(error.AnError), "AnError"));28 assert(mem.eql(u8, @errorName(error.AnError), "AnError"));
32 assert(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));29 assert(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
33}30}
...@@ -35,9 +32,7 @@ error AnError;...@@ -35,9 +32,7 @@ error AnError;
35error ALongerErrorName;32error ALongerErrorName;
3633
3734
38fn errorValues() {35test "errorValues" {
39 @setFnTest(this);
40
41 const a = i32(error.err1);36 const a = i32(error.err1);
42 const b = i32(error.err2);37 const b = i32(error.err2);
43 assert(a != b);38 assert(a != b);
...@@ -46,9 +41,7 @@ error err1;...@@ -46,9 +41,7 @@ error err1;
46error err2;41error err2;
4742
4843
49fn redefinitionOfErrorValuesAllowed() {44test "redefinitionOfErrorValuesAllowed" {
50 @setFnTest(this);
51
52 shouldBeNotEqual(error.AnError, error.SecondError);45 shouldBeNotEqual(error.AnError, error.SecondError);
53}46}
54error AnError;47error AnError;
...@@ -59,9 +52,7 @@ fn shouldBeNotEqual(a: error, b: error) {...@@ -59,9 +52,7 @@ fn shouldBeNotEqual(a: error, b: error) {
59}52}
6053
6154
62fn errBinaryOperator() {55test "errBinaryOperator" {
63 @setFnTest(this);
64
65 const a = errBinaryOperatorG(true) %% 3;56 const a = errBinaryOperatorG(true) %% 3;
66 const b = errBinaryOperatorG(false) %% 3;57 const b = errBinaryOperatorG(false) %% 3;
67 assert(a == 3);58 assert(a == 3);
...@@ -77,18 +68,14 @@ fn errBinaryOperatorG(x: bool) -> %isize {...@@ -77,18 +68,14 @@ fn errBinaryOperatorG(x: bool) -> %isize {
77}68}
7869
7970
80fn unwrapSimpleValueFromError() {71test "unwrapSimpleValueFromError" {
81 @setFnTest(this);
82
83 const i = %%unwrapSimpleValueFromErrorDo();72 const i = %%unwrapSimpleValueFromErrorDo();
84 assert(i == 13);73 assert(i == 13);
85}74}
86fn unwrapSimpleValueFromErrorDo() -> %isize { 13 }75fn unwrapSimpleValueFromErrorDo() -> %isize { 13 }
8776
8877
89fn errReturnInAssignment() {78test "errReturnInAssignment" {
90 @setFnTest(this);
91
92 %%doErrReturnInAssignment();79 %%doErrReturnInAssignment();
93}80}
9481
test/cases/eval.zig+19-55
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn compileTimeRecursion() {3test "compileTimeRecursion" {
4 @setFnTest(this);
5
6 assert(some_data.len == 21);4 assert(some_data.len == 21);
7}5}
8var some_data: [usize(fibonacci(7))]u8 = undefined;6var some_data: [usize(fibonacci(7))]u8 = undefined;
...@@ -17,14 +15,11 @@ fn unwrapAndAddOne(blah: ?i32) -> i32 {...@@ -17,14 +15,11 @@ fn unwrapAndAddOne(blah: ?i32) -> i32 {
17 return ??blah + 1;15 return ??blah + 1;
18}16}
19const should_be_1235 = unwrapAndAddOne(1234);17const should_be_1235 = unwrapAndAddOne(1234);
20fn testStaticAddOne() {18test "testStaticAddOne" {
21 @setFnTest(this);
22 assert(should_be_1235 == 1235);19 assert(should_be_1235 == 1235);
23}20}
2421
25fn inlinedLoop() {22test "inlinedLoop" {
26 @setFnTest(this);
27
28 comptime var i = 0;23 comptime var i = 0;
29 comptime var sum = 0;24 comptime var sum = 0;
30 inline while (i <= 5; i += 1)25 inline while (i <= 5; i += 1)
...@@ -38,25 +33,20 @@ fn gimme1or2(comptime a: bool) -> i32 {...@@ -38,25 +33,20 @@ fn gimme1or2(comptime a: bool) -> i32 {
38 comptime var z: i32 = if (a) x else y;33 comptime var z: i32 = if (a) x else y;
39 return z;34 return z;
40}35}
41fn inlineVariableGetsResultOfConstIf() {36test "inlineVariableGetsResultOfConstIf" {
42 @setFnTest(this);
43 assert(gimme1or2(true) == 1);37 assert(gimme1or2(true) == 1);
44 assert(gimme1or2(false) == 2);38 assert(gimme1or2(false) == 2);
45}39}
4640
4741
48fn staticFunctionEvaluation() {42test "staticFunctionEvaluation" {
49 @setFnTest(this);
50
51 assert(statically_added_number == 3);43 assert(statically_added_number == 3);
52}44}
53const statically_added_number = staticAdd(1, 2);45const statically_added_number = staticAdd(1, 2);
54fn staticAdd(a: i32, b: i32) -> i32 { a + b }46fn staticAdd(a: i32, b: i32) -> i32 { a + b }
5547
5648
57fn constExprEvalOnSingleExprBlocks() {49test "constExprEvalOnSingleExprBlocks" {
58 @setFnTest(this);
59
60 assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);50 assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
61}51}
6252
...@@ -75,9 +65,7 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {...@@ -75,9 +65,7 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {
7565
7666
7767
78fn staticallyInitalizedList() {68test "staticallyInitalizedList" {
79 @setFnTest(this);
80
81 assert(static_point_list[0].x == 1);69 assert(static_point_list[0].x == 1);
82 assert(static_point_list[0].y == 2);70 assert(static_point_list[0].y == 2);
83 assert(static_point_list[1].x == 3);71 assert(static_point_list[1].x == 3);
...@@ -96,9 +84,7 @@ fn makePoint(x: i32, y: i32) -> Point {...@@ -96,9 +84,7 @@ fn makePoint(x: i32, y: i32) -> Point {
96}84}
9785
9886
99fn staticEvalListInit() {87test "staticEvalListInit" {
100 @setFnTest(this);
101
102 assert(static_vec3.data[2] == 1.0);88 assert(static_vec3.data[2] == 1.0);
103 assert(vec3(0.0, 0.0, 3.0).data[2] == 3.0);89 assert(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
104}90}
...@@ -113,18 +99,14 @@ pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {...@@ -113,18 +99,14 @@ pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {
113}99}
114100
115101
116fn constantExpressions() {102test "constantExpressions" {
117 @setFnTest(this);
118
119 var array : [array_size]u8 = undefined;103 var array : [array_size]u8 = undefined;
120 assert(@sizeOf(@typeOf(array)) == 20);104 assert(@sizeOf(@typeOf(array)) == 20);
121}105}
122const array_size : u8 = 20;106const array_size : u8 = 20;
123107
124108
125fn constantStructWithNegation() {109test "constantStructWithNegation" {
126 @setFnTest(this);
127
128 assert(vertices[0].x == -0.6);110 assert(vertices[0].x == -0.6);
129}111}
130const Vertex = struct {112const Vertex = struct {
...@@ -141,9 +123,7 @@ const vertices = []Vertex {...@@ -141,9 +123,7 @@ const vertices = []Vertex {
141};123};
142124
143125
144fn staticallyInitalizedStruct() {126test "staticallyInitalizedStruct" {
145 @setFnTest(this);
146
147 st_init_str_foo.x += 1;127 st_init_str_foo.x += 1;
148 assert(st_init_str_foo.x == 14);128 assert(st_init_str_foo.x == 14);
149}129}
...@@ -154,18 +134,14 @@ const StInitStrFoo = struct {...@@ -154,18 +134,14 @@ const StInitStrFoo = struct {
154var st_init_str_foo = StInitStrFoo { .x = 13, .y = true, };134var st_init_str_foo = StInitStrFoo { .x = 13, .y = true, };
155135
156136
157fn staticallyInitializedArrayLiteral() {137test "staticallyInitializedArrayLiteral" {
158 @setFnTest(this);
159
160 const y : [4]u8 = st_init_arr_lit_x;138 const y : [4]u8 = st_init_arr_lit_x;
161 assert(y[3] == 4);139 assert(y[3] == 4);
162}140}
163const st_init_arr_lit_x = []u8{1,2,3,4};141const st_init_arr_lit_x = []u8{1,2,3,4};
164142
165143
166fn constSlice() {144test "constSlice" {
167 @setFnTest(this);
168
169 comptime {145 comptime {
170 const a = "1234567890";146 const a = "1234567890";
171 assert(a.len == 10);147 assert(a.len == 10);
...@@ -175,9 +151,7 @@ fn constSlice() {...@@ -175,9 +151,7 @@ fn constSlice() {
175 }151 }
176}152}
177153
178fn tryToTrickEvalWithRuntimeIf() {154test "tryToTrickEvalWithRuntimeIf" {
179 @setFnTest(this);
180
181 assert(testTryToTrickEvalWithRuntimeIf(true) == 10);155 assert(testTryToTrickEvalWithRuntimeIf(true) == 10);
182}156}
183157
...@@ -203,9 +177,7 @@ fn max(comptime T: type, a: T, b: T) -> T {...@@ -203,9 +177,7 @@ fn max(comptime T: type, a: T, b: T) -> T {
203fn letsTryToCompareBools(a: bool, b: bool) -> bool {177fn letsTryToCompareBools(a: bool, b: bool) -> bool {
204 max(bool, a, b)178 max(bool, a, b)
205}179}
206fn inlinedBlockAndRuntimeBlockPhi() {180test "inlinedBlockAndRuntimeBlockPhi" {
207 @setFnTest(this);
208
209 assert(letsTryToCompareBools(true, true));181 assert(letsTryToCompareBools(true, true));
210 assert(letsTryToCompareBools(true, false));182 assert(letsTryToCompareBools(true, false));
211 assert(letsTryToCompareBools(false, true));183 assert(letsTryToCompareBools(false, true));
...@@ -244,17 +216,13 @@ fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 {...@@ -244,17 +216,13 @@ fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 {
244 return result;216 return result;
245}217}
246218
247fn comptimeIterateOverFnPtrList() {219test "comptimeIterateOverFnPtrList" {
248 @setFnTest(this);
249
250 assert(performFn('t', 1) == 6);220 assert(performFn('t', 1) == 6);
251 assert(performFn('o', 0) == 1);221 assert(performFn('o', 0) == 1);
252 assert(performFn('w', 99) == 99);222 assert(performFn('w', 99) == 99);
253}223}
254224
255fn evalSetDebugSafetyAtCompileTime() {225test "evalSetDebugSafetyAtCompileTime" {
256 @setFnTest(this);
257
258 const result = comptime fnWithSetDebugSafety();226 const result = comptime fnWithSetDebugSafety();
259 assert(result == 1234);227 assert(result == 1234);
260}228}
...@@ -278,17 +246,13 @@ var simple_struct = SimpleStruct{ .field = 1234, };...@@ -278,17 +246,13 @@ var simple_struct = SimpleStruct{ .field = 1234, };
278246
279const bound_fn = simple_struct.method;247const bound_fn = simple_struct.method;
280248
281fn callMethodOnBoundFnReferringToVarInstance() {249test "callMethodOnBoundFnReferringToVarInstance" {
282 @setFnTest(this);
283
284 assert(bound_fn() == 1237);250 assert(bound_fn() == 1237);
285}251}
286252
287253
288254
289fn ptrToLocalArrayArgumentAtComptime() {255test "ptrToLocalArrayArgumentAtComptime" {
290 @setFnTest(this);
291
292 comptime {256 comptime {
293 var bytes: [10]u8 = undefined;257 var bytes: [10]u8 = undefined;
294 modifySomeBytes(bytes[0...]);258 modifySomeBytes(bytes[0...]);
test/cases/fn.zig+13-26
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn params() {3test "params" {
4 @setFnTest(this);
5
6 assert(testParamsAdd(22, 11) == 33);4 assert(testParamsAdd(22, 11) == 33);
7}5}
8fn testParamsAdd(a: i32, b: i32) -> i32 {6fn testParamsAdd(a: i32, b: i32) -> i32 {
...@@ -10,9 +8,7 @@ fn testParamsAdd(a: i32, b: i32) -> i32 {...@@ -10,9 +8,7 @@ fn testParamsAdd(a: i32, b: i32) -> i32 {
10}8}
119
1210
13fn localVariables() {11test "localVariables" {
14 @setFnTest(this);
15
16 testLocVars(2);12 testLocVars(2);
17}13}
18fn testLocVars(b: i32) {14fn testLocVars(b: i32) {
...@@ -21,9 +17,7 @@ fn testLocVars(b: i32) {...@@ -21,9 +17,7 @@ fn testLocVars(b: i32) {
21}17}
2218
2319
24fn voidParameters() {20test "voidParameters" {
25 @setFnTest(this);
26
27 voidFun(1, void{}, 2, {});21 voidFun(1, void{}, 2, {});
28}22}
29fn voidFun(a: i32, b: void, c: i32, d: void) {23fn voidFun(a: i32, b: void, c: i32, d: void) {
...@@ -34,9 +28,7 @@ fn voidFun(a: i32, b: void, c: i32, d: void) {...@@ -34,9 +28,7 @@ fn voidFun(a: i32, b: void, c: i32, d: void) {
34}28}
3529
3630
37fn mutableLocalVariables() {31test "mutableLocalVariables" {
38 @setFnTest(this);
39
40 var zero : i32 = 0;32 var zero : i32 = 0;
41 assert(zero == 0);33 assert(zero == 0);
4234
...@@ -47,9 +39,7 @@ fn mutableLocalVariables() {...@@ -47,9 +39,7 @@ fn mutableLocalVariables() {
47 assert(i == 3);39 assert(i == 3);
48}40}
4941
50fn separateBlockScopes() {42test "separateBlockScopes" {
51 @setFnTest(this);
52
53 {43 {
54 const no_conflict : i32 = 5;44 const no_conflict : i32 = 5;
55 assert(no_conflict == 5);45 assert(no_conflict == 5);
...@@ -62,22 +52,21 @@ fn separateBlockScopes() {...@@ -62,22 +52,21 @@ fn separateBlockScopes() {
62 assert(c == 10);52 assert(c == 10);
63}53}
6454
65fn callFnWithEmptyString() {55test "callFnWithEmptyString" {
66 @setFnTest(this);
67
68 acceptsString("");56 acceptsString("");
69}57}
7058
71fn acceptsString(foo: []u8) { }59fn acceptsString(foo: []u8) { }
7260
7361
74fn @"weird function name"() {62fn @"weird function name"() -> i32 {
75 @setFnTest(this);63 return 1234;
64}
65test "weird function name" {
66 assert(@"weird function name"() == 1234);
76}67}
7768
78fn implicitCastFnUnreachableReturn() {69test "implicitCastFnUnreachableReturn" {
79 @setFnTest(this);
80
81 wantsFnWithVoid(fnWithUnreachable);70 wantsFnWithVoid(fnWithUnreachable);
82}71}
8372
...@@ -88,9 +77,7 @@ fn fnWithUnreachable() -> unreachable {...@@ -88,9 +77,7 @@ fn fnWithUnreachable() -> unreachable {
88}77}
8978
9079
91fn functionPointers() {80test "functionPointers" {
92 @setFnTest(this);
93
94 const fns = []@typeOf(fn1) { fn1, fn2, fn3, fn4, };81 const fns = []@typeOf(fn1) { fn1, fn2, fn3, fn4, };
95 for (fns) |f, i| {82 for (fns) |f, i| {
96 assert(f() == u32(i) + 5);83 assert(f() == u32(i) + 5);
test/cases/for.zig+3-9
...@@ -2,9 +2,7 @@ const std = @import("std");...@@ -2,9 +2,7 @@ const std = @import("std");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const mem = std.mem;3const mem = std.mem;
44
5fn continueInForLoop() {5test "continueInForLoop" {
6 @setFnTest(this);
7
8 const array = []i32 {1, 2, 3, 4, 5};6 const array = []i32 {1, 2, 3, 4, 5};
9 var sum : i32 = 0;7 var sum : i32 = 0;
10 for (array) |x| {8 for (array) |x| {
...@@ -17,9 +15,7 @@ fn continueInForLoop() {...@@ -17,9 +15,7 @@ fn continueInForLoop() {
17 if (sum != 6) @unreachable()15 if (sum != 6) @unreachable()
18}16}
1917
20fn forLoopWithPointerElemVar() {18test "forLoopWithPointerElemVar" {
21 @setFnTest(this);
22
23 const source = "abcdefg";19 const source = "abcdefg";
24 var target: [source.len]u8 = undefined;20 var target: [source.len]u8 = undefined;
25 mem.copy(u8, target[0...], source);21 mem.copy(u8, target[0...], source);
...@@ -32,9 +28,7 @@ fn mangleString(s: []u8) {...@@ -32,9 +28,7 @@ fn mangleString(s: []u8) {
32 }28 }
33}29}
3430
35fn basicForLoop() {31test "basicForLoop" {
36 @setFnTest(this);
37
38 const expected_result = []u8{9, 8, 7, 6, 0, 1, 2, 3, 9, 8, 7, 6, 0, 1, 2, 3 };32 const expected_result = []u8{9, 8, 7, 6, 0, 1, 2, 3, 9, 8, 7, 6, 0, 1, 2, 3 };
3933
40 var buffer: [expected_result.len]u8 = undefined;34 var buffer: [expected_result.len]u8 = undefined;
test/cases/generics.zig+9-26
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn simpleGenericFn() {3test "simpleGenericFn" {
4 @setFnTest(this);
5
6 assert(max(i32, 3, -1) == 3);4 assert(max(i32, 3, -1) == 3);
7 assert(max(f32, 0.123, 0.456) == 0.456);5 assert(max(f32, 0.123, 0.456) == 0.456);
8 assert(add(2, 3) == 5);6 assert(add(2, 3) == 5);
...@@ -17,8 +15,7 @@ fn add(comptime a: i32, b: i32) -> i32 {...@@ -17,8 +15,7 @@ fn add(comptime a: i32, b: i32) -> i32 {
17}15}
1816
19const the_max = max(u32, 1234, 5678);17const the_max = max(u32, 1234, 5678);
20fn compileTimeGenericEval() {18test "compileTimeGenericEval" {
21 @setFnTest(this);
22 assert(the_max == 5678);19 assert(the_max == 5678);
23}20}
2421
...@@ -34,18 +31,14 @@ fn sameButWithFloats(a: f64, b: f64) -> f64 {...@@ -34,18 +31,14 @@ fn sameButWithFloats(a: f64, b: f64) -> f64 {
34 max(f64, a, b)31 max(f64, a, b)
35}32}
3633
37fn fnWithInlineArgs() {34test "fnWithInlineArgs" {
38 @setFnTest(this);
39
40 assert(gimmeTheBigOne(1234, 5678) == 5678);35 assert(gimmeTheBigOne(1234, 5678) == 5678);
41 assert(shouldCallSameInstance(34, 12) == 34);36 assert(shouldCallSameInstance(34, 12) == 34);
42 assert(sameButWithFloats(0.43, 0.49) == 0.49);37 assert(sameButWithFloats(0.43, 0.49) == 0.49);
43}38}
4439
4540
46fn varParams() {41test "varParams" {
47 @setFnTest(this);
48
49 assert(max_i32(12, 34) == 34);42 assert(max_i32(12, 34) == 34);
50 assert(max_f64(1.2, 3.4) == 3.4);43 assert(max_f64(1.2, 3.4) == 3.4);
51}44}
...@@ -79,9 +72,7 @@ pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {...@@ -79,9 +72,7 @@ pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
79 }72 }
80}73}
8174
82fn functionWithReturnTypeType() {75test "functionWithReturnTypeType" {
83 @setFnTest(this);
84
85 var list: List(i32) = undefined;76 var list: List(i32) = undefined;
86 var list2: List(i32) = undefined;77 var list2: List(i32) = undefined;
87 list.length = 10;78 list.length = 10;
...@@ -91,9 +82,7 @@ fn functionWithReturnTypeType() {...@@ -91,9 +82,7 @@ fn functionWithReturnTypeType() {
91}82}
9283
9384
94fn genericStruct() {85test "genericStruct" {
95 @setFnTest(this);
96
97 var a1 = GenNode(i32) {.value = 13, .next = null,};86 var a1 = GenNode(i32) {.value = 13, .next = null,};
98 var b1 = GenNode(bool) {.value = true, .next = null,};87 var b1 = GenNode(bool) {.value = true, .next = null,};
99 assert(a1.value == 13);88 assert(a1.value == 13);
...@@ -108,9 +97,7 @@ fn GenNode(comptime T: type) -> type {...@@ -108,9 +97,7 @@ fn GenNode(comptime T: type) -> type {
108 }97 }
109}98}
11099
111fn constDeclsInStruct() {100test "constDeclsInStruct" {
112 @setFnTest(this);
113
114 assert(GenericDataThing(3).count_plus_one == 4);101 assert(GenericDataThing(3).count_plus_one == 4);
115}102}
116fn GenericDataThing(comptime count: isize) -> type {103fn GenericDataThing(comptime count: isize) -> type {
...@@ -120,9 +107,7 @@ fn GenericDataThing(comptime count: isize) -> type {...@@ -120,9 +107,7 @@ fn GenericDataThing(comptime count: isize) -> type {
120}107}
121108
122109
123fn useGenericParamInGenericParam() {110test "useGenericParamInGenericParam" {
124 @setFnTest(this);
125
126 assert(aGenericFn(i32, 3, 4) == 7);111 assert(aGenericFn(i32, 3, 4) == 7);
127}112}
128fn aGenericFn(comptime T: type, comptime a: T, b: T) -> T {113fn aGenericFn(comptime T: type, comptime a: T, b: T) -> T {
...@@ -130,9 +115,7 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) -> T {...@@ -130,9 +115,7 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) -> T {
130}115}
131116
132117
133fn genericFnWithImplicitCast() {118test "genericFnWithImplicitCast" {
134 @setFnTest(this);
135
136 assert(getFirstByte(u8, []u8 {13}) == 13);119 assert(getFirstByte(u8, []u8 {13}) == 13);
137 assert(getFirstByte(u16, []u16 {0, 13}) == 0);120 assert(getFirstByte(u16, []u16 {0, 13}) == 0);
138}121}
test/cases/goto.zig+2-6
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn gotoAndLabels() {3test "gotoAndLabels" {
4 @setFnTest(this);
5
6 gotoLoop();4 gotoLoop();
7 assert(goto_counter == 10);5 assert(goto_counter == 10);
8}6}
...@@ -21,9 +19,7 @@ var goto_counter: i32 = 0;...@@ -21,9 +19,7 @@ var goto_counter: i32 = 0;
2119
2220
2321
24fn gotoLeaveDeferScope() {22test "gotoLeaveDeferScope" {
25 @setFnTest(this);
26
27 testGotoLeaveDeferScope(true);23 testGotoLeaveDeferScope(true);
28}24}
29fn testGotoLeaveDeferScope(b: bool) {25fn testGotoLeaveDeferScope(b: bool) {
test/cases/if.zig+2-6
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn ifStatements() {3test "ifStatements" {
4 @setFnTest(this);
5
6 shouldBeEqual(1, 1);4 shouldBeEqual(1, 1);
7 firstEqlThird(2, 1, 2);5 firstEqlThird(2, 1, 2);
8}6}
...@@ -26,9 +24,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) {...@@ -26,9 +24,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) {
26}24}
2725
2826
29fn elseIfExpression() {27test "elseIfExpression" {
30 @setFnTest(this);
31
32 assert(elseIfExpressionF(1) == 1);28 assert(elseIfExpressionF(1) == 1);
33}29}
34fn elseIfExpressionF(c: u8) -> u8 {30fn elseIfExpressionF(c: u8) -> u8 {
test/cases/import.zig+1-3
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
2const a_namespace = @import("cases/import/a_namespace.zig");2const a_namespace = @import("cases/import/a_namespace.zig");
33
4fn callFnViaNamespaceLookup() {4test "callFnViaNamespaceLookup" {
5 @setFnTest(this);
6
7 assert(a_namespace.foo() == 1234);5 assert(a_namespace.foo() == 1234);
8}6}
test/cases/ir_block_deps.zig+1-3
...@@ -15,9 +15,7 @@ fn getErrInt() -> %i32 { 0 }...@@ -15,9 +15,7 @@ fn getErrInt() -> %i32 { 0 }
1515
16error ItBroke;16error ItBroke;
1717
18fn irBlockDeps() {18test "irBlockDeps" {
19 @setFnTest(this);
20
21 assert(%%foo(1) == 0);19 assert(%%foo(1) == 0);
22 assert(%%foo(2) == 0);20 assert(%%foo(2) == 0);
23}21}
test/cases/math.zig+17-51
...@@ -1,60 +1,46 @@...@@ -1,60 +1,46 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn exactDivision() {3test "exactDivision" {
4 @setFnTest(this);
5
6 assert(divExact(55, 11) == 5);4 assert(divExact(55, 11) == 5);
7}5}
8fn divExact(a: u32, b: u32) -> u32 {6fn divExact(a: u32, b: u32) -> u32 {
9 @divExact(a, b)7 @divExact(a, b)
10}8}
119
12fn floatDivision() {10test "floatDivision" {
13 @setFnTest(this);
14
15 assert(fdiv32(12.0, 3.0) == 4.0);11 assert(fdiv32(12.0, 3.0) == 4.0);
16}12}
17fn fdiv32(a: f32, b: f32) -> f32 {13fn fdiv32(a: f32, b: f32) -> f32 {
18 a / b14 a / b
19}15}
2016
21fn overflowIntrinsics() {17test "overflowIntrinsics" {
22 @setFnTest(this);
23
24 var result: u8 = undefined;18 var result: u8 = undefined;
25 assert(@addWithOverflow(u8, 250, 100, &result));19 assert(@addWithOverflow(u8, 250, 100, &result));
26 assert(!@addWithOverflow(u8, 100, 150, &result));20 assert(!@addWithOverflow(u8, 100, 150, &result));
27 assert(result == 250);21 assert(result == 250);
28}22}
2923
30fn shlWithOverflow() {24test "shlWithOverflow" {
31 @setFnTest(this);
32
33 var result: u16 = undefined;25 var result: u16 = undefined;
34 assert(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));26 assert(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
35 assert(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));27 assert(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
36 assert(result == 0b1011111111111100);28 assert(result == 0b1011111111111100);
37}29}
3830
39fn countLeadingZeroes() {31test "countLeadingZeroes" {
40 @setFnTest(this);
41
42 assert(@clz(u8(0b00001010)) == 4);32 assert(@clz(u8(0b00001010)) == 4);
43 assert(@clz(u8(0b10001010)) == 0);33 assert(@clz(u8(0b10001010)) == 0);
44 assert(@clz(u8(0b00000000)) == 8);34 assert(@clz(u8(0b00000000)) == 8);
45}35}
4636
47fn countTrailingZeroes() {37test "countTrailingZeroes" {
48 @setFnTest(this);
49
50 assert(@ctz(u8(0b10100000)) == 5);38 assert(@ctz(u8(0b10100000)) == 5);
51 assert(@ctz(u8(0b10001010)) == 1);39 assert(@ctz(u8(0b10001010)) == 1);
52 assert(@ctz(u8(0b00000000)) == 8);40 assert(@ctz(u8(0b00000000)) == 8);
53}41}
5442
55fn modifyOperators() {43test "modifyOperators" {
56 @setFnTest(this);
57
58 var i : i32 = 0;44 var i : i32 = 0;
59 i += 5; assert(i == 5);45 i += 5; assert(i == 5);
60 i -= 2; assert(i == 3);46 i -= 2; assert(i == 3);
...@@ -70,9 +56,7 @@ fn modifyOperators() {...@@ -70,9 +56,7 @@ fn modifyOperators() {
70 i |= 3; assert(i == 7);56 i |= 3; assert(i == 7);
71}57}
7258
73fn threeExprInARow() {59test "threeExprInARow" {
74 @setFnTest(this);
75 testThreeExprInARow(false, true);
76}60}
77fn testThreeExprInARow(f: bool, t: bool) {61fn testThreeExprInARow(f: bool, t: bool) {
78 assertFalse(f || f || f);62 assertFalse(f || f || f);
...@@ -94,9 +78,7 @@ fn assertFalse(b: bool) {...@@ -94,9 +78,7 @@ fn assertFalse(b: bool) {
94}78}
9579
9680
97fn constNumberLiteral() {81test "constNumberLiteral" {
98 @setFnTest(this);
99
100 const one = 1;82 const one = 1;
101 const eleven = ten + one;83 const eleven = ten + one;
10284
...@@ -106,9 +88,7 @@ const ten = 10;...@@ -106,9 +88,7 @@ const ten = 10;
10688
10789
10890
109fn unsignedWrapping() {91test "unsignedWrapping" {
110 @setFnTest(this);
111
112 testUnsignedWrappingEval(@maxValue(u32));92 testUnsignedWrappingEval(@maxValue(u32));
113}93}
114fn testUnsignedWrappingEval(x: u32) {94fn testUnsignedWrappingEval(x: u32) {
...@@ -118,9 +98,7 @@ fn testUnsignedWrappingEval(x: u32) {...@@ -118,9 +98,7 @@ fn testUnsignedWrappingEval(x: u32) {
118 assert(orig == @maxValue(u32));98 assert(orig == @maxValue(u32));
119}99}
120100
121fn signedWrapping() {101test "signedWrapping" {
122 @setFnTest(this);
123
124 testSignedWrappingEval(@maxValue(i32));102 testSignedWrappingEval(@maxValue(i32));
125}103}
126fn testSignedWrappingEval(x: i32) {104fn testSignedWrappingEval(x: i32) {
...@@ -130,9 +108,7 @@ fn testSignedWrappingEval(x: i32) {...@@ -130,9 +108,7 @@ fn testSignedWrappingEval(x: i32) {
130 assert(max_val == @maxValue(i32));108 assert(max_val == @maxValue(i32));
131}109}
132110
133fn negationWrapping() {111test "negationWrapping" {
134 @setFnTest(this);
135
136 testNegationWrappingEval(@minValue(i16));112 testNegationWrappingEval(@minValue(i16));
137}113}
138fn testNegationWrappingEval(x: i16) {114fn testNegationWrappingEval(x: i16) {
...@@ -141,9 +117,7 @@ fn testNegationWrappingEval(x: i16) {...@@ -141,9 +117,7 @@ fn testNegationWrappingEval(x: i16) {
141 assert(neg == -32768);117 assert(neg == -32768);
142}118}
143119
144fn shlWrapping() {120test "shlWrapping" {
145 @setFnTest(this);
146
147 testShlWrappingEval(@maxValue(u16));121 testShlWrappingEval(@maxValue(u16));
148}122}
149fn testShlWrappingEval(x: u16) {123fn testShlWrappingEval(x: u16) {
...@@ -151,9 +125,7 @@ fn testShlWrappingEval(x: u16) {...@@ -151,9 +125,7 @@ fn testShlWrappingEval(x: u16) {
151 assert(shifted == 65534);125 assert(shifted == 65534);
152}126}
153127
154fn unsigned64BitDivision() {128test "unsigned64BitDivision" {
155 @setFnTest(this);
156
157 const result = div(1152921504606846976, 34359738365);129 const result = div(1152921504606846976, 34359738365);
158 assert(result.quotient == 33554432);130 assert(result.quotient == 33554432);
159 assert(result.remainder == 100663296);131 assert(result.remainder == 100663296);
...@@ -169,9 +141,7 @@ const DivResult = struct {...@@ -169,9 +141,7 @@ const DivResult = struct {
169 remainder: u64,141 remainder: u64,
170};142};
171143
172fn binaryNot() {144test "binaryNot" {
173 @setFnTest(this);
174
175 assert(comptime {~u16(0b1010101010101010) == 0b0101010101010101});145 assert(comptime {~u16(0b1010101010101010) == 0b0101010101010101});
176 assert(comptime {~u64(2147483647) == 18446744071562067968});146 assert(comptime {~u64(2147483647) == 18446744071562067968});
177 testBinaryNot(0b1010101010101010);147 testBinaryNot(0b1010101010101010);
...@@ -181,9 +151,7 @@ fn testBinaryNot(x: u16) {...@@ -181,9 +151,7 @@ fn testBinaryNot(x: u16) {
181 assert(~x == 0b0101010101010101);151 assert(~x == 0b0101010101010101);
182}152}
183153
184fn smallIntAddition() {154test "smallIntAddition" {
185 @setFnTest(this);
186
187 var x: @intType(false, 2) = 0;155 var x: @intType(false, 2) = 0;
188 assert(x == 0);156 assert(x == 0);
189157
...@@ -202,9 +170,7 @@ fn smallIntAddition() {...@@ -202,9 +170,7 @@ fn smallIntAddition() {
202 assert(result == 0);170 assert(result == 0);
203}171}
204172
205fn testFloatEquality() {173test "testFloatEquality" {
206 @setFnTest(this);
207
208 const x: f64 = 0.012;174 const x: f64 = 0.012;
209 const y: f64 = x + 1.0;175 const y: f64 = x + 1.0;
210176
test/cases/misc.zig+48-131
...@@ -5,23 +5,21 @@ const cstr = @import("std").cstr;...@@ -5,23 +5,21 @@ const cstr = @import("std").cstr;
5// normal comment5// normal comment
6/// this is a documentation comment6/// this is a documentation comment
7/// doc comment line 27/// doc comment line 2
8fn emptyFunctionWithComments() {8fn emptyFunctionWithComments() {}
9 @setFnTest(this);9
10test "emptyFunctionWithComments" {
11 emptyFunctionWithComments();
10}12}
1113
12export fn disabledExternFn() {14export fn disabledExternFn() {
13 @setFnVisible(this, false);15 @setFnVisible(this, false);
14}16}
1517
16fn callDisabledExternFn() {18test "callDisabledExternFn" {
17 @setFnTest(this);
18
19 disabledExternFn();19 disabledExternFn();
20}20}
2121
22fn intTypeBuiltin() {22test "intTypeBuiltin" {
23 @setFnTest(this);
24
25 assert(@intType(true, 8) == i8);23 assert(@intType(true, 8) == i8);
26 assert(@intType(true, 16) == i16);24 assert(@intType(true, 16) == i16);
27 assert(@intType(true, 32) == i32);25 assert(@intType(true, 32) == i32);
...@@ -55,9 +53,7 @@ const u63 = @intType(false, 63);...@@ -55,9 +53,7 @@ const u63 = @intType(false, 63);
55const i1 = @intType(true, 1);53const i1 = @intType(true, 1);
56const i63 = @intType(true, 63);54const i63 = @intType(true, 63);
5755
58fn minValueAndMaxValue() {56test "minValueAndMaxValue" {
59 @setFnTest(this);
60
61 assert(@maxValue(u1) == 1);57 assert(@maxValue(u1) == 1);
62 assert(@maxValue(u8) == 255);58 assert(@maxValue(u8) == 255);
63 assert(@maxValue(u16) == 65535);59 assert(@maxValue(u16) == 65535);
...@@ -86,9 +82,7 @@ fn minValueAndMaxValue() {...@@ -86,9 +82,7 @@ fn minValueAndMaxValue() {
86 assert(@minValue(i64) == -9223372036854775808);82 assert(@minValue(i64) == -9223372036854775808);
87}83}
8884
89fn maxValueType() {85test "maxValueType" {
90 @setFnTest(this);
91
92 // If the type of @maxValue(i32) was i32 then this implicit cast to86 // If the type of @maxValue(i32) was i32 then this implicit cast to
93 // u32 would not work. But since the value is a number literal,87 // u32 would not work. But since the value is a number literal,
94 // it works fine.88 // it works fine.
...@@ -96,8 +90,7 @@ fn maxValueType() {...@@ -96,8 +90,7 @@ fn maxValueType() {
96 assert(x == 2147483647);90 assert(x == 2147483647);
97}91}
9892
99fn shortCircuit() {93test "shortCircuit" {
100 @setFnTest(this);
101 testShortCircuit(false, true);94 testShortCircuit(false, true);
102}95}
10396
...@@ -128,18 +121,14 @@ fn testShortCircuit(f: bool, t: bool) {...@@ -128,18 +121,14 @@ fn testShortCircuit(f: bool, t: bool) {
128 assert(hit_4);121 assert(hit_4);
129}122}
130123
131fn truncate() {124test "truncate" {
132 @setFnTest(this);
133
134 assert(testTruncate(0x10fd) == 0xfd);125 assert(testTruncate(0x10fd) == 0xfd);
135}126}
136fn testTruncate(x: u32) -> u8 {127fn testTruncate(x: u32) -> u8 {
137 @truncate(u8, x)128 @truncate(u8, x)
138}129}
139130
140fn assignToIfVarPtr() {131test "assignToIfVarPtr" {
141 @setFnTest(this);
142
143 var maybe_bool: ?bool = true;132 var maybe_bool: ?bool = true;
144133
145 if (const *b ?= maybe_bool) {134 if (const *b ?= maybe_bool) {
...@@ -153,27 +142,21 @@ fn first4KeysOfHomeRow() -> []const u8 {...@@ -153,27 +142,21 @@ fn first4KeysOfHomeRow() -> []const u8 {
153 "aoeu"142 "aoeu"
154}143}
155144
156fn ReturnStringFromFunction() {145test "ReturnStringFromFunction" {
157 @setFnTest(this);
158
159 assert(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));146 assert(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
160}147}
161148
162const g1 : i32 = 1233 + 1;149const g1 : i32 = 1233 + 1;
163var g2 : i32 = 0;150var g2 : i32 = 0;
164151
165fn globalVariables() {152test "globalVariables" {
166 @setFnTest(this);
167
168 assert(g2 == 0);153 assert(g2 == 0);
169 g2 = g1;154 g2 = g1;
170 assert(g2 == 1234);155 assert(g2 == 1234);
171}156}
172157
173158
174fn memcpyAndMemsetIntrinsics() {159test "memcpyAndMemsetIntrinsics" {
175 @setFnTest(this);
176
177 var foo : [20]u8 = undefined;160 var foo : [20]u8 = undefined;
178 var bar : [20]u8 = undefined;161 var bar : [20]u8 = undefined;
179162
...@@ -183,16 +166,12 @@ fn memcpyAndMemsetIntrinsics() {...@@ -183,16 +166,12 @@ fn memcpyAndMemsetIntrinsics() {
183 if (bar[11] != 'A') @unreachable();166 if (bar[11] != 'A') @unreachable();
184}167}
185168
186fn builtinStaticEval() {169test "builtinStaticEval" {
187 @setFnTest(this);
188
189 const x : i32 = comptime {1 + 2 + 3};170 const x : i32 = comptime {1 + 2 + 3};
190 assert(x == comptime 6);171 assert(x == comptime 6);
191}172}
192173
193fn slicing() {174test "slicing" {
194 @setFnTest(this);
195
196 var array : [20]i32 = undefined;175 var array : [20]i32 = undefined;
197176
198 array[5] = 1234;177 array[5] = 1234;
...@@ -209,9 +188,7 @@ fn slicing() {...@@ -209,9 +188,7 @@ fn slicing() {
209}188}
210189
211190
212fn constantEqualFunctionPointers() {191test "constantEqualFunctionPointers" {
213 @setFnTest(this);
214
215 const alias = emptyFn;192 const alias = emptyFn;
216 assert(comptime {emptyFn == alias});193 assert(comptime {emptyFn == alias});
217}194}
...@@ -219,27 +196,19 @@ fn constantEqualFunctionPointers() {...@@ -219,27 +196,19 @@ fn constantEqualFunctionPointers() {
219fn emptyFn() {}196fn emptyFn() {}
220197
221198
222fn hexEscape() {199test "hexEscape" {
223 @setFnTest(this);
224
225 assert(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));200 assert(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));
226}201}
227202
228fn stringConcatenation() {203test "stringConcatenation" {
229 @setFnTest(this);
230
231 assert(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));204 assert(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
232}205}
233206
234fn arrayMultOperator() {207test "arrayMultOperator" {
235 @setFnTest(this);
236
237 assert(mem.eql(u8, "ab" ** 5, "ababababab"));208 assert(mem.eql(u8, "ab" ** 5, "ababababab"));
238}209}
239210
240fn stringEscapes() {211test "stringEscapes" {
241 @setFnTest(this);
242
243 assert(mem.eql(u8, "\"", "\x22"));212 assert(mem.eql(u8, "\"", "\x22"));
244 assert(mem.eql(u8, "\'", "\x27"));213 assert(mem.eql(u8, "\'", "\x27"));
245 assert(mem.eql(u8, "\n", "\x0a"));214 assert(mem.eql(u8, "\n", "\x0a"));
...@@ -249,9 +218,7 @@ fn stringEscapes() {...@@ -249,9 +218,7 @@ fn stringEscapes() {
249 assert(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69"));218 assert(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69"));
250}219}
251220
252fn multilineString() {221test "multilineString" {
253 @setFnTest(this);
254
255 const s1 =222 const s1 =
256 \\one223 \\one
257 \\two)224 \\two)
...@@ -261,9 +228,7 @@ fn multilineString() {...@@ -261,9 +228,7 @@ fn multilineString() {
261 assert(mem.eql(u8, s1, s2));228 assert(mem.eql(u8, s1, s2));
262}229}
263230
264fn multilineCString() {231test "multilineCString" {
265 @setFnTest(this);
266
267 const s1 =232 const s1 =
268 c\\one233 c\\one
269 c\\two)234 c\\two)
...@@ -274,9 +239,7 @@ fn multilineCString() {...@@ -274,9 +239,7 @@ fn multilineCString() {
274}239}
275240
276241
277fn typeEquality() {242test "typeEquality" {
278 @setFnTest(this);
279
280 assert(&const u8 != &u8);243 assert(&const u8 != &u8);
281}244}
282245
...@@ -284,22 +247,17 @@ fn typeEquality() {...@@ -284,22 +247,17 @@ fn typeEquality() {
284const global_a: i32 = 1234;247const global_a: i32 = 1234;
285const global_b: &const i32 = &global_a;248const global_b: &const i32 = &global_a;
286const global_c: &const f32 = (&const f32)(global_b);249const global_c: &const f32 = (&const f32)(global_b);
287fn compileTimeGlobalReinterpret() {250test "compileTimeGlobalReinterpret" {
288 @setFnTest(this);
289 const d = (&const i32)(global_c);251 const d = (&const i32)(global_c);
290 assert(*d == 1234);252 assert(*d == 1234);
291}253}
292254
293fn explicitCastMaybePointers() {255test "explicitCastMaybePointers" {
294 @setFnTest(this);
295
296 const a: ?&i32 = undefined;256 const a: ?&i32 = undefined;
297 const b: ?&f32 = (?&f32)(a);257 const b: ?&f32 = (?&f32)(a);
298}258}
299259
300fn genericMallocFree() {260test "genericMallocFree" {
301 @setFnTest(this);
302
303 const a = %%memAlloc(u8, 10);261 const a = %%memAlloc(u8, 10);
304 memFree(u8, a);262 memFree(u8, a);
305}263}
...@@ -310,9 +268,7 @@ fn memAlloc(comptime T: type, n: usize) -> %[]T {...@@ -310,9 +268,7 @@ fn memAlloc(comptime T: type, n: usize) -> %[]T {
310fn memFree(comptime T: type, memory: []T) { }268fn memFree(comptime T: type, memory: []T) { }
311269
312270
313fn castUndefined() {271test "castUndefined" {
314 @setFnTest(this);
315
316 const array: [100]u8 = undefined;272 const array: [100]u8 = undefined;
317 const slice = ([]const u8)(array);273 const slice = ([]const u8)(array);
318 testCastUndefined(slice);274 testCastUndefined(slice);
...@@ -320,9 +276,7 @@ fn castUndefined() {...@@ -320,9 +276,7 @@ fn castUndefined() {
320fn testCastUndefined(x: []const u8) {}276fn testCastUndefined(x: []const u8) {}
321277
322278
323fn castSmallUnsignedToLargerSigned() {279test "castSmallUnsignedToLargerSigned" {
324 @setFnTest(this);
325
326 assert(castSmallUnsignedToLargerSigned1(200) == i16(200));280 assert(castSmallUnsignedToLargerSigned1(200) == i16(200));
327 assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999));281 assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
328}282}
...@@ -330,9 +284,7 @@ fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x }...@@ -330,9 +284,7 @@ fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x }
330fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x }284fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x }
331285
332286
333fn implicitCastAfterUnreachable() {287test "implicitCastAfterUnreachable" {
334 @setFnTest(this);
335
336 assert(outer() == 1234);288 assert(outer() == 1234);
337}289}
338fn inner() -> i32 { 1234 }290fn inner() -> i32 { 1234 }
...@@ -341,9 +293,7 @@ fn outer() -> i64 {...@@ -341,9 +293,7 @@ fn outer() -> i64 {
341}293}
342294
343295
344fn pointerDereferencing() {296test "pointerDereferencing" {
345 @setFnTest(this);
346
347 var x = i32(3);297 var x = i32(3);
348 const y = &x;298 const y = &x;
349299
...@@ -353,9 +303,7 @@ fn pointerDereferencing() {...@@ -353,9 +303,7 @@ fn pointerDereferencing() {
353 assert(*y == 4);303 assert(*y == 4);
354}304}
355305
356fn callResultOfIfElseExpression() {306test "callResultOfIfElseExpression" {
357 @setFnTest(this);
358
359 assert(mem.eql(u8, f2(true), "a"));307 assert(mem.eql(u8, f2(true), "a"));
360 assert(mem.eql(u8, f2(false), "b"));308 assert(mem.eql(u8, f2(false), "b"));
361}309}
...@@ -366,9 +314,7 @@ fn fA() -> []const u8 { "a" }...@@ -366,9 +314,7 @@ fn fA() -> []const u8 { "a" }
366fn fB() -> []const u8 { "b" }314fn fB() -> []const u8 { "b" }
367315
368316
369fn constExpressionEvalHandlingOfVariables() {317test "constExpressionEvalHandlingOfVariables" {
370 @setFnTest(this);
371
372 var x = true;318 var x = true;
373 while (x) {319 while (x) {
374 x = false;320 x = false;
...@@ -377,9 +323,7 @@ fn constExpressionEvalHandlingOfVariables() {...@@ -377,9 +323,7 @@ fn constExpressionEvalHandlingOfVariables() {
377323
378324
379325
380fn constantEnumInitializationWithDifferingSizes() {326test "constantEnumInitializationWithDifferingSizes" {
381 @setFnTest(this);
382
383 test3_1(test3_foo);327 test3_1(test3_foo);
384 test3_2(test3_bar);328 test3_2(test3_bar);
385}329}
...@@ -413,18 +357,14 @@ fn test3_2(f: Test3Foo) {...@@ -413,18 +357,14 @@ fn test3_2(f: Test3Foo) {
413}357}
414358
415359
416fn characterLiterals() {360test "characterLiterals" {
417 @setFnTest(this);
418
419 assert('\'' == single_quote);361 assert('\'' == single_quote);
420}362}
421const single_quote = '\'';363const single_quote = '\'';
422364
423365
424366
425fn takeAddressOfParameter() {367test "takeAddressOfParameter" {
426 @setFnTest(this);
427
428 testTakeAddressOfParameter(12.34);368 testTakeAddressOfParameter(12.34);
429}369}
430fn testTakeAddressOfParameter(f: f32) {370fn testTakeAddressOfParameter(f: f32) {
...@@ -433,9 +373,7 @@ fn testTakeAddressOfParameter(f: f32) {...@@ -433,9 +373,7 @@ fn testTakeAddressOfParameter(f: f32) {
433}373}
434374
435375
436fn intToPtrCast() {376test "intToPtrCast" {
437 @setFnTest(this);
438
439 const x = isize(13);377 const x = isize(13);
440 const y = (&u8)(x);378 const y = (&u8)(x);
441 const z = usize(y);379 const z = usize(y);
...@@ -443,9 +381,7 @@ fn intToPtrCast() {...@@ -443,9 +381,7 @@ fn intToPtrCast() {
443}381}
444382
445383
446fn pointerComparison() {384test "pointerComparison" {
447 @setFnTest(this);
448
449 const a = ([]const u8)("a");385 const a = ([]const u8)("a");
450 const b = &a;386 const b = &a;
451 assert(ptrEql(b, b));387 assert(ptrEql(b, b));
...@@ -455,9 +391,7 @@ fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool {...@@ -455,9 +391,7 @@ fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool {
455}391}
456392
457393
458fn cStringConcatenation() {394test "cStringConcatenation" {
459 @setFnTest(this);
460
461 const a = c"OK" ++ c" IT " ++ c"WORKED";395 const a = c"OK" ++ c" IT " ++ c"WORKED";
462 const b = c"OK IT WORKED";396 const b = c"OK IT WORKED";
463397
...@@ -470,9 +404,7 @@ fn cStringConcatenation() {...@@ -470,9 +404,7 @@ fn cStringConcatenation() {
470 assert(b[len] == 0);404 assert(b[len] == 0);
471}405}
472406
473fn castSliceToU8Slice() {407test "castSliceToU8Slice" {
474 @setFnTest(this);
475
476 assert(@sizeOf(i32) == 4);408 assert(@sizeOf(i32) == 4);
477 var big_thing_array = []i32{1, 2, 3, 4};409 var big_thing_array = []i32{1, 2, 3, 4};
478 const big_thing_slice: []i32 = big_thing_array[0...];410 const big_thing_slice: []i32 = big_thing_array[0...];
...@@ -492,9 +424,7 @@ fn castSliceToU8Slice() {...@@ -492,9 +424,7 @@ fn castSliceToU8Slice() {
492 assert(bytes[11] == @maxValue(u8));424 assert(bytes[11] == @maxValue(u8));
493}425}
494426
495fn pointerToVoidReturnType() {427test "pointerToVoidReturnType" {
496 @setFnTest(this);
497
498 %%testPointerToVoidReturnType();428 %%testPointerToVoidReturnType();
499}429}
500fn testPointerToVoidReturnType() -> %void {430fn testPointerToVoidReturnType() -> %void {
...@@ -507,17 +437,14 @@ fn testPointerToVoidReturnType2() -> &const void {...@@ -507,17 +437,14 @@ fn testPointerToVoidReturnType2() -> &const void {
507}437}
508438
509439
510fn nonConstPtrToAliasedType() {440test "nonConstPtrToAliasedType" {
511 @setFnTest(this);
512 const int = i32;441 const int = i32;
513 assert(?&int == ?&i32);442 assert(?&int == ?&i32);
514}443}
515444
516445
517446
518fn array2DConstDoublePtr() {447test "array2DConstDoublePtr" {
519 @setFnTest(this);
520
521 const rect_2d_vertexes = [][1]f32 {448 const rect_2d_vertexes = [][1]f32 {
522 []f32{1.0},449 []f32{1.0},
523 []f32{2.0},450 []f32{2.0},
...@@ -530,9 +457,7 @@ fn testArray2DConstDoublePtr(ptr: &const f32) {...@@ -530,9 +457,7 @@ fn testArray2DConstDoublePtr(ptr: &const f32) {
530 assert(ptr[1] == 2.0);457 assert(ptr[1] == 2.0);
531}458}
532459
533fn isInteger() {460test "isInteger" {
534 @setFnTest(this);
535
536 comptime {461 comptime {
537 assert(@isInteger(i8));462 assert(@isInteger(i8));
538 assert(@isInteger(u8));463 assert(@isInteger(u8));
...@@ -545,9 +470,7 @@ fn isInteger() {...@@ -545,9 +470,7 @@ fn isInteger() {
545 }470 }
546}471}
547472
548fn isFloat() {473test "isFloat" {
549 @setFnTest(this);
550
551 comptime {474 comptime {
552 assert(!@isFloat(i8));475 assert(!@isFloat(i8));
553 assert(!@isFloat(u8));476 assert(!@isFloat(u8));
...@@ -560,9 +483,7 @@ fn isFloat() {...@@ -560,9 +483,7 @@ fn isFloat() {
560 }483 }
561}484}
562485
563fn canImplicitCast() {486test "canImplicitCast" {
564 @setFnTest(this);
565
566 comptime {487 comptime {
567 assert(@canImplicitCast(i64, i32(3)));488 assert(@canImplicitCast(i64, i32(3)));
568 assert(!@canImplicitCast(i32, f32(1.234)));489 assert(!@canImplicitCast(i32, f32(1.234)));
...@@ -570,18 +491,14 @@ fn canImplicitCast() {...@@ -570,18 +491,14 @@ fn canImplicitCast() {
570 }491 }
571}492}
572493
573fn typeName() {494test "typeName" {
574 @setFnTest(this);
575
576 comptime {495 comptime {
577 assert(mem.eql(u8, @typeName(i64), "i64"));496 assert(mem.eql(u8, @typeName(i64), "i64"));
578 assert(mem.eql(u8, @typeName(&usize), "&usize"));497 assert(mem.eql(u8, @typeName(&usize), "&usize"));
579 }498 }
580}499}
581500
582fn volatileLoadAndStore() {501test "volatileLoadAndStore" {
583 @setFnTest(this);
584
585 var number: i32 = 1234;502 var number: i32 = 1234;
586 const ptr = &volatile number;503 const ptr = &volatile number;
587 *ptr += 1;504 *ptr += 1;
test/cases/namespace_depends_on_compile_var/index.zig+1-3
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn namespaceDependsOnCompileVar() {3test "namespaceDependsOnCompileVar" {
4 @setFnTest(this);
5
6 if (some_namespace.a_bool) {4 if (some_namespace.a_bool) {
7 assert(some_namespace.a_bool);5 assert(some_namespace.a_bool);
8 } else {6 } else {
test/cases/null.zig+8-24
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn nullableType() {3test "nullableType" {
4 @setFnTest(this);
5
6 const x : ?bool = @generatedCode(true);4 const x : ?bool = @generatedCode(true);
75
8 if (const y ?= x) {6 if (const y ?= x) {
...@@ -28,9 +26,7 @@ fn nullableType() {...@@ -28,9 +26,7 @@ fn nullableType() {
28 assert(num == 13);26 assert(num == 13);
29}27}
3028
31fn assignToIfVarPtr() {29test "assignToIfVarPtr" {
32 @setFnTest(this);
33
34 var maybe_bool: ?bool = true;30 var maybe_bool: ?bool = true;
3531
36 if (const *b ?= maybe_bool) {32 if (const *b ?= maybe_bool) {
...@@ -40,17 +36,13 @@ fn assignToIfVarPtr() {...@@ -40,17 +36,13 @@ fn assignToIfVarPtr() {
40 assert(??maybe_bool == false);36 assert(??maybe_bool == false);
41}37}
4238
43fn rhsMaybeUnwrapReturn() {39test "rhsMaybeUnwrapReturn" {
44 @setFnTest(this);
45
46 const x: ?bool = @generatedCode(true);40 const x: ?bool = @generatedCode(true);
47 const y = x ?? return;41 const y = x ?? return;
48}42}
4943
5044
51fn maybeReturn() {45test "maybeReturn" {
52 @setFnTest(this);
53
54 maybeReturnImpl();46 maybeReturnImpl();
55 comptime maybeReturnImpl();47 comptime maybeReturnImpl();
56}48}
...@@ -67,9 +59,7 @@ fn foo(x: ?i32) -> ?bool {...@@ -67,9 +59,7 @@ fn foo(x: ?i32) -> ?bool {
67}59}
6860
6961
70fn ifVarMaybePointer() {62test "ifVarMaybePointer" {
71 @setFnTest(this);
72
73 assert(shouldBeAPlus1(Particle {.a = 14, .b = 1, .c = 1, .d = 1}) == 15);63 assert(shouldBeAPlus1(Particle {.a = 14, .b = 1, .c = 1, .d = 1}) == 15);
74}64}
75fn shouldBeAPlus1(p: Particle) -> u64 {65fn shouldBeAPlus1(p: Particle) -> u64 {
...@@ -90,9 +80,7 @@ const Particle = struct {...@@ -90,9 +80,7 @@ const Particle = struct {
90};80};
9181
9282
93fn nullLiteralOutsideFunction() {83test "nullLiteralOutsideFunction" {
94 @setFnTest(this);
95
96 const is_null = here_is_a_null_literal.context == null;84 const is_null = here_is_a_null_literal.context == null;
97 assert(is_null);85 assert(is_null);
9886
...@@ -107,9 +95,7 @@ const here_is_a_null_literal = SillyStruct {...@@ -107,9 +95,7 @@ const here_is_a_null_literal = SillyStruct {
107};95};
10896
10997
110fn testNullRuntime() {98test "testNullRuntime" {
111 @setFnTest(this);
112
113 testTestNullRuntime(null);99 testTestNullRuntime(null);
114}100}
115fn testTestNullRuntime(x: ?i32) {101fn testTestNullRuntime(x: ?i32) {
...@@ -117,9 +103,7 @@ fn testTestNullRuntime(x: ?i32) {...@@ -117,9 +103,7 @@ fn testTestNullRuntime(x: ?i32) {
117 assert(!(x != null));103 assert(!(x != null));
118}104}
119105
120fn nullableVoid() {106test "nullableVoid" {
121 @setFnTest(this);
122
123 nullableVoidImpl();107 nullableVoidImpl();
124 comptime nullableVoidImpl();108 comptime nullableVoidImpl();
125}109}
test/cases/pub_enum/index.zig+2-6
...@@ -1,17 +1,13 @@...@@ -1,17 +1,13 @@
1const other = @import("cases/pub_enum/other.zig");1const other = @import("cases/pub_enum/other.zig");
2const assert = @import("std").debug.assert;2const assert = @import("std").debug.assert;
33
4fn pubEnum() {4test "pubEnum" {
5 @setFnTest(this);
6
7 pubEnumTest(other.APubEnum.Two);5 pubEnumTest(other.APubEnum.Two);
8}6}
9fn pubEnumTest(foo: other.APubEnum) {7fn pubEnumTest(foo: other.APubEnum) {
10 assert(foo == other.APubEnum.Two);8 assert(foo == other.APubEnum.Two);
11}9}
1210
13fn castWithImportedSymbol() {11test "castWithImportedSymbol" {
14 @setFnTest(this);
15
16 assert(other.size_t(42) == 42);12 assert(other.size_t(42) == 42);
17}13}
test/cases/sizeof_and_typeof.zig+1-3
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn sizeofAndTypeOf() {3test "sizeofAndTypeOf" {
4 @setFnTest(this);
5
6 const y: @typeOf(x) = 120;4 const y: @typeOf(x) = 120;
7 assert(@sizeOf(@typeOf(y)) == 2);5 assert(@sizeOf(@typeOf(y)) == 2);
8}6}
test/cases/struct.zig+22-56
...@@ -5,27 +5,25 @@ const StructWithNoFields = struct {...@@ -5,27 +5,25 @@ const StructWithNoFields = struct {
5};5};
6const empty_global_instance = StructWithNoFields {};6const empty_global_instance = StructWithNoFields {};
77
8fn callStructStaticMethod() {8test "callStructStaticMethod" {
9 @setFnTest(this);
10 const result = StructWithNoFields.add(3, 4);9 const result = StructWithNoFields.add(3, 4);
11 assert(result == 7);10 assert(result == 7);
12}11}
1312
13test "returnEmptyStructInstance" {
14 _ = returnEmptyStructInstance();
15}
14fn returnEmptyStructInstance() -> StructWithNoFields {16fn returnEmptyStructInstance() -> StructWithNoFields {
15 @setFnTest(this);
16 return empty_global_instance;17 return empty_global_instance;
17}18}
1819
19const should_be_11 = StructWithNoFields.add(5, 6);20const should_be_11 = StructWithNoFields.add(5, 6);
2021
21fn invokeStaticMethodInGlobalScope() {22test "invokeStaticMethodInGlobalScope" {
22 @setFnTest(this);
23 assert(should_be_11 == 11);23 assert(should_be_11 == 11);
24}24}
2525
26fn voidStructFields() {26test "voidStructFields" {
27 @setFnTest(this);
28
29 const foo = VoidStructFieldsFoo {27 const foo = VoidStructFieldsFoo {
30 .a = void{},28 .a = void{},
31 .b = 1,29 .b = 1,
...@@ -41,9 +39,7 @@ const VoidStructFieldsFoo = struct {...@@ -41,9 +39,7 @@ const VoidStructFieldsFoo = struct {
41};39};
4240
4341
44pub fn structs() {42test "fn" {
45 @setFnTest(this);
46
47 var foo: StructFoo = undefined;43 var foo: StructFoo = undefined;
48 @memset((&u8)(&foo), 0, @sizeOf(StructFoo));44 @memset((&u8)(&foo), 0, @sizeOf(StructFoo));
49 foo.a += 1;45 foo.a += 1;
...@@ -74,9 +70,7 @@ const Val = struct {...@@ -74,9 +70,7 @@ const Val = struct {
74 x: i32,70 x: i32,
75};71};
7672
77fn structPointToSelf() {73test "structPointToSelf" {
78 @setFnTest(this);
79
80 var root : Node = undefined;74 var root : Node = undefined;
81 root.val.x = 1;75 root.val.x = 1;
8276
...@@ -89,9 +83,7 @@ fn structPointToSelf() {...@@ -89,9 +83,7 @@ fn structPointToSelf() {
89 assert(node.next.next.next.val.x == 1);83 assert(node.next.next.next.val.x == 1);
90}84}
9185
92fn structByvalAssign() {86test "structByvalAssign" {
93 @setFnTest(this);
94
95 var foo1 : StructFoo = undefined;87 var foo1 : StructFoo = undefined;
96 var foo2 : StructFoo = undefined;88 var foo2 : StructFoo = undefined;
9789
...@@ -108,9 +100,7 @@ fn structInitializer() {...@@ -108,9 +100,7 @@ fn structInitializer() {
108}100}
109101
110102
111fn fnCallOfStructField() {103test "fnCallOfStructField" {
112 @setFnTest(this);
113
114 assert(callStructField(Foo {.ptr = aFunc,}) == 13);104 assert(callStructField(Foo {.ptr = aFunc,}) == 13);
115}105}
116106
...@@ -125,9 +115,7 @@ fn callStructField(foo: Foo) -> i32 {...@@ -125,9 +115,7 @@ fn callStructField(foo: Foo) -> i32 {
125}115}
126116
127117
128fn storeMemberFunctionInVariable() {118test "storeMemberFunctionInVariable" {
129 @setFnTest(this);
130
131 const instance = MemberFnTestFoo { .x = 1234, };119 const instance = MemberFnTestFoo { .x = 1234, };
132 const memberFn = MemberFnTestFoo.member;120 const memberFn = MemberFnTestFoo.member;
133 const result = memberFn(instance);121 const result = memberFn(instance);
...@@ -139,17 +127,13 @@ const MemberFnTestFoo = struct {...@@ -139,17 +127,13 @@ const MemberFnTestFoo = struct {
139};127};
140128
141129
142fn callMemberFunctionDirectly() {130test "callMemberFunctionDirectly" {
143 @setFnTest(this);
144
145 const instance = MemberFnTestFoo { .x = 1234, };131 const instance = MemberFnTestFoo { .x = 1234, };
146 const result = MemberFnTestFoo.member(instance);132 const result = MemberFnTestFoo.member(instance);
147 assert(result == 1234);133 assert(result == 1234);
148}134}
149135
150fn memberFunctions() {136test "memberFunctions" {
151 @setFnTest(this);
152
153 const r = MemberFnRand {.seed = 1234};137 const r = MemberFnRand {.seed = 1234};
154 assert(r.getSeed() == 1234);138 assert(r.getSeed() == 1234);
155}139}
...@@ -160,9 +144,7 @@ const MemberFnRand = struct {...@@ -160,9 +144,7 @@ const MemberFnRand = struct {
160 }144 }
161};145};
162146
163fn returnStructByvalFromFunction() {147test "returnStructByvalFromFunction" {
164 @setFnTest(this);
165
166 const bar = makeBar(1234, 5678);148 const bar = makeBar(1234, 5678);
167 assert(bar.y == 5678);149 assert(bar.y == 5678);
168}150}
...@@ -177,9 +159,7 @@ fn makeBar(x: i32, y: i32) -> Bar {...@@ -177,9 +159,7 @@ fn makeBar(x: i32, y: i32) -> Bar {
177 }159 }
178}160}
179161
180fn emptyStructMethodCall() {162test "emptyStructMethodCall" {
181 @setFnTest(this);
182
183 const es = EmptyStruct{};163 const es = EmptyStruct{};
184 assert(es.method() == 1234);164 assert(es.method() == 1234);
185}165}
...@@ -190,9 +170,7 @@ const EmptyStruct = struct {...@@ -190,9 +170,7 @@ const EmptyStruct = struct {
190};170};
191171
192172
193fn returnEmptyStructFromFn() {173test "returnEmptyStructFromFn" {
194 @setFnTest(this);
195
196 _ = testReturnEmptyStructFromFn();174 _ = testReturnEmptyStructFromFn();
197}175}
198const EmptyStruct2 = struct {};176const EmptyStruct2 = struct {};
...@@ -200,9 +178,7 @@ fn testReturnEmptyStructFromFn() -> EmptyStruct2 {...@@ -200,9 +178,7 @@ fn testReturnEmptyStructFromFn() -> EmptyStruct2 {
200 EmptyStruct2 {}178 EmptyStruct2 {}
201}179}
202180
203fn passSliceOfEmptyStructToFn() {181test "passSliceOfEmptyStructToFn" {
204 @setFnTest(this);
205
206 assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1);182 assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1);
207}183}
208fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) -> usize {184fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) -> usize {
...@@ -214,9 +190,7 @@ const APackedStruct = packed struct {...@@ -214,9 +190,7 @@ const APackedStruct = packed struct {
214 y: u8,190 y: u8,
215};191};
216192
217fn packedStruct() {193test "packedStruct" {
218 @setFnTest(this);
219
220 var foo = APackedStruct {194 var foo = APackedStruct {
221 .x = 1,195 .x = 1,
222 .y = 2,196 .y = 2,
...@@ -242,9 +216,7 @@ const bit_field_1 = BitField1 {...@@ -242,9 +216,7 @@ const bit_field_1 = BitField1 {
242 .c = 3,216 .c = 3,
243};217};
244218
245fn bitFieldAccess() {219test "bitFieldAccess" {
246 @setFnTest(this);
247
248 var data = bit_field_1;220 var data = bit_field_1;
249 assert(getA(&data) == 1);221 assert(getA(&data) == 1);
250 assert(getB(&data) == 2);222 assert(getB(&data) == 2);
...@@ -282,9 +254,7 @@ const Foo96Bits = packed struct {...@@ -282,9 +254,7 @@ const Foo96Bits = packed struct {
282 d: u24,254 d: u24,
283};255};
284256
285fn packedStruct24Bits() {257test "packedStruct24Bits" {
286 @setFnTest(this);
287
288 comptime {258 comptime {
289 assert(@sizeOf(Foo24Bits) == 3);259 assert(@sizeOf(Foo24Bits) == 3);
290 assert(@sizeOf(Foo96Bits) == 12);260 assert(@sizeOf(Foo96Bits) == 12);
...@@ -327,9 +297,7 @@ const FooArray24Bits = packed struct {...@@ -327,9 +297,7 @@ const FooArray24Bits = packed struct {
327 c: u16,297 c: u16,
328};298};
329299
330fn packedArray24Bits() {300test "packedArray24Bits" {
331 @setFnTest(this);
332
333 comptime {301 comptime {
334 assert(@sizeOf([9]Foo24Bits) == 9 * 3);302 assert(@sizeOf([9]Foo24Bits) == 9 * 3);
335 assert(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2);303 assert(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2);
...@@ -379,9 +347,7 @@ const FooArrayOfAligned = packed struct {...@@ -379,9 +347,7 @@ const FooArrayOfAligned = packed struct {
379 a: [2]FooStructAligned,347 a: [2]FooStructAligned,
380};348};
381349
382fn alignedArrayOfPackedStruct() {350test "alignedArrayOfPackedStruct" {
383 @setFnTest(this);
384
385 comptime {351 comptime {
386 assert(@sizeOf(FooStructAligned) == 2);352 assert(@sizeOf(FooStructAligned) == 2);
387 assert(@sizeOf(FooArrayOfAligned) == 2 * 2);353 assert(@sizeOf(FooArrayOfAligned) == 2 * 2);
test/cases/struct_contains_slice_of_itself.zig+1-3
...@@ -5,9 +5,7 @@ const Node = struct {...@@ -5,9 +5,7 @@ const Node = struct {
5 children: []Node,5 children: []Node,
6};6};
77
8fn structContainsSliceOfItself() {8test "structContainsSliceOfItself" {
9 @setFnTest(this);
10
11 var nodes = []Node {9 var nodes = []Node {
12 Node {10 Node {
13 .payload = 1,11 .payload = 1,
test/cases/switch.zig+8-24
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn switchWithNumbers() {3test "switchWithNumbers" {
4 @setFnTest(this);
5
6 testSwitchWithNumbers(13);4 testSwitchWithNumbers(13);
7}5}
86
...@@ -15,9 +13,7 @@ fn testSwitchWithNumbers(x: u32) {...@@ -15,9 +13,7 @@ fn testSwitchWithNumbers(x: u32) {
15 assert(result);13 assert(result);
16}14}
1715
18fn switchWithAllRanges() {16test "switchWithAllRanges" {
19 @setFnTest(this);
20
21 assert(testSwitchWithAllRanges(50, 3) == 1);17 assert(testSwitchWithAllRanges(50, 3) == 1);
22 assert(testSwitchWithAllRanges(101, 0) == 2);18 assert(testSwitchWithAllRanges(101, 0) == 2);
23 assert(testSwitchWithAllRanges(300, 5) == 3);19 assert(testSwitchWithAllRanges(300, 5) == 3);
...@@ -33,9 +29,7 @@ fn testSwitchWithAllRanges(x: u32, y: u32) -> u32 {...@@ -33,9 +29,7 @@ fn testSwitchWithAllRanges(x: u32, y: u32) -> u32 {
33 }29 }
34}30}
3531
36fn implicitComptimeSwitch() {32test "implicitComptimeSwitch" {
37 @setFnTest(this);
38
39 const x = 3 + 4;33 const x = 3 + 4;
40 const result = switch (x) {34 const result = switch (x) {
41 3 => 10,35 3 => 10,
...@@ -50,9 +44,7 @@ fn implicitComptimeSwitch() {...@@ -50,9 +44,7 @@ fn implicitComptimeSwitch() {
50 }44 }
51}45}
5246
53fn switchOnEnum() {47test "switchOnEnum" {
54 @setFnTest(this);
55
56 const fruit = Fruit.Orange;48 const fruit = Fruit.Orange;
57 nonConstSwitchOnEnum(fruit);49 nonConstSwitchOnEnum(fruit);
58}50}
...@@ -70,9 +62,7 @@ fn nonConstSwitchOnEnum(fruit: Fruit) {...@@ -70,9 +62,7 @@ fn nonConstSwitchOnEnum(fruit: Fruit) {
70}62}
7163
7264
73fn switchStatement() {65test "switchStatement" {
74 @setFnTest(this);
75
76 nonConstSwitch(SwitchStatmentFoo.C);66 nonConstSwitch(SwitchStatmentFoo.C);
77}67}
78fn nonConstSwitch(foo: SwitchStatmentFoo) {68fn nonConstSwitch(foo: SwitchStatmentFoo) {
...@@ -92,9 +82,7 @@ const SwitchStatmentFoo = enum {...@@ -92,9 +82,7 @@ const SwitchStatmentFoo = enum {
92};82};
9383
9484
95fn switchProngWithVar() {85test "switchProngWithVar" {
96 @setFnTest(this);
97
98 switchProngWithVarFn(SwitchProngWithVarEnum.One {13});86 switchProngWithVarFn(SwitchProngWithVarEnum.One {13});
99 switchProngWithVarFn(SwitchProngWithVarEnum.Two {13.0});87 switchProngWithVarFn(SwitchProngWithVarEnum.Two {13.0});
100 switchProngWithVarFn(SwitchProngWithVarEnum.Meh);88 switchProngWithVarFn(SwitchProngWithVarEnum.Meh);
...@@ -119,9 +107,7 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) {...@@ -119,9 +107,7 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) {
119}107}
120108
121109
122fn switchWithMultipleExpressions() {110test "switchWithMultipleExpressions" {
123 @setFnTest(this);
124
125 const x = switch (returnsFive()) {111 const x = switch (returnsFive()) {
126 1, 2, 3 => 1,112 1, 2, 3 => 1,
127 4, 5, 6 => 2,113 4, 5, 6 => 2,
...@@ -149,8 +135,6 @@ fn returnsFalse() -> bool {...@@ -149,8 +135,6 @@ fn returnsFalse() -> bool {
149 Number.Three => |x| return x > 12.34,135 Number.Three => |x| return x > 12.34,
150 }136 }
151}137}
152fn switchOnConstEnumWithVar() {138test "switchOnConstEnumWithVar" {
153 @setFnTest(this);
154
155 assert(!returnsFalse());139 assert(!returnsFalse());
156}140}
test/cases/switch_prong_err_enum.zig+1-3
...@@ -21,9 +21,7 @@ fn doThing(form_id: u64) -> %FormValue {...@@ -21,9 +21,7 @@ fn doThing(form_id: u64) -> %FormValue {
21 }21 }
22}22}
2323
24fn switchProngReturnsErrorEnum() {24test "switchProngReturnsErrorEnum" {
25 @setFnTest(this);
26
27 %%doThing(17);25 %%doThing(17);
28 assert(read_count == 1);26 assert(read_count == 1);
29}27}
test/cases/switch_prong_implicit_cast.zig+1-3
...@@ -15,9 +15,7 @@ fn foo(id: u64) -> %FormValue {...@@ -15,9 +15,7 @@ fn foo(id: u64) -> %FormValue {
15 }15 }
16}16}
1717
18fn switchProngImplicitCast() {18test "switchProngImplicitCast" {
19 @setFnTest(this);
20
21 const result = switch (%%foo(2)) {19 const result = switch (%%foo(2)) {
22 FormValue.One => false,20 FormValue.One => false,
23 FormValue.Two => |x| x,21 FormValue.Two => |x| x,
test/cases/this.zig+3-9
...@@ -28,15 +28,11 @@ fn factorial(x: i32) -> i32 {...@@ -28,15 +28,11 @@ fn factorial(x: i32) -> i32 {
28 }28 }
29}29}
3030
31fn thisReferToModuleCallPrivateFn() {31test "thisReferToModuleCallPrivateFn" {
32 @setFnTest(this);
33
34 assert(module.add(1, 2) == 3);32 assert(module.add(1, 2) == 3);
35}33}
3634
37fn thisReferToContainer() {35test "thisReferToContainer" {
38 @setFnTest(this);
39
40 var pt = Point(i32) {36 var pt = Point(i32) {
41 .x = 12,37 .x = 12,
42 .y = 34,38 .y = 34,
...@@ -46,8 +42,6 @@ fn thisReferToContainer() {...@@ -46,8 +42,6 @@ fn thisReferToContainer() {
46 assert(pt.y == 35);42 assert(pt.y == 35);
47}43}
4844
49fn thisReferToFn() {45test "thisReferToFn" {
50 @setFnTest(this);
51
52 assert(factorial(5) == 120);46 assert(factorial(5) == 120);
53}47}
test/cases/try.zig+2-6
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn tryOnErrorUnion() {3test "tryOnErrorUnion" {
4 @setFnTest(this);
5
6 tryOnErrorUnionImpl();4 tryOnErrorUnionImpl();
7 comptime tryOnErrorUnionImpl();5 comptime tryOnErrorUnionImpl();
86
...@@ -25,9 +23,7 @@ fn returnsTen() -> %i32 {...@@ -25,9 +23,7 @@ fn returnsTen() -> %i32 {
25 1023 10
26}24}
2725
28fn tryWithoutVars() {26test "tryWithoutVars" {
29 @setFnTest(this);
30
31 const result1 = try (failIfTrue(true)) {27 const result1 = try (failIfTrue(true)) {
32 128 1
33 } else {29 } else {
test/cases/typedef.zig+1-3
...@@ -5,8 +5,6 @@ type int = u8;...@@ -5,8 +5,6 @@ type int = u8;
5fn add(a: int, b: int) -> int {5fn add(a: int, b: int) -> int {
6 a + b6 a + b
7}7}
8fn typedef() {8test "typedef" {
9 @setFnTest(this);
10
11 assert(add(12, 34) == 46);9 assert(add(12, 34) == 46);
12}10}
test/cases/undefined.zig+3-9
...@@ -9,9 +9,7 @@ fn initStaticArray() -> [10]i32 {...@@ -9,9 +9,7 @@ fn initStaticArray() -> [10]i32 {
9 return array;9 return array;
10}10}
11const static_array = initStaticArray();11const static_array = initStaticArray();
12fn initStaticArrayToUndefined() {12test "initStaticArrayToUndefined" {
13 @setFnTest(this);
14
15 assert(static_array[0] == 1);13 assert(static_array[0] == 1);
16 assert(static_array[4] == 2);14 assert(static_array[4] == 2);
17 assert(static_array[7] == 3);15 assert(static_array[7] == 3);
...@@ -37,9 +35,7 @@ fn setFooX(foo: &Foo) {...@@ -37,9 +35,7 @@ fn setFooX(foo: &Foo) {
37 foo.x = 2;35 foo.x = 2;
38}36}
3937
40fn assignUndefinedToStruct() {38test "assignUndefinedToStruct" {
41 @setFnTest(this);
42
43 comptime {39 comptime {
44 var foo: Foo = undefined;40 var foo: Foo = undefined;
45 setFooX(&foo);41 setFooX(&foo);
...@@ -52,9 +48,7 @@ fn assignUndefinedToStruct() {...@@ -52,9 +48,7 @@ fn assignUndefinedToStruct() {
52 }48 }
53}49}
5450
55fn assignUndefinedToStructWithMethod() {51test "assignUndefinedToStructWithMethod" {
56 @setFnTest(this);
57
58 comptime {52 comptime {
59 var foo: Foo = undefined;53 var foo: Foo = undefined;
60 foo.setFooXMethod();54 foo.setFooXMethod();
test/cases/var_args.zig+3-9
...@@ -8,9 +8,7 @@ fn add(args: ...) -> i32 {...@@ -8,9 +8,7 @@ fn add(args: ...) -> i32 {
8 return sum;8 return sum;
9}9}
1010
11fn testAddArbitraryArgs() {11test "testAddArbitraryArgs" {
12 @setFnTest(this);
13
14 assert(add(i32(1), i32(2), i32(3), i32(4)) == 10);12 assert(add(i32(1), i32(2), i32(3), i32(4)) == 10);
15 assert(add(i32(1234)) == 1234);13 assert(add(i32(1234)) == 1234);
16 assert(add() == 0);14 assert(add() == 0);
...@@ -20,15 +18,11 @@ fn readFirstVarArg(args: ...) {...@@ -20,15 +18,11 @@ fn readFirstVarArg(args: ...) {
20 const value = args[0];18 const value = args[0];
21}19}
2220
23fn sendVoidArgToVarArgs() {21test "sendVoidArgToVarArgs" {
24 @setFnTest(this);
25
26 readFirstVarArg({});22 readFirstVarArg({});
27}23}
2824
29fn testPassArgsDirectly() {25test "testPassArgsDirectly" {
30 @setFnTest(this);
31
32 assert(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);26 assert(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);
33 assert(addSomeStuff(i32(1234)) == 1234);27 assert(addSomeStuff(i32(1234)) == 1234);
34 assert(addSomeStuff() == 0);28 assert(addSomeStuff() == 0);
test/cases/void.zig+1-3
...@@ -6,9 +6,7 @@ const Foo = struct {...@@ -6,9 +6,7 @@ const Foo = struct {
6 c: void,6 c: void,
7};7};
88
9fn compareVoidWithVoidCompileTimeKnown() {9test "compareVoidWithVoidCompileTimeKnown" {
10 @setFnTest(this);
11
12 comptime {10 comptime {
13 const foo = Foo {11 const foo = Foo {
14 .a = {},12 .a = {},
test/cases/while.zig+5-15
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3fn whileLoop() {3test "whileLoop" {
4 @setFnTest(this);
5
6 var i : i32 = 0;4 var i : i32 = 0;
7 while (i < 4) {5 while (i < 4) {
8 i += 1;6 i += 1;
...@@ -18,9 +16,7 @@ fn whileLoop2() -> i32 {...@@ -18,9 +16,7 @@ fn whileLoop2() -> i32 {
18 return 1;16 return 1;
19 }17 }
20}18}
21fn staticEvalWhile() {19test "staticEvalWhile" {
22 @setFnTest(this);
23
24 assert(static_eval_while_number == 1);20 assert(static_eval_while_number == 1);
25}21}
26const static_eval_while_number = staticWhileLoop1();22const static_eval_while_number = staticWhileLoop1();
...@@ -33,9 +29,7 @@ fn staticWhileLoop2() -> i32 {...@@ -33,9 +29,7 @@ fn staticWhileLoop2() -> i32 {
33 }29 }
34}30}
3531
36fn continueAndBreak() {32test "continueAndBreak" {
37 @setFnTest(this);
38
39 runContinueAndBreakTest();33 runContinueAndBreakTest();
40 assert(continue_and_break_counter == 8);34 assert(continue_and_break_counter == 8);
41}35}
...@@ -53,9 +47,7 @@ fn runContinueAndBreakTest() {...@@ -53,9 +47,7 @@ fn runContinueAndBreakTest() {
53 assert(i == 4);47 assert(i == 4);
54}48}
5549
56fn returnWithImplicitCastFromWhileLoop() {50test "returnWithImplicitCastFromWhileLoop" {
57 @setFnTest(this);
58
59 %%returnWithImplicitCastFromWhileLoopTest();51 %%returnWithImplicitCastFromWhileLoopTest();
60}52}
61fn returnWithImplicitCastFromWhileLoopTest() -> %void {53fn returnWithImplicitCastFromWhileLoopTest() -> %void {
...@@ -64,9 +56,7 @@ fn returnWithImplicitCastFromWhileLoopTest() -> %void {...@@ -64,9 +56,7 @@ fn returnWithImplicitCastFromWhileLoopTest() -> %void {
64 }56 }
65}57}
6658
67fn whileWithContinueExpr() {59test "whileWithContinueExpr" {
68 @setFnTest(this);
69
70 var sum: i32 = 0;60 var sum: i32 = 0;
71 {var i: i32 = 0; while (i < 10; i += 1) {61 {var i: i32 = 0; while (i < 10; i += 1) {
72 if (i == 5) continue;62 if (i == 5) continue;
test/run_tests.cpp+223-88
...@@ -14,6 +14,12 @@...@@ -14,6 +14,12 @@
14#include <stdio.h>14#include <stdio.h>
15#include <stdarg.h>15#include <stdarg.h>
1616
17enum TestSpecial {
18 TestSpecialNone,
19 TestSpecialSelfHosted,
20 TestSpecialStd,
21};
22
17struct TestSourceFile {23struct TestSourceFile {
18 const char *relative_path;24 const char *relative_path;
19 const char *source_code;25 const char *source_code;
...@@ -32,7 +38,7 @@ struct TestCase {...@@ -32,7 +38,7 @@ struct TestCase {
32 ZigList<const char *> compiler_args;38 ZigList<const char *> compiler_args;
33 ZigList<const char *> program_args;39 ZigList<const char *> program_args;
34 bool is_parseh;40 bool is_parseh;
35 bool is_self_hosted;41 TestSpecial special;
36 bool is_release_mode;42 bool is_release_mode;
37 bool is_debug_safety;43 bool is_debug_safety;
38 AllowWarnings allow_warnings;44 AllowWarnings allow_warnings;
...@@ -79,7 +85,6 @@ static TestCase *add_simple_case(const char *case_name, const char *source, cons...@@ -79,7 +85,6 @@ static TestCase *add_simple_case(const char *case_name, const char *source, cons
79 test_case->compiler_args.append("--strip");85 test_case->compiler_args.append("--strip");
80 test_case->compiler_args.append("--color");86 test_case->compiler_args.append("--color");
81 test_case->compiler_args.append("on");87 test_case->compiler_args.append("on");
82 test_case->compiler_args.append("--check-unused");
8388
84 test_cases.append(test_case);89 test_cases.append(test_case);
8590
...@@ -93,9 +98,10 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,...@@ -93,9 +98,10 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,
93 return tc;98 return tc;
94}99}
95100
96static TestCase *add_compile_fail_case_extra(const char *case_name, const char *source, bool check_unused,101static TestCase *add_compile_fail_case(const char *case_name, const char *source, size_t count, ...) {
97 size_t count, va_list ap)102 va_list ap;
98{103 va_start(ap, count);
104
99 TestCase *test_case = allocate<TestCase>(1);105 TestCase *test_case = allocate<TestCase>(1);
100 test_case->case_name = case_name;106 test_case->case_name = case_name;
101 test_case->source_files.resize(1);107 test_case->source_files.resize(1);
...@@ -122,31 +128,11 @@ static TestCase *add_compile_fail_case_extra(const char *case_name, const char *...@@ -122,31 +128,11 @@ static TestCase *add_compile_fail_case_extra(const char *case_name, const char *
122 test_case->compiler_args.append("--release");128 test_case->compiler_args.append("--release");
123 test_case->compiler_args.append("--strip");129 test_case->compiler_args.append("--strip");
124130
125 if (check_unused) {
126 test_case->compiler_args.append("--check-unused");
127 }
128
129 test_cases.append(test_case);131 test_cases.append(test_case);
130132
131 return test_case;133 return test_case;
132}134}
133135
134static TestCase *add_compile_fail_case_no_check_unused(const char *case_name, const char *source, size_t count, ...) {
135 va_list ap;
136 va_start(ap, count);
137 TestCase *result = add_compile_fail_case_extra(case_name, source, false, count, ap);
138 va_end(ap);
139 return result;
140}
141
142static TestCase *add_compile_fail_case(const char *case_name, const char *source, size_t count, ...) {
143 va_list ap;
144 va_start(ap, count);
145 TestCase *result = add_compile_fail_case_extra(case_name, source, true, count, ap);
146 va_end(ap);
147 return result;
148}
149
150static void add_debug_safety_case(const char *case_name, const char *source) {136static void add_debug_safety_case(const char *case_name, const char *source) {
151 {137 {
152 TestCase *test_case = allocate<TestCase>(1);138 TestCase *test_case = allocate<TestCase>(1);
...@@ -674,24 +660,27 @@ static void add_compile_failure_test_cases(void) {...@@ -674,24 +660,27 @@ static void add_compile_failure_test_cases(void) {
674 add_compile_fail_case("multiple function definitions", R"SOURCE(660 add_compile_fail_case("multiple function definitions", R"SOURCE(
675fn a() {}661fn a() {}
676fn a() {}662fn a() {}
663export fn entry() { a(); }
677 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'");664 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'");
678665
679 add_compile_fail_case("unreachable with return", R"SOURCE(666 add_compile_fail_case("unreachable with return", R"SOURCE(
680fn a() -> unreachable {return;}667fn a() -> unreachable {return;}
668export fn entry() { a(); }
681 )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', found 'void'");669 )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', found 'void'");
682670
683 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(671 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(
684fn a() -> i32 {}672fn a() -> i32 {}
673export fn entry() { _ = a(); }
685 )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', found 'void'");674 )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', found 'void'");
686675
687 add_compile_fail_case("undefined function call", R"SOURCE(676 add_compile_fail_case("undefined function call", R"SOURCE(
688fn a() {677export fn a() {
689 b();678 b();
690}679}
691 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");680 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");
692681
693 add_compile_fail_case("wrong number of arguments", R"SOURCE(682 add_compile_fail_case("wrong number of arguments", R"SOURCE(
694fn a() {683export fn a() {
695 b(1);684 b(1);
696}685}
697fn b(a: i32, b: i32, c: i32) { }686fn b(a: i32, b: i32, c: i32) { }
...@@ -699,14 +688,16 @@ fn b(a: i32, b: i32, c: i32) { }...@@ -699,14 +688,16 @@ fn b(a: i32, b: i32, c: i32) { }
699688
700 add_compile_fail_case("invalid type", R"SOURCE(689 add_compile_fail_case("invalid type", R"SOURCE(
701fn a() -> bogus {}690fn a() -> bogus {}
691export fn entry() { _ = a(); }
702 )SOURCE", 1, ".tmp_source.zig:2:11: error: use of undeclared identifier 'bogus'");692 )SOURCE", 1, ".tmp_source.zig:2:11: error: use of undeclared identifier 'bogus'");
703693
704 add_compile_fail_case("pointer to unreachable", R"SOURCE(694 add_compile_fail_case("pointer to unreachable", R"SOURCE(
705fn a() -> &unreachable {}695fn a() -> &unreachable {}
696export fn entry() { _ = a(); }
706 )SOURCE", 1, ".tmp_source.zig:2:12: error: pointer to unreachable not allowed");697 )SOURCE", 1, ".tmp_source.zig:2:12: error: pointer to unreachable not allowed");
707698
708 add_compile_fail_case("unreachable code", R"SOURCE(699 add_compile_fail_case("unreachable code", R"SOURCE(
709fn a() {700export fn a() {
710 return;701 return;
711 b();702 b();
712}703}
...@@ -716,10 +707,11 @@ fn b() {}...@@ -716,10 +707,11 @@ fn b() {}
716707
717 add_compile_fail_case("bad import", R"SOURCE(708 add_compile_fail_case("bad import", R"SOURCE(
718const bogus = @import("bogus-does-not-exist.zig");709const bogus = @import("bogus-does-not-exist.zig");
710export fn entry() { bogus.bogo(); }
719 )SOURCE", 1, ".tmp_source.zig:2:15: error: unable to find 'bogus-does-not-exist.zig'");711 )SOURCE", 1, ".tmp_source.zig:2:15: error: unable to find 'bogus-does-not-exist.zig'");
720712
721 add_compile_fail_case("undeclared identifier", R"SOURCE(713 add_compile_fail_case("undeclared identifier", R"SOURCE(
722fn a() {714export fn a() {
723 b +715 b +
724 c716 c
725}717}
...@@ -730,10 +722,11 @@ fn a() {...@@ -730,10 +722,11 @@ fn a() {
730 add_compile_fail_case("parameter redeclaration", R"SOURCE(722 add_compile_fail_case("parameter redeclaration", R"SOURCE(
731fn f(a : i32, a : i32) {723fn f(a : i32, a : i32) {
732}724}
725export fn entry() { f(1, 2); }
733 )SOURCE", 1, ".tmp_source.zig:2:15: error: redeclaration of variable 'a'");726 )SOURCE", 1, ".tmp_source.zig:2:15: error: redeclaration of variable 'a'");
734727
735 add_compile_fail_case("local variable redeclaration", R"SOURCE(728 add_compile_fail_case("local variable redeclaration", R"SOURCE(
736fn f() {729export fn f() {
737 const a : i32 = 0;730 const a : i32 = 0;
738 const a = 0;731 const a = 0;
739}732}
...@@ -743,71 +736,73 @@ fn f() {...@@ -743,71 +736,73 @@ fn f() {
743fn f(a : i32) {736fn f(a : i32) {
744 const a = 0;737 const a = 0;
745}738}
739export fn entry() { f(1); }
746 )SOURCE", 1, ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");740 )SOURCE", 1, ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");
747741
748 add_compile_fail_case("variable has wrong type", R"SOURCE(742 add_compile_fail_case("variable has wrong type", R"SOURCE(
749fn f() -> i32 {743export fn f() -> i32 {
750 const a = c"a";744 const a = c"a";
751 a745 a
752}746}
753 )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', found '&const u8'");747 )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', found '&const u8'");
754748
755 add_compile_fail_case("if condition is bool, not int", R"SOURCE(749 add_compile_fail_case("if condition is bool, not int", R"SOURCE(
756fn f() {750export fn f() {
757 if (0) {}751 if (0) {}
758}752}
759 )SOURCE", 1, ".tmp_source.zig:3:9: error: integer value 0 cannot be implicitly casted to type 'bool'");753 )SOURCE", 1, ".tmp_source.zig:3:9: error: integer value 0 cannot be implicitly casted to type 'bool'");
760754
761 add_compile_fail_case("assign unreachable", R"SOURCE(755 add_compile_fail_case("assign unreachable", R"SOURCE(
762fn f() {756export fn f() {
763 const a = return;757 const a = return;
764}758}
765 )SOURCE", 1, ".tmp_source.zig:3:5: error: unreachable code");759 )SOURCE", 1, ".tmp_source.zig:3:5: error: unreachable code");
766760
767 add_compile_fail_case("unreachable variable", R"SOURCE(761 add_compile_fail_case("unreachable variable", R"SOURCE(
768fn f() {762export fn f() {
769 const a : unreachable = {};763 const a : unreachable = {};
770}764}
771 )SOURCE", 1, ".tmp_source.zig:3:15: error: variable of type 'unreachable' not allowed");765 )SOURCE", 1, ".tmp_source.zig:3:15: error: variable of type 'unreachable' not allowed");
772766
773 add_compile_fail_case("unreachable parameter", R"SOURCE(767 add_compile_fail_case("unreachable parameter", R"SOURCE(
774fn f(a : unreachable) {}768fn f(a : unreachable) {}
769export fn entry() { f(); }
775 )SOURCE", 1, ".tmp_source.zig:2:10: error: parameter of type 'unreachable' not allowed");770 )SOURCE", 1, ".tmp_source.zig:2:10: error: parameter of type 'unreachable' not allowed");
776771
777 add_compile_fail_case("bad assignment target", R"SOURCE(772 add_compile_fail_case("bad assignment target", R"SOURCE(
778fn f() {773export fn f() {
779 3 = 3;774 3 = 3;
780}775}
781 )SOURCE", 1, ".tmp_source.zig:3:7: error: cannot assign to constant");776 )SOURCE", 1, ".tmp_source.zig:3:7: error: cannot assign to constant");
782777
783 add_compile_fail_case("assign to constant variable", R"SOURCE(778 add_compile_fail_case("assign to constant variable", R"SOURCE(
784fn f() {779export fn f() {
785 const a = 3;780 const a = 3;
786 a = 4;781 a = 4;
787}782}
788 )SOURCE", 1, ".tmp_source.zig:4:7: error: cannot assign to constant");783 )SOURCE", 1, ".tmp_source.zig:4:7: error: cannot assign to constant");
789784
790 add_compile_fail_case("use of undeclared identifier", R"SOURCE(785 add_compile_fail_case("use of undeclared identifier", R"SOURCE(
791fn f() {786export fn f() {
792 b = 3;787 b = 3;
793}788}
794 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");789 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");
795790
796 add_compile_fail_case("const is a statement, not an expression", R"SOURCE(791 add_compile_fail_case("const is a statement, not an expression", R"SOURCE(
797fn f() {792export fn f() {
798 (const a = 0);793 (const a = 0);
799}794}
800 )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'");795 )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'");
801796
802 add_compile_fail_case("array access of undeclared identifier", R"SOURCE(797 add_compile_fail_case("array access of undeclared identifier", R"SOURCE(
803fn f() {798export fn f() {
804 i[i] = i[i];799 i[i] = i[i];
805}800}
806 )SOURCE", 2, ".tmp_source.zig:3:5: error: use of undeclared identifier 'i'",801 )SOURCE", 2, ".tmp_source.zig:3:5: error: use of undeclared identifier 'i'",
807 ".tmp_source.zig:3:12: error: use of undeclared identifier 'i'");802 ".tmp_source.zig:3:12: error: use of undeclared identifier 'i'");
808803
809 add_compile_fail_case("array access of non array", R"SOURCE(804 add_compile_fail_case("array access of non array", R"SOURCE(
810fn f() {805export fn f() {
811 var bad : bool = undefined;806 var bad : bool = undefined;
812 bad[bad] = bad[bad];807 bad[bad] = bad[bad];
813}808}
...@@ -815,7 +810,7 @@ fn f() {...@@ -815,7 +810,7 @@ fn f() {
815 ".tmp_source.zig:4:19: error: array access of non-array type 'bool'");810 ".tmp_source.zig:4:19: error: array access of non-array type 'bool'");
816811
817 add_compile_fail_case("array access with non integer index", R"SOURCE(812 add_compile_fail_case("array access with non integer index", R"SOURCE(
818fn f() {813export fn f() {
819 var array = "aoeu";814 var array = "aoeu";
820 var bad = false;815 var bad = false;
821 array[bad] = array[bad];816 array[bad] = array[bad];
...@@ -828,6 +823,7 @@ const x : i32 = 99;...@@ -828,6 +823,7 @@ const x : i32 = 99;
828fn f() {823fn f() {
829 x = 1;824 x = 1;
830}825}
826export fn entry() { f(); }
831 )SOURCE", 1, ".tmp_source.zig:4:7: error: cannot assign to constant");827 )SOURCE", 1, ".tmp_source.zig:4:7: error: cannot assign to constant");
832828
833829
...@@ -836,22 +832,25 @@ fn f(b: bool) {...@@ -836,22 +832,25 @@ fn f(b: bool) {
836 const x : i32 = if (b) { 1 };832 const x : i32 = if (b) { 1 };
837 const y = if (b) { i32(1) };833 const y = if (b) { i32(1) };
838}834}
835export fn entry() { f(true); }
839 )SOURCE", 2, ".tmp_source.zig:3:30: error: integer value 1 cannot be implicitly casted to type 'void'",836 )SOURCE", 2, ".tmp_source.zig:3:30: error: integer value 1 cannot be implicitly casted to type 'void'",
840 ".tmp_source.zig:4:15: error: incompatible types: 'i32' and 'void'");837 ".tmp_source.zig:4:15: error: incompatible types: 'i32' and 'void'");
841838
842 add_compile_fail_case("direct struct loop", R"SOURCE(839 add_compile_fail_case("direct struct loop", R"SOURCE(
843const A = struct { a : A, };840const A = struct { a : A, };
841export fn entry() -> usize { @sizeOf(A) }
844 )SOURCE", 1, ".tmp_source.zig:2:11: error: struct 'A' contains itself");842 )SOURCE", 1, ".tmp_source.zig:2:11: error: struct 'A' contains itself");
845843
846 add_compile_fail_case("indirect struct loop", R"SOURCE(844 add_compile_fail_case("indirect struct loop", R"SOURCE(
847const A = struct { b : B, };845const A = struct { b : B, };
848const B = struct { c : C, };846const B = struct { c : C, };
849const C = struct { a : A, };847const C = struct { a : A, };
848export fn entry() -> usize { @sizeOf(A) }
850 )SOURCE", 1, ".tmp_source.zig:2:11: error: struct 'A' contains itself");849 )SOURCE", 1, ".tmp_source.zig:2:11: error: struct 'A' contains itself");
851850
852 add_compile_fail_case("invalid struct field", R"SOURCE(851 add_compile_fail_case("invalid struct field", R"SOURCE(
853const A = struct { x : i32, };852const A = struct { x : i32, };
854fn f() {853export fn f() {
855 var a : A = undefined;854 var a : A = undefined;
856 a.foo = 1;855 a.foo = 1;
857 const y = a.bar;856 const y = a.bar;
...@@ -873,7 +872,9 @@ const A = enum {};...@@ -873,7 +872,9 @@ const A = enum {};
873 add_compile_fail_case("redefinition of global variables", R"SOURCE(872 add_compile_fail_case("redefinition of global variables", R"SOURCE(
874var a : i32 = 1;873var a : i32 = 1;
875var a : i32 = 2;874var a : i32 = 2;
876 )SOURCE", 1, ".tmp_source.zig:3:1: error: redeclaration of variable 'a'");875 )SOURCE", 2,
876 ".tmp_source.zig:3:1: error: redefinition of 'a'",
877 ".tmp_source.zig:2:1: note: previous definition is here");
877878
878 add_compile_fail_case("byvalue struct parameter in exported function", R"SOURCE(879 add_compile_fail_case("byvalue struct parameter in exported function", R"SOURCE(
879const A = struct { x : i32, };880const A = struct { x : i32, };
...@@ -893,7 +894,7 @@ const A = struct {...@@ -893,7 +894,7 @@ const A = struct {
893 y : i32,894 y : i32,
894 z : i32,895 z : i32,
895};896};
896fn f() {897export fn f() {
897 const a = A {898 const a = A {
898 .z = 1,899 .z = 1,
899 .y = 2,900 .y = 2,
...@@ -909,7 +910,7 @@ const A = struct {...@@ -909,7 +910,7 @@ const A = struct {
909 y : i32,910 y : i32,
910 z : i32,911 z : i32,
911};912};
912fn f() {913export fn f() {
913 // we want the error on the '{' not the 'A' because914 // we want the error on the '{' not the 'A' because
914 // the A could be a complicated expression915 // the A could be a complicated expression
915 const a = A {916 const a = A {
...@@ -925,7 +926,7 @@ const A = struct {...@@ -925,7 +926,7 @@ const A = struct {
925 y : i32,926 y : i32,
926 z : i32,927 z : i32,
927};928};
928fn f() {929export fn f() {
929 const a = A {930 const a = A {
930 .z = 4,931 .z = 4,
931 .y = 2,932 .y = 2,
...@@ -935,19 +936,19 @@ fn f() {...@@ -935,19 +936,19 @@ fn f() {
935 )SOURCE", 1, ".tmp_source.zig:11:9: error: no member named 'foo' in 'A'");936 )SOURCE", 1, ".tmp_source.zig:11:9: error: no member named 'foo' in 'A'");
936937
937 add_compile_fail_case("invalid break expression", R"SOURCE(938 add_compile_fail_case("invalid break expression", R"SOURCE(
938fn f() {939export fn f() {
939 break;940 break;
940}941}
941 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'break' expression outside loop");942 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'break' expression outside loop");
942943
943 add_compile_fail_case("invalid continue expression", R"SOURCE(944 add_compile_fail_case("invalid continue expression", R"SOURCE(
944fn f() {945export fn f() {
945 continue;946 continue;
946}947}
947 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'continue' expression outside loop");948 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'continue' expression outside loop");
948949
949 add_compile_fail_case("invalid maybe type", R"SOURCE(950 add_compile_fail_case("invalid maybe type", R"SOURCE(
950fn f() {951export fn f() {
951 if (const x ?= true) { }952 if (const x ?= true) { }
952}953}
953 )SOURCE", 1, ".tmp_source.zig:3:20: error: expected nullable type, found 'bool'");954 )SOURCE", 1, ".tmp_source.zig:3:20: error: expected nullable type, found 'bool'");
...@@ -956,42 +957,39 @@ fn f() {...@@ -956,42 +957,39 @@ fn f() {
956fn f() -> i32 {957fn f() -> i32 {
957 i32(return 1)958 i32(return 1)
958}959}
960export fn entry() { _ = f(); }
959 )SOURCE", 1, ".tmp_source.zig:3:8: error: unreachable code");961 )SOURCE", 1, ".tmp_source.zig:3:8: error: unreachable code");
960962
961 add_compile_fail_case("invalid builtin fn", R"SOURCE(963 add_compile_fail_case("invalid builtin fn", R"SOURCE(
962fn f() -> @bogus(foo) {964fn f() -> @bogus(foo) {
963}965}
966export fn entry() { _ = f(); }
964 )SOURCE", 1, ".tmp_source.zig:2:11: error: invalid builtin function: 'bogus'");967 )SOURCE", 1, ".tmp_source.zig:2:11: error: invalid builtin function: 'bogus'");
965968
966 add_compile_fail_case("top level decl dependency loop", R"SOURCE(969 add_compile_fail_case("top level decl dependency loop", R"SOURCE(
967const a : @typeOf(b) = 0;970const a : @typeOf(b) = 0;
968const b : @typeOf(a) = 0;971const b : @typeOf(a) = 0;
972export fn entry() {
973 const c = a + b;
974}
969 )SOURCE", 1, ".tmp_source.zig:2:1: error: 'a' depends on itself");975 )SOURCE", 1, ".tmp_source.zig:2:1: error: 'a' depends on itself");
970976
971 add_compile_fail_case("noalias on non pointer param", R"SOURCE(977 add_compile_fail_case("noalias on non pointer param", R"SOURCE(
972fn f(noalias x: i32) {}978fn f(noalias x: i32) {}
979export fn entry() { f(1234); }
973 )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter");980 )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter");
974981
975 add_compile_fail_case("struct init syntax for array", R"SOURCE(982 add_compile_fail_case("struct init syntax for array", R"SOURCE(
976const foo = []u16{.x = 1024,};983const foo = []u16{.x = 1024,};
984export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
977 )SOURCE", 1, ".tmp_source.zig:2:18: error: type '[]u16' does not support struct initialization syntax");985 )SOURCE", 1, ".tmp_source.zig:2:18: error: type '[]u16' does not support struct initialization syntax");
978986
979 add_compile_fail_case("type variables must be constant", R"SOURCE(987 add_compile_fail_case("type variables must be constant", R"SOURCE(
980var foo = u8;988var foo = u8;
981 )SOURCE", 1, ".tmp_source.zig:2:1: error: variable of type 'type' must be constant");989export fn entry() -> foo {
982990 return 1;
983 add_compile_fail_case("variables shadowing types", R"SOURCE(
984const Foo = struct {};
985const Bar = struct {};
986
987fn f(Foo: i32) {
988 var Bar : i32 = undefined;
989}991}
990 )SOURCE", 4,992 )SOURCE", 1, ".tmp_source.zig:2:1: error: variable of type 'type' must be constant");
991 ".tmp_source.zig:5:6: error: redeclaration of variable 'Foo'",
992 ".tmp_source.zig:2:1: note: previous declaration is here",
993 ".tmp_source.zig:6:5: error: redeclaration of variable 'Bar'",
994 ".tmp_source.zig:3:1: note: previous declaration is here");
995993
996 add_compile_fail_case("multiple else prongs in a switch", R"SOURCE(994 add_compile_fail_case("multiple else prongs in a switch", R"SOURCE(
997fn f(x: u32) {995fn f(x: u32) {
...@@ -1000,28 +998,36 @@ fn f(x: u32) {...@@ -1000,28 +998,36 @@ fn f(x: u32) {
1000 else => true,998 else => true,
1001 else => true,999 else => true,
1002 };1000 };
1001}
1002export fn entry() {
1003 f(1234);
1003}1004}
1004 )SOURCE", 1, ".tmp_source.zig:6:9: error: multiple else prongs in switch expression");1005 )SOURCE", 1, ".tmp_source.zig:6:9: error: multiple else prongs in switch expression");
10051006
1006 add_compile_fail_case("global variable initializer must be constant expression", R"SOURCE(1007 add_compile_fail_case("global variable initializer must be constant expression", R"SOURCE(
1007extern fn foo() -> i32;1008extern fn foo() -> i32;
1008const x = foo();1009const x = foo();
1010export fn entry() -> i32 { x }
1009 )SOURCE", 1, ".tmp_source.zig:3:11: error: unable to evaluate constant expression");1011 )SOURCE", 1, ".tmp_source.zig:3:11: error: unable to evaluate constant expression");
10101012
1011 add_compile_fail_case("array concatenation with wrong type", R"SOURCE(1013 add_compile_fail_case("array concatenation with wrong type", R"SOURCE(
1012const src = "aoeu";1014const src = "aoeu";
1013const derp = usize(1234);1015const derp = usize(1234);
1014const a = derp ++ "foo";1016const a = derp ++ "foo";
1017
1018export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1015 )SOURCE", 1, ".tmp_source.zig:4:11: error: expected array or C string literal, found 'usize'");1019 )SOURCE", 1, ".tmp_source.zig:4:11: error: expected array or C string literal, found 'usize'");
10161020
1017 add_compile_fail_case("non compile time array concatenation", R"SOURCE(1021 add_compile_fail_case("non compile time array concatenation", R"SOURCE(
1018fn f(s: [10]u8) -> []u8 {1022fn f(s: [10]u8) -> []u8 {
1019 s ++ "foo"1023 s ++ "foo"
1020}1024}
1025export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1021 )SOURCE", 1, ".tmp_source.zig:3:5: error: unable to evaluate constant expression");1026 )SOURCE", 1, ".tmp_source.zig:3:5: error: unable to evaluate constant expression");
10221027
1023 add_compile_fail_case("@cImport with bogus include", R"SOURCE(1028 add_compile_fail_case("@cImport with bogus include", R"SOURCE(
1024const c = @cImport(@cInclude("bogus.h"));1029const c = @cImport(@cInclude("bogus.h"));
1030export fn entry() -> usize { @sizeOf(@typeOf(c.bogo)) }
1025 )SOURCE", 2, ".tmp_source.zig:2:11: error: C import failed",1031 )SOURCE", 2, ".tmp_source.zig:2:11: error: C import failed",
1026 ".h:1:10: note: 'bogus.h' file not found");1032 ".h:1:10: note: 'bogus.h' file not found");
10271033
...@@ -1029,14 +1035,17 @@ const c = @cImport(@cInclude("bogus.h"));...@@ -1029,14 +1035,17 @@ const c = @cImport(@cInclude("bogus.h"));
1029const x = 3;1035const x = 3;
1030const y = &x;1036const y = &x;
1031fn foo() -> &const i32 { y }1037fn foo() -> &const i32 { y }
1038export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1032 )SOURCE", 1, ".tmp_source.zig:4:26: error: expected type '&const i32', found '&const (integer literal)'");1039 )SOURCE", 1, ".tmp_source.zig:4:26: error: expected type '&const i32', found '&const (integer literal)'");
10331040
1034 add_compile_fail_case("integer overflow error", R"SOURCE(1041 add_compile_fail_case("integer overflow error", R"SOURCE(
1035const x : u8 = 300;1042const x : u8 = 300;
1043export fn entry() -> usize { @sizeOf(@typeOf(x)) }
1036 )SOURCE", 1, ".tmp_source.zig:2:16: error: integer value 300 cannot be implicitly casted to type 'u8'");1044 )SOURCE", 1, ".tmp_source.zig:2:16: error: integer value 300 cannot be implicitly casted to type 'u8'");
10371045
1038 add_compile_fail_case("incompatible number literals", R"SOURCE(1046 add_compile_fail_case("incompatible number literals", R"SOURCE(
1039const x = 2 == 2.0;1047const x = 2 == 2.0;
1048export fn entry() -> usize { @sizeOf(@typeOf(x)) }
1040 )SOURCE", 1, ".tmp_source.zig:2:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");1049 )SOURCE", 1, ".tmp_source.zig:2:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");
10411050
1042 add_compile_fail_case("missing function call param", R"SOURCE(1051 add_compile_fail_case("missing function call param", R"SOURCE(
...@@ -1061,11 +1070,14 @@ const members = []member_fn_type {...@@ -1061,11 +1070,14 @@ const members = []member_fn_type {
1061fn f(foo: Foo, index: usize) {1070fn f(foo: Foo, index: usize) {
1062 const result = members[index]();1071 const result = members[index]();
1063}1072}
1073
1074export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1064 )SOURCE", 1, ".tmp_source.zig:21:34: error: expected 1 arguments, found 0");1075 )SOURCE", 1, ".tmp_source.zig:21:34: error: expected 1 arguments, found 0");
10651076
1066 add_compile_fail_case("missing function name and param name", R"SOURCE(1077 add_compile_fail_case("missing function name and param name", R"SOURCE(
1067fn () {}1078fn () {}
1068fn f(i32) {}1079fn f(i32) {}
1080export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1069 )SOURCE", 2,1081 )SOURCE", 2,
1070 ".tmp_source.zig:2:1: error: missing function name",1082 ".tmp_source.zig:2:1: error: missing function name",
1071 ".tmp_source.zig:3:6: error: missing parameter name");1083 ".tmp_source.zig:3:6: error: missing parameter name");
...@@ -1075,6 +1087,7 @@ const fns = []fn(){ a, b, c };...@@ -1075,6 +1087,7 @@ const fns = []fn(){ a, b, c };
1075fn a() -> i32 {0}1087fn a() -> i32 {0}
1076fn b() -> i32 {1}1088fn b() -> i32 {1}
1077fn c() -> i32 {2}1089fn c() -> i32 {2}
1090export fn entry() -> usize { @sizeOf(@typeOf(fns)) }
1078 )SOURCE", 1, ".tmp_source.zig:2:21: error: expected type 'fn()', found 'fn() -> i32'");1091 )SOURCE", 1, ".tmp_source.zig:2:21: error: expected type 'fn()', found 'fn() -> i32'");
10791092
1080 add_compile_fail_case("extern function pointer mismatch", R"SOURCE(1093 add_compile_fail_case("extern function pointer mismatch", R"SOURCE(
...@@ -1082,18 +1095,23 @@ const fns = [](fn(i32)->i32){ a, b, c };...@@ -1082,18 +1095,23 @@ const fns = [](fn(i32)->i32){ a, b, c };
1082pub fn a(x: i32) -> i32 {x + 0}1095pub fn a(x: i32) -> i32 {x + 0}
1083pub fn b(x: i32) -> i32 {x + 1}1096pub fn b(x: i32) -> i32 {x + 1}
1084export fn c(x: i32) -> i32 {x + 2}1097export fn c(x: i32) -> i32 {x + 2}
1098
1099export fn entry() -> usize { @sizeOf(@typeOf(fns)) }
1085 )SOURCE", 1, ".tmp_source.zig:2:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");1100 )SOURCE", 1, ".tmp_source.zig:2:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");
10861101
10871102
1088 add_compile_fail_case("implicit cast from f64 to f32", R"SOURCE(1103 add_compile_fail_case("implicit cast from f64 to f32", R"SOURCE(
1089const x : f64 = 1.0;1104const x : f64 = 1.0;
1090const y : f32 = x;1105const y : f32 = x;
1106
1107export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1091 )SOURCE", 1, ".tmp_source.zig:3:17: error: expected type 'f32', found 'f64'");1108 )SOURCE", 1, ".tmp_source.zig:3:17: error: expected type 'f32', found 'f64'");
10921109
10931110
1094 add_compile_fail_case("colliding invalid top level functions", R"SOURCE(1111 add_compile_fail_case("colliding invalid top level functions", R"SOURCE(
1095fn func() -> bogus {}1112fn func() -> bogus {}
1096fn func() -> bogus {}1113fn func() -> bogus {}
1114export fn entry() -> usize { @sizeOf(@typeOf(func)) }
1097 )SOURCE", 2,1115 )SOURCE", 2,
1098 ".tmp_source.zig:3:1: error: redefinition of 'func'",1116 ".tmp_source.zig:3:1: error: redefinition of 'func'",
1099 ".tmp_source.zig:2:14: error: use of undeclared identifier 'bogus'");1117 ".tmp_source.zig:2:14: error: use of undeclared identifier 'bogus'");
...@@ -1101,6 +1119,7 @@ fn func() -> bogus {}...@@ -1101,6 +1119,7 @@ fn func() -> bogus {}
11011119
1102 add_compile_fail_case("bogus compile var", R"SOURCE(1120 add_compile_fail_case("bogus compile var", R"SOURCE(
1103const x = @compileVar("bogus");1121const x = @compileVar("bogus");
1122export fn entry() -> usize { @sizeOf(@typeOf(x)) }
1104 )SOURCE", 1, ".tmp_source.zig:2:23: error: unrecognized compile variable: 'bogus'");1123 )SOURCE", 1, ".tmp_source.zig:2:23: error: unrecognized compile variable: 'bogus'");
11051124
11061125
...@@ -1110,6 +1129,8 @@ const Foo = struct {...@@ -1110,6 +1129,8 @@ const Foo = struct {
1110};1129};
1111var global_var: usize = 1;1130var global_var: usize = 1;
1112fn get() -> usize { global_var }1131fn get() -> usize { global_var }
1132
1133export fn entry() -> usize { @sizeOf(@typeOf(Foo)) }
1113 )SOURCE", 3,1134 )SOURCE", 3,
1114 ".tmp_source.zig:6:21: error: unable to evaluate constant expression",1135 ".tmp_source.zig:6:21: error: unable to evaluate constant expression",
1115 ".tmp_source.zig:3:12: note: called from here",1136 ".tmp_source.zig:3:12: note: called from here",
...@@ -1121,6 +1142,8 @@ const Foo = struct {...@@ -1121,6 +1142,8 @@ const Foo = struct {
1121 field: i32,1142 field: i32,
1122};1143};
1123const x = Foo {.field = 1} + Foo {.field = 2};1144const x = Foo {.field = 1} + Foo {.field = 2};
1145
1146export fn entry() -> usize { @sizeOf(@typeOf(x)) }
1124 )SOURCE", 1, ".tmp_source.zig:5:28: error: invalid operands to binary expression: 'Foo' and 'Foo'");1147 )SOURCE", 1, ".tmp_source.zig:5:28: error: invalid operands to binary expression: 'Foo' and 'Foo'");
11251148
11261149
...@@ -1129,6 +1152,11 @@ const lit_int_x = 1 / 0;...@@ -1129,6 +1152,11 @@ const lit_int_x = 1 / 0;
1129const lit_float_x = 1.0 / 0.0;1152const lit_float_x = 1.0 / 0.0;
1130const int_x = i32(1) / i32(0);1153const int_x = i32(1) / i32(0);
1131const float_x = f32(1.0) / f32(0.0);1154const float_x = f32(1.0) / f32(0.0);
1155
1156export fn entry1() -> usize { @sizeOf(@typeOf(lit_int_x)) }
1157export fn entry2() -> usize { @sizeOf(@typeOf(lit_float_x)) }
1158export fn entry3() -> usize { @sizeOf(@typeOf(int_x)) }
1159export fn entry4() -> usize { @sizeOf(@typeOf(float_x)) }
1132 )SOURCE", 4,1160 )SOURCE", 4,
1133 ".tmp_source.zig:2:21: error: division by zero is undefined",1161 ".tmp_source.zig:2:21: error: division by zero is undefined",
1134 ".tmp_source.zig:3:25: error: division by zero is undefined",1162 ".tmp_source.zig:3:25: error: division by zero is undefined",
...@@ -1150,16 +1178,22 @@ fn f(n: Number) -> i32 {...@@ -1150,16 +1178,22 @@ fn f(n: Number) -> i32 {
1150 Number.Three => i32(3),1178 Number.Three => i32(3),
1151 }1179 }
1152}1180}
1181
1182export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1153 )SOURCE", 1, ".tmp_source.zig:9:5: error: enumeration value 'Number.Four' not handled in switch");1183 )SOURCE", 1, ".tmp_source.zig:9:5: error: enumeration value 'Number.Four' not handled in switch");
11541184
1155 add_compile_fail_case("normal string with newline", R"SOURCE(1185 add_compile_fail_case("normal string with newline", R"SOURCE(
1156const foo = "a1186const foo = "a
1157b";1187b";
1188
1189export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1158 )SOURCE", 1, ".tmp_source.zig:2:13: error: newline not allowed in string literal");1190 )SOURCE", 1, ".tmp_source.zig:2:13: error: newline not allowed in string literal");
11591191
1160 add_compile_fail_case("invalid comparison for function pointers", R"SOURCE(1192 add_compile_fail_case("invalid comparison for function pointers", R"SOURCE(
1161fn foo() {}1193fn foo() {}
1162const invalid = foo > foo;1194const invalid = foo > foo;
1195
1196export fn entry() -> usize { @sizeOf(@typeOf(invalid)) }
1163 )SOURCE", 1, ".tmp_source.zig:3:21: error: operator not allowed for type 'fn()'");1197 )SOURCE", 1, ".tmp_source.zig:3:21: error: operator not allowed for type 'fn()'");
11641198
1165 add_compile_fail_case("generic function instance with non-constant expression", R"SOURCE(1199 add_compile_fail_case("generic function instance with non-constant expression", R"SOURCE(
...@@ -1167,10 +1201,12 @@ fn foo(comptime x: i32, y: i32) -> i32 { return x + y; }...@@ -1167,10 +1201,12 @@ fn foo(comptime x: i32, y: i32) -> i32 { return x + y; }
1167fn test1(a: i32, b: i32) -> i32 {1201fn test1(a: i32, b: i32) -> i32 {
1168 return foo(a, b);1202 return foo(a, b);
1169}1203}
1204
1205export fn entry() -> usize { @sizeOf(@typeOf(test1)) }
1170 )SOURCE", 1, ".tmp_source.zig:4:16: error: unable to evaluate constant expression");1206 )SOURCE", 1, ".tmp_source.zig:4:16: error: unable to evaluate constant expression");
11711207
1172 add_compile_fail_case("goto jumping into block", R"SOURCE(1208 add_compile_fail_case("goto jumping into block", R"SOURCE(
1173fn f() {1209export fn f() {
1174 {1210 {
1175a_label:1211a_label:
1176 }1212 }
...@@ -1185,15 +1221,19 @@ fn f(b: bool) {...@@ -1185,15 +1221,19 @@ fn f(b: bool) {
1185label:1221label:
1186}1222}
1187fn derp(){}1223fn derp(){}
1224
1225export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1188 )SOURCE", 1, ".tmp_source.zig:3:12: error: no label in scope named 'label'");1226 )SOURCE", 1, ".tmp_source.zig:3:12: error: no label in scope named 'label'");
11891227
1190 add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE(1228 add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE(
1191const a: &u8 = null;1229const a: &u8 = null;
1230
1231export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1192 )SOURCE", 1, ".tmp_source.zig:2:16: error: expected type '&u8', found '(null)'");1232 )SOURCE", 1, ".tmp_source.zig:2:16: error: expected type '&u8', found '(null)'");
11931233
1194 add_compile_fail_case("indexing an array of size zero", R"SOURCE(1234 add_compile_fail_case("indexing an array of size zero", R"SOURCE(
1195const array = []u8{};1235const array = []u8{};
1196fn foo() {1236export fn foo() {
1197 const pointer = &array[0];1237 const pointer = &array[0];
1198}1238}
1199 )SOURCE", 1, ".tmp_source.zig:4:27: error: index 0 outside array of size 0");1239 )SOURCE", 1, ".tmp_source.zig:4:27: error: index 0 outside array of size 0");
...@@ -1203,12 +1243,16 @@ const y = foo(0);...@@ -1203,12 +1243,16 @@ const y = foo(0);
1203fn foo(x: i32) -> i32 {1243fn foo(x: i32) -> i32 {
1204 1 / x1244 1 / x
1205}1245}
1246
1247export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1206 )SOURCE", 2,1248 )SOURCE", 2,
1207 ".tmp_source.zig:4:7: error: division by zero is undefined",1249 ".tmp_source.zig:4:7: error: division by zero is undefined",
1208 ".tmp_source.zig:2:14: note: called from here");1250 ".tmp_source.zig:2:14: note: called from here");
12091251
1210 add_compile_fail_case("branch on undefined value", R"SOURCE(1252 add_compile_fail_case("branch on undefined value", R"SOURCE(
1211const x = if (undefined) true else false;1253const x = if (undefined) true else false;
1254
1255export fn entry() -> usize { @sizeOf(@typeOf(x)) }
1212 )SOURCE", 1, ".tmp_source.zig:2:15: error: use of undefined value");1256 )SOURCE", 1, ".tmp_source.zig:2:15: error: use of undefined value");
12131257
12141258
...@@ -1217,12 +1261,16 @@ const seventh_fib_number = fibbonaci(7);...@@ -1217,12 +1261,16 @@ const seventh_fib_number = fibbonaci(7);
1217fn fibbonaci(x: i32) -> i32 {1261fn fibbonaci(x: i32) -> i32 {
1218 return fibbonaci(x - 1) + fibbonaci(x - 2);1262 return fibbonaci(x - 1) + fibbonaci(x - 2);
1219}1263}
1264
1265export fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) }
1220 )SOURCE", 2,1266 )SOURCE", 2,
1221 ".tmp_source.zig:4:21: error: evaluation exceeded 1000 backwards branches",1267 ".tmp_source.zig:4:21: error: evaluation exceeded 1000 backwards branches",
1222 ".tmp_source.zig:4:21: note: called from here");1268 ".tmp_source.zig:4:21: note: called from here");
12231269
1224 add_compile_fail_case("@embedFile with bogus file", R"SOURCE(1270 add_compile_fail_case("@embedFile with bogus file", R"SOURCE(
1225const resource = @embedFile("bogus.txt");1271const resource = @embedFile("bogus.txt");
1272
1273export fn entry() -> usize { @sizeOf(@typeOf(resource)) }
1226 )SOURCE", 1, ".tmp_source.zig:2:29: error: unable to find './bogus.txt'");1274 )SOURCE", 1, ".tmp_source.zig:2:29: error: unable to find './bogus.txt'");
12271275
12281276
...@@ -1232,6 +1280,8 @@ const Foo = struct {...@@ -1232,6 +1280,8 @@ const Foo = struct {
1232};1280};
1233const a = Foo {.x = get_it()};1281const a = Foo {.x = get_it()};
1234extern fn get_it() -> i32;1282extern fn get_it() -> i32;
1283
1284export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1235 )SOURCE", 1, ".tmp_source.zig:5:21: error: unable to evaluate constant expression");1285 )SOURCE", 1, ".tmp_source.zig:5:21: error: unable to evaluate constant expression");
12361286
1237 add_compile_fail_case("non-const expression function call with struct return value outside function", R"SOURCE(1287 add_compile_fail_case("non-const expression function call with struct return value outside function", R"SOURCE(
...@@ -1245,12 +1295,13 @@ fn get_it() -> Foo {...@@ -1245,12 +1295,13 @@ fn get_it() -> Foo {
1245}1295}
1246var global_side_effect = false;1296var global_side_effect = false;
12471297
1298export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1248 )SOURCE", 2,1299 )SOURCE", 2,
1249 ".tmp_source.zig:7:24: error: unable to evaluate constant expression",1300 ".tmp_source.zig:7:24: error: unable to evaluate constant expression",
1250 ".tmp_source.zig:5:17: note: called from here");1301 ".tmp_source.zig:5:17: note: called from here");
12511302
1252 add_compile_fail_case("undeclared identifier error should mark fn as impure", R"SOURCE(1303 add_compile_fail_case("undeclared identifier error should mark fn as impure", R"SOURCE(
1253fn foo() {1304export fn foo() {
1254 test_a_thing();1305 test_a_thing();
1255}1306}
1256fn test_a_thing() {1307fn test_a_thing() {
...@@ -1269,12 +1320,15 @@ const EnumWithData = enum {...@@ -1269,12 +1320,15 @@ const EnumWithData = enum {
1269fn bad_eql_2(a: EnumWithData, b: EnumWithData) -> bool {1320fn bad_eql_2(a: EnumWithData, b: EnumWithData) -> bool {
1270 a == b1321 a == b
1271}1322}
1323
1324export fn entry1() -> usize { @sizeOf(@typeOf(bad_eql_1)) }
1325export fn entry2() -> usize { @sizeOf(@typeOf(bad_eql_2)) }
1272 )SOURCE", 2,1326 )SOURCE", 2,
1273 ".tmp_source.zig:3:7: error: operator not allowed for type '[]u8'",1327 ".tmp_source.zig:3:7: error: operator not allowed for type '[]u8'",
1274 ".tmp_source.zig:10:7: error: operator not allowed for type 'EnumWithData'");1328 ".tmp_source.zig:10:7: error: operator not allowed for type 'EnumWithData'");
12751329
1276 add_compile_fail_case("non-const switch number literal", R"SOURCE(1330 add_compile_fail_case("non-const switch number literal", R"SOURCE(
1277fn foo() {1331export fn foo() {
1278 const x = switch (bar()) {1332 const x = switch (bar()) {
1279 1, 2 => 1,1333 1, 2 => 1,
1280 3, 4 => 2,1334 3, 4 => 2,
...@@ -1284,18 +1338,17 @@ fn foo() {...@@ -1284,18 +1338,17 @@ fn foo() {
1284fn bar() -> i32 {1338fn bar() -> i32 {
1285 21339 2
1286}1340}
1287
1288 )SOURCE", 1, ".tmp_source.zig:3:15: error: unable to infer expression type");1341 )SOURCE", 1, ".tmp_source.zig:3:15: error: unable to infer expression type");
12891342
1290 add_compile_fail_case("atomic orderings of cmpxchg - failure stricter than success", R"SOURCE(1343 add_compile_fail_case("atomic orderings of cmpxchg - failure stricter than success", R"SOURCE(
1291fn f() {1344export fn f() {
1292 var x: i32 = 1234;1345 var x: i32 = 1234;
1293 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}1346 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
1294}1347}
1295 )SOURCE", 1, ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success");1348 )SOURCE", 1, ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success");
12961349
1297 add_compile_fail_case("atomic orderings of cmpxchg - success Monotonic or stricter", R"SOURCE(1350 add_compile_fail_case("atomic orderings of cmpxchg - success Monotonic or stricter", R"SOURCE(
1298fn f() {1351export fn f() {
1299 var x: i32 = 1234;1352 var x: i32 = 1234;
1300 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}1353 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
1301}1354}
...@@ -1306,6 +1359,8 @@ const y = neg(-128);...@@ -1306,6 +1359,8 @@ const y = neg(-128);
1306fn neg(x: i8) -> i8 {1359fn neg(x: i8) -> i8 {
1307 -x1360 -x
1308}1361}
1362
1363export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1309 )SOURCE", 2,1364 )SOURCE", 2,
1310 ".tmp_source.zig:4:5: error: negation caused overflow",1365 ".tmp_source.zig:4:5: error: negation caused overflow",
1311 ".tmp_source.zig:2:14: note: called from here");1366 ".tmp_source.zig:2:14: note: called from here");
...@@ -1315,6 +1370,8 @@ const y = add(65530, 10);...@@ -1315,6 +1370,8 @@ const y = add(65530, 10);
1315fn add(a: u16, b: u16) -> u16 {1370fn add(a: u16, b: u16) -> u16 {
1316 a + b1371 a + b
1317}1372}
1373
1374export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1318 )SOURCE", 2,1375 )SOURCE", 2,
1319 ".tmp_source.zig:4:7: error: operation caused overflow",1376 ".tmp_source.zig:4:7: error: operation caused overflow",
1320 ".tmp_source.zig:2:14: note: called from here");1377 ".tmp_source.zig:2:14: note: called from here");
...@@ -1325,6 +1382,8 @@ const y = sub(10, 20);...@@ -1325,6 +1382,8 @@ const y = sub(10, 20);
1325fn sub(a: u16, b: u16) -> u16 {1382fn sub(a: u16, b: u16) -> u16 {
1326 a - b1383 a - b
1327}1384}
1385
1386export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1328 )SOURCE", 2,1387 )SOURCE", 2,
1329 ".tmp_source.zig:4:7: error: operation caused overflow",1388 ".tmp_source.zig:4:7: error: operation caused overflow",
1330 ".tmp_source.zig:2:14: note: called from here");1389 ".tmp_source.zig:2:14: note: called from here");
...@@ -1334,6 +1393,8 @@ const y = mul(300, 6000);...@@ -1334,6 +1393,8 @@ const y = mul(300, 6000);
1334fn mul(a: u16, b: u16) -> u16 {1393fn mul(a: u16, b: u16) -> u16 {
1335 a * b1394 a * b
1336}1395}
1396
1397export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1337 )SOURCE", 2,1398 )SOURCE", 2,
1338 ".tmp_source.zig:4:7: error: operation caused overflow",1399 ".tmp_source.zig:4:7: error: operation caused overflow",
1339 ".tmp_source.zig:2:14: note: called from here");1400 ".tmp_source.zig:2:14: note: called from here");
...@@ -1343,10 +1404,12 @@ fn f() -> i8 {...@@ -1343,10 +1404,12 @@ fn f() -> i8 {
1343 const x: u32 = 10;1404 const x: u32 = 10;
1344 @truncate(i8, x)1405 @truncate(i8, x)
1345}1406}
1407
1408export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1346 )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, found 'u32'");1409 )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, found 'u32'");
13471410
1348 add_compile_fail_case("%return in function with non error return type", R"SOURCE(1411 add_compile_fail_case("%return in function with non error return type", R"SOURCE(
1349fn f() {1412export fn f() {
1350 %return something();1413 %return something();
1351}1414}
1352fn something() -> %void { }1415fn something() -> %void { }
...@@ -1361,7 +1424,7 @@ pub fn main(args: [][]u8) { }...@@ -1361,7 +1424,7 @@ pub fn main(args: [][]u8) { }
1361 add_compile_fail_case("invalid pointer for var type", R"SOURCE(1424 add_compile_fail_case("invalid pointer for var type", R"SOURCE(
1362extern fn ext() -> usize;1425extern fn ext() -> usize;
1363var bytes: [ext()]u8 = undefined;1426var bytes: [ext()]u8 = undefined;
1364fn f() {1427export fn f() {
1365 for (bytes) |*b, i| {1428 for (bytes) |*b, i| {
1366 *b = u8(i);1429 *b = u8(i);
1367 }1430 }
...@@ -1379,10 +1442,11 @@ extern fn foo(comptime x: i32, y: i32) -> i32;...@@ -1379,10 +1442,11 @@ extern fn foo(comptime x: i32, y: i32) -> i32;
1379fn f() -> i32 {1442fn f() -> i32 {
1380 foo(1, 2)1443 foo(1, 2)
1381}1444}
1445export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1382 )SOURCE", 1, ".tmp_source.zig:2:15: error: comptime parameter not allowed in extern function");1446 )SOURCE", 1, ".tmp_source.zig:2:15: error: comptime parameter not allowed in extern function");
13831447
1384 add_compile_fail_case("convert fixed size array to slice with invalid size", R"SOURCE(1448 add_compile_fail_case("convert fixed size array to slice with invalid size", R"SOURCE(
1385fn f() {1449export fn f() {
1386 var array: [5]u8 = undefined;1450 var array: [5]u8 = undefined;
1387 var foo = ([]const u32)(array)[0];1451 var foo = ([]const u32)(array)[0];
1388}1452}
...@@ -1403,7 +1467,7 @@ pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {...@@ -1403,7 +1467,7 @@ pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
1403 }1467 }
1404}1468}
14051469
1406fn function_with_return_type_type() {1470export fn function_with_return_type_type() {
1407 var list: List(i32) = undefined;1471 var list: List(i32) = undefined;
1408 list.length = 10;1472 list.length = 10;
1409}1473}
...@@ -1417,6 +1481,7 @@ var self = "aoeu";...@@ -1417,6 +1481,7 @@ var self = "aoeu";
1417fn f(m: []const u8) {1481fn f(m: []const u8) {
1418 m.copy(u8, self[0...], m);1482 m.copy(u8, self[0...], m);
1419}1483}
1484export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1420 )SOURCE", 1, ".tmp_source.zig:4:6: error: no member named 'copy' in '[]const u8'");1485 )SOURCE", 1, ".tmp_source.zig:4:6: error: no member named 'copy' in '[]const u8'");
14211486
1422 add_compile_fail_case("wrong number of arguments for method fn call", R"SOURCE(1487 add_compile_fail_case("wrong number of arguments for method fn call", R"SOURCE(
...@@ -1427,17 +1492,18 @@ fn f(foo: &const Foo) {...@@ -1427,17 +1492,18 @@ fn f(foo: &const Foo) {
14271492
1428 foo.method(1, 2);1493 foo.method(1, 2);
1429}1494}
1495export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1430 )SOURCE", 1, ".tmp_source.zig:7:15: error: expected 2 arguments, found 3");1496 )SOURCE", 1, ".tmp_source.zig:7:15: error: expected 2 arguments, found 3");
14311497
1432 add_compile_fail_case("assign through constant pointer", R"SOURCE(1498 add_compile_fail_case("assign through constant pointer", R"SOURCE(
1433fn f() {1499export fn f() {
1434 var cstr = c"Hat";1500 var cstr = c"Hat";
1435 cstr[0] = 'W';1501 cstr[0] = 'W';
1436}1502}
1437 )SOURCE", 1, ".tmp_source.zig:4:11: error: cannot assign to constant");1503 )SOURCE", 1, ".tmp_source.zig:4:11: error: cannot assign to constant");
14381504
1439 add_compile_fail_case("assign through constant slice", R"SOURCE(1505 add_compile_fail_case("assign through constant slice", R"SOURCE(
1440pub fn f() {1506export fn f() {
1441 var cstr: []const u8 = "Hat";1507 var cstr: []const u8 = "Hat";
1442 cstr[0] = 'W';1508 cstr[0] = 'W';
1443}1509}
...@@ -1451,6 +1517,7 @@ pub fn main(args: [][]bogus) -> %void {}...@@ -1451,6 +1517,7 @@ pub fn main(args: [][]bogus) -> %void {}
1451fn foo(blah: []u8) {1517fn foo(blah: []u8) {
1452 for (blah) { }1518 for (blah) { }
1453}1519}
1520export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1454 )SOURCE", 1, ".tmp_source.zig:3:5: error: for loop expression missing element parameter");1521 )SOURCE", 1, ".tmp_source.zig:3:5: error: for loop expression missing element parameter");
14551522
1456 add_compile_fail_case("misspelled type with pointer only reference", R"SOURCE(1523 add_compile_fail_case("misspelled type with pointer only reference", R"SOURCE(
...@@ -1482,6 +1549,8 @@ fn foo() {...@@ -1482,6 +1549,8 @@ fn foo() {
1482 jll.init(1234);1549 jll.init(1234);
1483 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };1550 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
1484}1551}
1552
1553export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1485 )SOURCE", 1, ".tmp_source.zig:6:16: error: use of undeclared identifier 'JsonList'");1554 )SOURCE", 1, ".tmp_source.zig:6:16: error: use of undeclared identifier 'JsonList'");
14861555
1487 add_compile_fail_case("method call with first arg type primitive", R"SOURCE(1556 add_compile_fail_case("method call with first arg type primitive", R"SOURCE(
...@@ -1495,7 +1564,7 @@ const Foo = struct {...@@ -1495,7 +1564,7 @@ const Foo = struct {
1495 }1564 }
1496};1565};
14971566
1498fn f() {1567export fn f() {
1499 const derp = Foo.init(3);1568 const derp = Foo.init(3);
15001569
1501 derp.init();1570 derp.init();
...@@ -1523,7 +1592,7 @@ pub const Allocator = struct {...@@ -1523,7 +1592,7 @@ pub const Allocator = struct {
1523 field: i32,1592 field: i32,
1524};1593};
15251594
1526fn foo() {1595export fn foo() {
1527 var x = List.init(&global_allocator);1596 var x = List.init(&global_allocator);
1528 x.init();1597 x.init();
1529}1598}
...@@ -1533,13 +1602,15 @@ fn foo() {...@@ -1533,13 +1602,15 @@ fn foo() {
1533const TINY_QUANTUM_SHIFT = 4;1602const TINY_QUANTUM_SHIFT = 4;
1534const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;1603const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
1535var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);1604var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
1605
1606export fn entry() -> usize { @sizeOf(@typeOf(block_aligned_stuff)) }
1536 )SOURCE", 1, ".tmp_source.zig:4:60: error: unable to perform binary not operation on type '(integer literal)'");1607 )SOURCE", 1, ".tmp_source.zig:4:60: error: unable to perform binary not operation on type '(integer literal)'");
15371608
1538 {1609 {
1539 TestCase *tc = add_compile_fail_case("multiple files with private function error", R"SOURCE(1610 TestCase *tc = add_compile_fail_case("multiple files with private function error", R"SOURCE(
1540const foo = @import("foo.zig");1611const foo = @import("foo.zig");
15411612
1542fn callPrivFunction() {1613export fn callPrivFunction() {
1543 foo.privateFunction();1614 foo.privateFunction();
1544}1615}
1545 )SOURCE", 2, 1616 )SOURCE", 2,
...@@ -1554,13 +1625,15 @@ fn privateFunction() { }...@@ -1554,13 +1625,15 @@ fn privateFunction() { }
1554 add_compile_fail_case("container init with non-type", R"SOURCE(1625 add_compile_fail_case("container init with non-type", R"SOURCE(
1555const zero: i32 = 0;1626const zero: i32 = 0;
1556const a = zero{1};1627const a = zero{1};
1628
1629export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1557 )SOURCE", 1, ".tmp_source.zig:3:11: error: expected type, found 'i32'");1630 )SOURCE", 1, ".tmp_source.zig:3:11: error: expected type, found 'i32'");
15581631
1559 add_compile_fail_case("assign to constant field", R"SOURCE(1632 add_compile_fail_case("assign to constant field", R"SOURCE(
1560const Foo = struct {1633const Foo = struct {
1561 field: i32,1634 field: i32,
1562};1635};
1563fn derp() {1636export fn derp() {
1564 const f = Foo {.field = 1234,};1637 const f = Foo {.field = 1234,};
1565 f.field = 0;1638 f.field = 0;
1566}1639}
...@@ -1580,6 +1653,8 @@ fn canFail() -> %void { }...@@ -1580,6 +1653,8 @@ fn canFail() -> %void { }
1580pub fn maybeInt() -> ?i32 {1653pub fn maybeInt() -> ?i32 {
1581 return 0;1654 return 0;
1582}1655}
1656
1657export fn entry() -> usize { @sizeOf(@typeOf(testTrickyDefer)) }
1583 )SOURCE", 1, ".tmp_source.zig:5:11: error: cannot return from defer expression");1658 )SOURCE", 1, ".tmp_source.zig:5:11: error: cannot return from defer expression");
15841659
1585 add_compile_fail_case("attempt to access var args out of bounds", R"SOURCE(1660 add_compile_fail_case("attempt to access var args out of bounds", R"SOURCE(
...@@ -1590,6 +1665,8 @@ fn add(args: ...) -> i32 {...@@ -1590,6 +1665,8 @@ fn add(args: ...) -> i32 {
1590fn foo() -> i32 {1665fn foo() -> i32 {
1591 add(i32(1234))1666 add(i32(1234))
1592}1667}
1668
1669export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1593 )SOURCE", 2,1670 )SOURCE", 2,
1594 ".tmp_source.zig:3:19: error: index 1 outside argument list of size 1",1671 ".tmp_source.zig:3:19: error: index 1 outside argument list of size 1",
1595 ".tmp_source.zig:7:8: note: called from here");1672 ".tmp_source.zig:7:8: note: called from here");
...@@ -1606,10 +1683,12 @@ fn add(args: ...) -> i32 {...@@ -1606,10 +1683,12 @@ fn add(args: ...) -> i32 {
1606fn bar() -> i32 {1683fn bar() -> i32 {
1607 add(1, 2, 3, 4)1684 add(1, 2, 3, 4)
1608}1685}
1686
1687export fn entry() -> usize { @sizeOf(@typeOf(bar)) }
1609 )SOURCE", 1, ".tmp_source.zig:11:9: error: parameter of type '(integer literal)' requires comptime");1688 )SOURCE", 1, ".tmp_source.zig:11:9: error: parameter of type '(integer literal)' requires comptime");
16101689
1611 add_compile_fail_case("assign too big number to u16", R"SOURCE(1690 add_compile_fail_case("assign too big number to u16", R"SOURCE(
1612fn foo() {1691export fn foo() {
1613 var vga_mem: u16 = 0xB8000;1692 var vga_mem: u16 = 0xB8000;
1614}1693}
1615 )SOURCE", 1, ".tmp_source.zig:3:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");1694 )SOURCE", 1, ".tmp_source.zig:3:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");
...@@ -1619,10 +1698,11 @@ const some_data: [100]u8 = {...@@ -1619,10 +1698,11 @@ const some_data: [100]u8 = {
1619 @setGlobalAlign(some_data, 3);1698 @setGlobalAlign(some_data, 3);
1620 undefined1699 undefined
1621};1700};
1701export fn entry() -> usize { @sizeOf(@typeOf(some_data)) }
1622 )SOURCE", 1, ".tmp_source.zig:3:32: error: alignment value must be power of 2");1702 )SOURCE", 1, ".tmp_source.zig:3:32: error: alignment value must be power of 2");
16231703
1624 add_compile_fail_case("compile log", R"SOURCE(1704 add_compile_fail_case("compile log", R"SOURCE(
1625fn foo() {1705export fn foo() {
1626 comptime bar(12, "hi");1706 comptime bar(12, "hi");
1627}1707}
1628fn bar(a: i32, b: []const u8) {1708fn bar(a: i32, b: []const u8) {
...@@ -1660,9 +1740,11 @@ fn foo(bit_field: &const BitField) -> u3 {...@@ -1660,9 +1740,11 @@ fn foo(bit_field: &const BitField) -> u3 {
1660fn bar(x: &const u3) -> u3 {1740fn bar(x: &const u3) -> u3 {
1661 return *x;1741 return *x;
1662}1742}
1743
1744export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1663 )SOURCE", 1, ".tmp_source.zig:12:26: error: expected type '&const u3', found '&:3:6 const u3'");1745 )SOURCE", 1, ".tmp_source.zig:12:26: error: expected type '&const u3', found '&:3:6 const u3'");
16641746
1665 add_compile_fail_case_no_check_unused("referring to a struct that is invalid without --check-unused", R"SOURCE(1747 add_compile_fail_case("referring to a struct that is invalid", R"SOURCE(
1666const UsbDeviceRequest = struct {1748const UsbDeviceRequest = struct {
1667 Type: u8,1749 Type: u8,
1668};1750};
...@@ -1679,7 +1761,7 @@ fn assert(ok: bool) {...@@ -1679,7 +1761,7 @@ fn assert(ok: bool) {
1679 ".tmp_source.zig:7:20: note: called from here");1761 ".tmp_source.zig:7:20: note: called from here");
16801762
1681 add_compile_fail_case("control flow uses comptime var at runtime", R"SOURCE(1763 add_compile_fail_case("control flow uses comptime var at runtime", R"SOURCE(
1682fn foo() {1764export fn foo() {
1683 comptime var i = 0;1765 comptime var i = 0;
1684 while (i < 5; i += 1) {1766 while (i < 5; i += 1) {
1685 bar();1767 bar();
...@@ -1692,14 +1774,14 @@ fn bar() { }...@@ -1692,14 +1774,14 @@ fn bar() { }
1692 ".tmp_source.zig:4:21: note: compile-time variable assigned here");1774 ".tmp_source.zig:4:21: note: compile-time variable assigned here");
16931775
1694 add_compile_fail_case("ignored return value", R"SOURCE(1776 add_compile_fail_case("ignored return value", R"SOURCE(
1695fn foo() {1777export fn foo() {
1696 bar();1778 bar();
1697}1779}
1698fn bar() -> i32 { 0 }1780fn bar() -> i32 { 0 }
1699 )SOURCE", 1, ".tmp_source.zig:3:8: error: return value ignored");1781 )SOURCE", 1, ".tmp_source.zig:3:8: error: return value ignored");
17001782
1701 add_compile_fail_case("integer literal on a non-comptime var", R"SOURCE(1783 add_compile_fail_case("integer literal on a non-comptime var", R"SOURCE(
1702fn foo() {1784export fn foo() {
1703 var i = 0;1785 var i = 0;
1704 while (i < 10; i += 1) { }1786 while (i < 10; i += 1) { }
1705}1787}
...@@ -1712,6 +1794,8 @@ pub fn pass(in: []u8) -> []u8 {...@@ -1712,6 +1794,8 @@ pub fn pass(in: []u8) -> []u8 {
1712 *out[0] = in[0];1794 *out[0] = in[0];
1713 return (*out)[0...1];1795 return (*out)[0...1];
1714}1796}
1797
1798export fn entry() -> usize { @sizeOf(@typeOf(pass)) }
1715 )SOURCE", 1, ".tmp_source.zig:5:5: error: attempt to dereference non pointer type '[10]u8'");1799 )SOURCE", 1, ".tmp_source.zig:5:5: error: attempt to dereference non pointer type '[10]u8'");
17161800
1717 add_compile_fail_case("pass const ptr to mutable ptr fn", R"SOURCE(1801 add_compile_fail_case("pass const ptr to mutable ptr fn", R"SOURCE(
...@@ -1723,6 +1807,8 @@ fn foo() -> bool {...@@ -1723,6 +1807,8 @@ fn foo() -> bool {
1723fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool {1807fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool {
1724 return true;1808 return true;
1725}1809}
1810
1811export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1726 )SOURCE", 1, ".tmp_source.zig:5:19: error: expected type '&[]const u8', found '&const []const u8'");1812 )SOURCE", 1, ".tmp_source.zig:5:19: error: expected type '&[]const u8', found '&const []const u8'");
1727}1813}
17281814
...@@ -2159,23 +2245,69 @@ static void run_self_hosted_test(bool is_release_mode) {...@@ -2159,23 +2245,69 @@ static void run_self_hosted_test(bool is_release_mode) {
2159 }2245 }
2160}2246}
21612247
2248static void run_std_lib_test(bool is_release_mode) {
2249 Buf std_index_file = BUF_INIT;
2250 os_path_join(buf_create_from_str(ZIG_STD_DIR),
2251 buf_create_from_str("index.zig"), &std_index_file);
2252
2253 Buf zig_stderr = BUF_INIT;
2254 Buf zig_stdout = BUF_INIT;
2255 ZigList<const char *> args = {0};
2256 args.append("test");
2257 args.append(buf_ptr(&std_index_file));
2258 if (is_release_mode) {
2259 args.append("--release");
2260 }
2261 Termination term;
2262 os_exec_process(zig_exe, args, &term, &zig_stderr, &zig_stdout);
2263
2264 if (term.how != TerminationIdClean || term.code != 0) {
2265 printf("\nstd lib tests failed:\n");
2266 printf("./zig");
2267 for (size_t i = 0; i < args.length; i += 1) {
2268 printf(" %s", args.at(i));
2269 }
2270 printf("\n%s\n", buf_ptr(&zig_stderr));
2271 exit(1);
2272 }
2273}
2274
2275
2162static void add_self_hosted_tests(void) {2276static void add_self_hosted_tests(void) {
2163 {2277 {
2164 TestCase *test_case = allocate<TestCase>(1);2278 TestCase *test_case = allocate<TestCase>(1);
2165 test_case->case_name = "self hosted tests (debug)";2279 test_case->case_name = "self hosted tests (debug)";
2166 test_case->is_self_hosted = true;2280 test_case->special = TestSpecialSelfHosted;
2167 test_case->is_release_mode = false;2281 test_case->is_release_mode = false;
2168 test_cases.append(test_case);2282 test_cases.append(test_case);
2169 }2283 }
2170 {2284 {
2171 TestCase *test_case = allocate<TestCase>(1);2285 TestCase *test_case = allocate<TestCase>(1);
2172 test_case->case_name = "self hosted tests (release)";2286 test_case->case_name = "self hosted tests (release)";
2173 test_case->is_self_hosted = true;2287 test_case->special = TestSpecialSelfHosted;
2174 test_case->is_release_mode = true;2288 test_case->is_release_mode = true;
2175 test_cases.append(test_case);2289 test_cases.append(test_case);
2176 }2290 }
2177}2291}
21782292
2293static void add_std_lib_tests(void) {
2294 {
2295 TestCase *test_case = allocate<TestCase>(1);
2296 test_case->case_name = "std (debug)";
2297 test_case->special = TestSpecialStd;
2298 test_case->is_release_mode = false;
2299 test_cases.append(test_case);
2300 }
2301 {
2302 TestCase *test_case = allocate<TestCase>(1);
2303 test_case->case_name = "std (release)";
2304 test_case->special = TestSpecialStd;
2305 test_case->is_release_mode = true;
2306 test_cases.append(test_case);
2307 }
2308}
2309
2310
2179static void print_compiler_invocation(TestCase *test_case) {2311static void print_compiler_invocation(TestCase *test_case) {
2180 printf("%s", zig_exe);2312 printf("%s", zig_exe);
2181 for (size_t i = 0; i < test_case->compiler_args.length; i += 1) {2313 for (size_t i = 0; i < test_case->compiler_args.length; i += 1) {
...@@ -2193,8 +2325,10 @@ static void print_exe_invocation(TestCase *test_case) {...@@ -2193,8 +2325,10 @@ static void print_exe_invocation(TestCase *test_case) {
2193}2325}
21942326
2195static void run_test(TestCase *test_case) {2327static void run_test(TestCase *test_case) {
2196 if (test_case->is_self_hosted) {2328 if (test_case->special == TestSpecialSelfHosted) {
2197 return run_self_hosted_test(test_case->is_release_mode);2329 return run_self_hosted_test(test_case->is_release_mode);
2330 } else if (test_case->special == TestSpecialStd) {
2331 return run_std_lib_test(test_case->is_release_mode);
2198 }2332 }
21992333
2200 for (size_t i = 0; i < test_case->source_files.length; i += 1) {2334 for (size_t i = 0; i < test_case->source_files.length; i += 1) {
...@@ -2366,6 +2500,7 @@ int main(int argc, char **argv) {...@@ -2366,6 +2500,7 @@ int main(int argc, char **argv) {
2366 add_compile_failure_test_cases();2500 add_compile_failure_test_cases();
2367 add_parseh_test_cases();2501 add_parseh_test_cases();
2368 add_self_hosted_tests();2502 add_self_hosted_tests();
2503 add_std_lib_tests();
2369 run_all_tests(reverse);2504 run_all_tests(reverse);
2370 cleanup();2505 cleanup();
2371}2506}