[Libguestfs] [libnbd PATCH 7/7] golang: Enforce coding style during 'make check'

Daniel P. Berrangé berrange at redhat.com
Fri Jul 28 12:34:57 UTC 2023


On Wed, Jul 26, 2023 at 12:50:05PM -0500, Eric Blake wrote:
> Now that I've finished tweaking the generator to output consistent Go
> style, add a test that runs gofmt to flag places where we introduce
> style regressions.  As lining up columns in generated const() blocks
> is trickier, for now I am making the test skip that by default (export
> TEST_GOFMT_ALL=1 to see the difference).
> 
> A later patch may figure out how to do it in OCaml (two passes: one to
> collect the maximum length of a name, the second to output columnar
> data), or to include gofmt as part of the generation process (when
> available), where a 'make dist' tarball will compile no matter what,
> but only have correct formatting if the developer building the tarball
> had gofmt installed.
> 
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
>  golang/Makefile.am        |  2 +-
>  golang/codestyle-tests.sh | 45 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 46 insertions(+), 1 deletion(-)
>  create mode 100755 golang/codestyle-tests.sh

> +
> +$GOFMT -d $(find . -name "*.go" $exclude) > codestyle-tests.out

By default it only reports the first 10 errors. Adding -e makes it
report all of them

> +if test -s codestyle-tests.out; then
> +    echo 'FAIL: fix the following style errors' >&2
> +    cat codestyle-tests.out >&2
> +    exit 1
> +fi

The full output could potentially be quite large. So consider
just running 'diffstat codestyle-tests.out' and simply telling
people to open codestyle-tests.out to see full details.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


More information about the Libguestfs mailing list