From 9b2cbdacc65276cebf37eaf79aa148776ac2773f Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 16 Jul 2020 19:46:03 +0200 Subject: [PATCH] vfmt: verify --- .github/workflows/ci.yml | 3 +++ cmd/tools/vfmt.v | 13 +++++++++++++ vlib/v/checker/checker.v | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42b919c5e0..4df7371393 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,9 @@ jobs: ./v vet vlib/v/gen/cgen.v ./v vet vlib/v/checker ./v vet vlib/sqlite + - name: v fmt + run: | + ./v fmt -verify vlib/v/checker/checker.v # - name: Test v binaries # run: ./v -silent build-vbinaries diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index af6b95c289..9b8c3d4e06 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -23,6 +23,7 @@ struct FormatOptions { is_worker bool is_debug bool is_noerror bool + is_verify bool // exit(1) if the file is not vfmt'ed } const ( @@ -51,6 +52,7 @@ fn main() { is_worker: '-worker' in args is_debug: '-debug' in args is_noerror: '-noerror' in args + is_verify: '-verify' in args } if foptions.is_verbose { eprintln('vfmt foptions: $foptions') @@ -185,6 +187,17 @@ fn (foptions &FormatOptions) post_process_file(file, formatted_file_path string) println(util.color_compare_files(diff_cmd, file, formatted_file_path)) return } + if foptions.is_verify { + diff_cmd := util.find_working_diff_command() or { + eprintln('No working "diff" CLI command found.') + return + } + x := util.color_compare_files(diff_cmd, file, formatted_file_path) + if x.len != 0 { + exit(1) + } + return + } fc := os.read_file(file) or { eprintln('File $file could not be read') return diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b99feab5d0..709601287e 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -19,7 +19,7 @@ const ( pub struct Checker { pub mut: - table &table.Table +table &table.Table file ast.File nr_errors int nr_warnings int