aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-03 21:34:09 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-03 21:34:09 -0700
commit2521afef699d40917db906ebb27a87c5ea287fbe (patch)
treea42906cf33e4199b81f8aba70153120cd4aa5c0f /test
parent5c310f43432ec723f8b7d449313c1ea20f1f2d78 (diff)
downloadzig-2521afef699d40917db906ebb27a87c5ea287fbe.tar.gz
zig-2521afef699d40917db906ebb27a87c5ea287fbe.zip
add ability to call function pointer field
also introduce the self hosted tests closes #108
Diffstat (limited to 'test')
-rw-r--r--test/run_tests.cpp45
-rw-r--r--test/self_hosted.zig37
2 files changed, 67 insertions, 15 deletions
diff --git a/test/run_tests.cpp b/test/run_tests.cpp
index f3a7145f17..3f9eafcda0 100644
--- a/test/run_tests.cpp
+++ b/test/run_tests.cpp
@@ -25,6 +25,7 @@ struct TestCase {
ZigList<const char *> compiler_args;
ZigList<const char *> program_args;
bool is_parseh;
+ bool is_self_hosted;
};
static ZigList<TestCase*> test_cases = {0};
@@ -157,21 +158,6 @@ fn this_is_a_function() -> unreachable {
}
)SOURCE", "OK\n");
- add_simple_case("comments", R"SOURCE(
-import "std.zig";
-
-/**
- * multi line doc comment
- */
-fn another_function() {}
-
-/// this is a documentation comment
-/// doc comment line 2
-pub fn main(args: [][]u8) -> %void {
- %%stdout.printf(/* mid-line comment /* nested */ */ "OK\n");
-}
- )SOURCE", "OK\n");
-
{
TestCase *tc = add_simple_case("multiple files with private function", R"SOURCE(
import "std.zig";
@@ -2205,6 +2191,30 @@ extern void (*fn_ptr)(void);
})SOURCE");
}
+static void run_self_hosted_test(void) {
+ Buf zig_stderr = BUF_INIT;
+ Buf zig_stdout = BUF_INIT;
+ int return_code;
+ ZigList<const char *> args = {0};
+ args.append("test");
+ args.append("../test/self_hosted.zig");
+ os_exec_process(zig_exe, args, &return_code, &zig_stderr, &zig_stdout);
+
+ if (return_code) {
+ printf("\nSelf-hosted tests failed:\n");
+ printf("./zig test ../test/self_hosted.zig\n");
+ printf("%s\n", buf_ptr(&zig_stderr));
+ exit(1);
+ }
+}
+
+static void add_self_hosted_tests(void) {
+ TestCase *test_case = allocate<TestCase>(1);
+ test_case->case_name = "self hosted tests";
+ test_case->is_self_hosted = true;
+ test_cases.append(test_case);
+}
+
static void print_compiler_invocation(TestCase *test_case) {
printf("%s", zig_exe);
for (int i = 0; i < test_case->compiler_args.length; i += 1) {
@@ -2214,6 +2224,10 @@ static void print_compiler_invocation(TestCase *test_case) {
}
static void run_test(TestCase *test_case) {
+ if (test_case->is_self_hosted) {
+ return run_self_hosted_test();
+ }
+
for (int i = 0; i < test_case->source_files.length; i += 1) {
TestSourceFile *test_source = &test_case->source_files.at(i);
os_write_file(
@@ -2359,6 +2373,7 @@ int main(int argc, char **argv) {
add_compiling_test_cases();
add_compile_failure_test_cases();
add_parseh_test_cases();
+ add_self_hosted_tests();
run_all_tests(reverse);
cleanup();
}
diff --git a/test/self_hosted.zig b/test/self_hosted.zig
new file mode 100644
index 0000000000..cc5fd73750
--- /dev/null
+++ b/test/self_hosted.zig
@@ -0,0 +1,37 @@
+#attribute("test")
+fn empty_function() {}
+
+
+
+
+/**
+ * multi line doc comment
+ */
+/// this is a documentation comment
+/// doc comment line 2
+#attribute("test")
+fn comments() {
+ comments_f1(/* mid-line comment /* nested */ */ "OK\n");
+}
+
+fn comments_f1(s: []u8) {}
+
+
+
+
+#attribute("test")
+fn fn_call_of_struct_field() {
+ if (call_struct_field(Foo {.ptr = a_func,}) != 13) {
+ unreachable{};
+ }
+}
+
+struct Foo {
+ ptr: fn() -> i32,
+}
+
+fn a_func() -> i32 { 13 }
+
+fn call_struct_field(foo: Foo) -> i32 {
+ return foo.ptr();
+}