Makefile.am (check): Check whether formatting is required

Given that developers should be doing TDD and therefore running this target
frequently, this has the effect of providing immediate feedback when
formatting is needed and outputting a diff.  Developers will then quickly
understand what changes need to be made to avoid future issues (and can run
`cargo fmt` to fix it), at which point they'll rarely ever encounter
formatting errors.

The original purpose was to ensure pipelines fail when the formatter has not
been run.
master
Mike Gerwitz 2019-12-03 13:53:29 -05:00
parent e1076ce388
commit 0acc21f16f
3 changed files with 48 additions and 2 deletions

View File

@ -18,7 +18,7 @@
.DELETE_ON_ERROR:
.PHONY: all
.PHONY: all fix fmt
CARGO_BUILD_FLAGS=@CARGO_BUILD_FLAGS@
@ -31,6 +31,12 @@ html-am:
# note that 'cargo check' is something else; see 'cargo --help'
test: check
check-am:
check-am: check-fmt
@CARGO@ test
check-fmt:
@CARGO@ fmt -- --check
fix: fmt
fmt:
@CARGO@ fmt

View File

@ -47,3 +47,34 @@ $ ./configure CARGO_BUILD_FLAGS=--release && make
$ ./configure && make
$ ./configure CARGO_BUILD_FLAGS=--release && make CARGO_BUILD_FLAGS=
```
## Hacking
This section contains advice for those developing TAMER.
### Running Tests
Developers should be using test-driven development (TDD). `make check` will
run all necessary tests.
### Code Format
Rust provides `rustfmt` that can automatically format code for you. This
project mandates its use and therefore eliminates personal preference in
code style (for better or worse).
Formatting checks are run during `make check` and, on failure, will output
the diff that would be applied if you ran `make fmt` (or `make fix`); this
will run `cargo fmt` for you (and will use the binaries configured via
`configure`).
Since developers should be doing test-driven development (TDD) and therefore
should be running `make check` frequently, the hope is that frequent
feedback on formatting issues will allow developers to quickly adjust their
habits to avoid triggering formatting errors at all.
If you want to automatically fix formatting errors and then run tests:
```sh
$ make fmt check
```

View File

@ -55,6 +55,15 @@ AX_COMPARE_VERSION([$rustc_version], [ge], [$rustc_ver_req],
AC_ARG_VAR([CARGO_BUILD_FLAGS],
[Flags to be passed to `cargo build' when invoked via Make])
# Cargo commands may be available but not necessarily installed for the
# active toolchain. Let's check that.
AC_MSG_CHECKING([whether cargo-fmt is available for active toolchain])
AS_IF([cargo fmt --help &>/dev/null],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)
cargo fmt --help # run again so user can see output
AC_MSG_ERROR([missing cargo-fmt for active toolchain])])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT