authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-17 06:58:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-17 06:58:36-04:00
log401eed8153d909eda4146b5a1815dee7130cf1c3
tree88aa4d79c7e4a56b9d66834f776dc70ace32d6ce
parent05b3082121e225ec2dfc9a062c765b4b60befaef

build examples in ./run_tests

closes #325

1 files changed, 33 insertions(+), 1 deletions(-)

test/run_tests.cpp+33-1
...@@ -211,6 +211,28 @@ static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warn...@@ -211,6 +211,28 @@ static TestCase *add_parseh_case(const char *case_name, AllowWarnings allow_warn
211 return test_case;211 return test_case;
212}212}
213213
214static TestCase *add_example_compile_extra(const char *root_source_file, bool libc) {
215 TestCase *test_case = allocate<TestCase>(1);
216 test_case->case_name = buf_ptr(buf_sprintf("build example %s", root_source_file));
217 test_case->output = nullptr;
218 test_case->special = TestSpecialNone;
219
220 test_case->compiler_args.append("build_exe");
221 test_case->compiler_args.append(buf_ptr(buf_sprintf("../%s", root_source_file)));
222
223 test_cases.append(test_case);
224
225 return test_case;
226}
227
228static TestCase *add_example_compile(const char *root_source_file) {
229 return add_example_compile_extra(root_source_file, false);
230}
231
232static TestCase *add_example_compile_libc(const char *root_source_file) {
233 return add_example_compile_extra(root_source_file, true);
234}
235
214static void add_compiling_test_cases(void) {236static void add_compiling_test_cases(void) {
215 add_simple_case_libc("hello world with libc", R"SOURCE(237 add_simple_case_libc("hello world with libc", R"SOURCE(
216const c = @cImport(@cInclude("stdio.h"));238const c = @cImport(@cInclude("stdio.h"));
...@@ -617,6 +639,15 @@ pub fn main() -> %void {...@@ -617,6 +639,15 @@ pub fn main() -> %void {
617 }639 }
618}640}
619641
642////////////////////////////////////////////////////////////////////////////////////
643
644static void add_build_examples(void) {
645 add_example_compile("example/hello_world/hello.zig");
646 add_example_compile_libc("example/hello_world/hello_libc.zig");
647 add_example_compile("example/cat/main.zig");
648 add_example_compile("example/guess_number/main.zig");
649}
650
620651
621////////////////////////////////////////////////////////////////////////////////////652////////////////////////////////////////////////////////////////////////////////////
622653
...@@ -2825,7 +2856,7 @@ static void run_test(TestCase *test_case) {...@@ -2825,7 +2856,7 @@ static void run_test(TestCase *test_case) {
2825 exit(1);2856 exit(1);
2826 }2857 }
28272858
2828 if (!buf_eql_str(&program_stdout, test_case->output)) {2859 if (test_case->output != nullptr && !buf_eql_str(&program_stdout, test_case->output)) {
2829 printf("\n");2860 printf("\n");
2830 print_compiler_invocation(test_case);2861 print_compiler_invocation(test_case);
2831 print_exe_invocation(test_case);2862 print_exe_invocation(test_case);
...@@ -2887,6 +2918,7 @@ int main(int argc, char **argv) {...@@ -2887,6 +2918,7 @@ int main(int argc, char **argv) {
2887 }2918 }
2888 }2919 }
2889 add_compiling_test_cases();2920 add_compiling_test_cases();
2921 add_build_examples();
2890 add_debug_safety_test_cases();2922 add_debug_safety_test_cases();
2891 add_compile_failure_test_cases();2923 add_compile_failure_test_cases();
2892 add_parse_error_tests();2924 add_parse_error_tests();