On 7/26/23 19:50, 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 <ebl...@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
> 
> diff --git a/golang/Makefile.am b/golang/Makefile.am
> index fac65248..9201ed8e 100644
> --- a/golang/Makefile.am
> +++ b/golang/Makefile.am
> @@ -98,7 +98,7 @@ TESTS_ENVIRONMENT = \
>       abs_top_srcdir=$(abs_top_srcdir) \
>       $(NULL)
>  LOG_COMPILER = $(top_builddir)/run
> -TESTS = run-tests.sh
> +TESTS = run-tests.sh codestyle-tests.sh
> 
>  endif
> 
> diff --git a/golang/codestyle-tests.sh b/golang/codestyle-tests.sh
> new file mode 100755
> index 00000000..f4928fe5
> --- /dev/null
> +++ b/golang/codestyle-tests.sh
> @@ -0,0 +1,45 @@
> +#!/bin/bash -
> +# nbd client library in userspace
> +# Copyright Red Hat
> +#
> +# This library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License as published by the Free Software Foundation; either
> +# version 2 of the License, or (at your option) any later version.
> +#
> +# This library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with this library; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> +
> +. ../tests/functions.sh
> +
> +set -e
> +set -x
> +
> +# Assume that 'gofmt' lives in the same place as 'go'
> +GOFMT=${GOLANG}fmt
> +
> +requires $GOFMT --help
> +
> +rm -f codestyle-tests.out
> +cleanup_fn rm -f codestyle-tests.out
> +
> +# Lining up generated = in const() in bindings.go is hard; to check
> +# that file, export TEST_GOFMT_ALL=1 while running this test.
> +if test x"$TEST_GOFMT_ALL" = x; then
> +    exclude='-not -name bindings.go'
> +else
> +    exclude=
> +fi
> +
> +$GOFMT -d $(find . -name "*.go" $exclude) > codestyle-tests.out
> +if test -s codestyle-tests.out; then
> +    echo 'FAIL: fix the following style errors' >&2
> +    cat codestyle-tests.out >&2
> +    exit 1
> +fi

Looks good to me.

Reviewed-by: Laszlo Ersek <ler...@redhat.com>

_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs

Reply via email to