From efa1092199aecdb6ee96ec73782817a5852286dd Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 6 Oct 2021 00:14:16 +0300 Subject: [PATCH] v.gen.c: add coutput tests for the `[console]` codegen to prevent future regressions --- vlib/v/gen/c/fn.v | 2 +- .../v/gen/c/testdata/console_windows_program.c.must_have | 1 + vlib/v/gen/c/testdata/console_windows_program.vv | 6 ++++++ vlib/v/gen/c/testdata/gui_windows_program.c.must_have | 1 + vlib/v/gen/c/testdata/gui_windows_program.vv | 8 ++++++++ .../gui_windows_program_with_console_tag.c.must_have | 1 + .../c/testdata/gui_windows_program_with_console_tag.vv | 9 +++++++++ 7 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 vlib/v/gen/c/testdata/console_windows_program.c.must_have create mode 100644 vlib/v/gen/c/testdata/console_windows_program.vv create mode 100644 vlib/v/gen/c/testdata/gui_windows_program.c.must_have create mode 100644 vlib/v/gen/c/testdata/gui_windows_program.vv create mode 100644 vlib/v/gen/c/testdata/gui_windows_program_with_console_tag.c.must_have create mode 100644 vlib/v/gen/c/testdata/gui_windows_program_with_console_tag.vv diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 15fdf201d5..c83ca39995 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1483,7 +1483,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as } fn (mut g Gen) is_gui_app() bool { - $if windows { + if g.pref.os == .windows { if g.force_main_console { return false } diff --git a/vlib/v/gen/c/testdata/console_windows_program.c.must_have b/vlib/v/gen/c/testdata/console_windows_program.c.must_have new file mode 100644 index 0000000000..d6c325c1f7 --- /dev/null +++ b/vlib/v/gen/c/testdata/console_windows_program.c.must_have @@ -0,0 +1 @@ +int wmain(int ___argc, wchar_t* ___argv[], wchar_t* ___envp[]){ diff --git a/vlib/v/gen/c/testdata/console_windows_program.vv b/vlib/v/gen/c/testdata/console_windows_program.vv new file mode 100644 index 0000000000..7e935d4253 --- /dev/null +++ b/vlib/v/gen/c/testdata/console_windows_program.vv @@ -0,0 +1,6 @@ +// vtest vflags: -cc msvc -os windows + +[console] +fn main() { + println('hello world') +} diff --git a/vlib/v/gen/c/testdata/gui_windows_program.c.must_have b/vlib/v/gen/c/testdata/gui_windows_program.c.must_have new file mode 100644 index 0000000000..d14abb19fe --- /dev/null +++ b/vlib/v/gen/c/testdata/gui_windows_program.c.must_have @@ -0,0 +1 @@ +int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, LPWSTR cmd_line, int show_cmd){ diff --git a/vlib/v/gen/c/testdata/gui_windows_program.vv b/vlib/v/gen/c/testdata/gui_windows_program.vv new file mode 100644 index 0000000000..d5f55ca7e6 --- /dev/null +++ b/vlib/v/gen/c/testdata/gui_windows_program.vv @@ -0,0 +1,8 @@ +// vtest vflags: -cc msvc -os windows +import sokol + +const used_import = sokol.used_import + +fn main() { + println('hello world') +} diff --git a/vlib/v/gen/c/testdata/gui_windows_program_with_console_tag.c.must_have b/vlib/v/gen/c/testdata/gui_windows_program_with_console_tag.c.must_have new file mode 100644 index 0000000000..d6c325c1f7 --- /dev/null +++ b/vlib/v/gen/c/testdata/gui_windows_program_with_console_tag.c.must_have @@ -0,0 +1 @@ +int wmain(int ___argc, wchar_t* ___argv[], wchar_t* ___envp[]){ diff --git a/vlib/v/gen/c/testdata/gui_windows_program_with_console_tag.vv b/vlib/v/gen/c/testdata/gui_windows_program_with_console_tag.vv new file mode 100644 index 0000000000..bd57d9f4e6 --- /dev/null +++ b/vlib/v/gen/c/testdata/gui_windows_program_with_console_tag.vv @@ -0,0 +1,9 @@ +// vtest vflags: -cc msvc -os windows +import sokol + +const used_import = sokol.used_import + +[console] +fn main() { + println('hello world') +}