From 653121bad9a087524bdea20f790892f716d49777 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Thu, 7 Jan 2021 21:36:59 +0100 Subject: [PATCH] fmt: test bin2v output formatting (#7926) --- vlib/v/fmt/fmt_keep_test.v | 16 ++++++++++++++++ vlib/v/fmt/tests/bin2v_keep.vv | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 vlib/v/fmt/tests/bin2v_keep.vv diff --git a/vlib/v/fmt/fmt_keep_test.v b/vlib/v/fmt/fmt_keep_test.v index 003d1465c3..f3dd72f077 100644 --- a/vlib/v/fmt/fmt_keep_test.v +++ b/vlib/v/fmt/fmt_keep_test.v @@ -12,6 +12,7 @@ import v.util.vtest const ( error_missing_vexe = 1 error_failed_tests = 2 + b2v_keep_path = os.join_path('vlib', 'v', 'fmt', 'tests', 'bin2v_keep.vv') ) fn test_fmt() { @@ -28,6 +29,7 @@ fn test_fmt() { tmpfolder := os.temp_dir() diff_cmd := util.find_working_diff_command() or { '' } mut fmt_bench := benchmark.new_benchmark() + fill_bin2v_keep() or { eprintln('failed creating vbin2v_keep.vv: $err') } keep_input_files := os.walk_ext('vlib/v/fmt/tests', '_keep.vv') expected_input_files := os.walk_ext('vlib/v/fmt/tests', '_expected.vv') mut input_files := []string{} @@ -69,6 +71,7 @@ fn test_fmt() { fmt_bench.ok() eprintln(fmt_bench.step_message_ok('$vrelpath')) } + restore_bin2v_placeholder() or { eprintln('failed restoring vbin2v_keep.vv placeholder: $err') } fmt_bench.stop() eprintln(term.h_divider('-')) eprintln(fmt_bench.total_message(fmt_message)) @@ -76,3 +79,16 @@ fn test_fmt() { exit(error_failed_tests) } } + +fn fill_bin2v_keep() ? { + img0 := os.join_path('tutorials', 'img', 'hello.png') + img1 := os.join_path('tutorials', 'img', 'time.png') + os.rm(b2v_keep_path) ? + os.exec('v bin2v -w $b2v_keep_path $img0 $img1') ? +} + +fn restore_bin2v_placeholder() ? { + text := '// This is a placeholder file which will be filled with bin2v output before the test. +// HINT: do NOT delete, move or rename this file!\n' + os.write_file(b2v_keep_path, text) ? +} diff --git a/vlib/v/fmt/tests/bin2v_keep.vv b/vlib/v/fmt/tests/bin2v_keep.vv new file mode 100644 index 0000000000..5c6f8618ab --- /dev/null +++ b/vlib/v/fmt/tests/bin2v_keep.vv @@ -0,0 +1,2 @@ +// This is a placeholder file which will be filled with bin2v output before the test. +// HINT: do NOT delete, move or rename this file!