Commit 42433e27 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: add format verification test

TestFormats finds potential (Printf, etc.) format strings.
If they are used in a call, the format verbs are verified
based on the matching argument type against a precomputed
table of valid formats (formatMapping, below). The table
can be used to automatically rewrite format strings with
the -u flag.

Run as: go test -run Formats [-u]

A formatMapping based on the existing formats is printed
when the test is run in verbose mode (-v flag). The table
needs to be updated whenever a new (type, format) combination
is found and the format verb is not 'v' (as in "%v").

Known bugs:
- indexed format strings ("%[2]s", etc.) are not suported
  (the test will fail)
- format strings that are not simple string literals cannot
  be updated automatically
  (the test will fail with respective warnings)

Change-Id: I1ca5bb6421d57ac78a00f1a80b9547a72837adc9
Reviewed-on: https://go-review.googlesource.com/28419
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 0cff219c
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment