diff options
author | Mike Gerwitz <mike.gerwitz@ryansg.com> | 2019-12-03 13:53:29 -0500 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@ryansg.com> | 2020-02-24 14:56:28 -0500 |
commit | 0acc21f16f098b2784b1382b82816889d694f91a (patch) | |
tree | 3910ff74a85e1b70bbcf83818d233f8caecf7214 | |
parent | e1076ce3880f5533cad311543f551a50be58c53e (diff) | |
download | tame-0acc21f16f098b2784b1382b82816889d694f91a.tar.gz tame-0acc21f16f098b2784b1382b82816889d694f91a.tar.bz2 tame-0acc21f16f098b2784b1382b82816889d694f91a.zip |
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.
-rw-r--r-- | tamer/Makefile.am | 10 | ||||
-rw-r--r-- | tamer/README.md | 31 | ||||
-rw-r--r-- | tamer/configure.ac | 9 |
3 files changed, 48 insertions, 2 deletions
diff --git a/tamer/Makefile.am b/tamer/Makefile.am index 2cc502c..3248bc6 100644 --- a/tamer/Makefile.am +++ b/tamer/Makefile.am @@ -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 diff --git a/tamer/README.md b/tamer/README.md index 6d44f02..2d14ef4 100644 --- a/tamer/README.md +++ b/tamer/README.md @@ -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 +``` diff --git a/tamer/configure.ac b/tamer/configure.ac index 9ed3526..350b77b 100644 --- a/tamer/configure.ac +++ b/tamer/configure.ac @@ -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 |