Commit Graph

37 Commits

Author SHA1 Message Date
Hannes Steffenhagen b8d64ca6cf Escape braces in regression test regexes 2018-09-17 11:39:49 +01:00
Michael Tautschnig 3321735dc7 Move implementation of failed-tests-printer.pl into test.pl
Added a new option "-p" to test.pl to request printing failure logs instead of
doing so via an external script. This simplifies various Makefiles and enables
use in cmake builds.
2017-11-02 12:18:15 +00:00
Pascal Kesseli 427194c626 Allow anonymous namespaces
Only give warnings for namespaces with actual names, in accordance with
ad41375353.
This enables the use of anonymous namespaces without warnings.

Fixes: #932
2017-07-12 15:36:32 +02:00
martin 975b5a3550 Get the linter to check for assertions and give a deprecated warning. 2017-06-13 16:12:12 +01:00
Michael Tautschnig 05192db2b8 Remove blank lines from regression test specs
Matching blank lines fails on Windows/AppVeyor. Also, there should not be any
requirement for our output to contain blank lines.
2017-04-06 14:08:21 +01:00
Daniel Poetzl c16d75b5f6 merge fixes 2017-04-03 16:57:59 +01:00
thk123 9b052c200f Modified tests to pass without using grep
Now directly test individual lines with perls regex matching rather than
calling out to grep. Some changes were required:

- escape (,  ) if we want to match them
- unescape (, ) if we want to use them as regex bracket groups
- escape +, $ if we want to use them as actual characters
- unescape + to use as a regex +
2017-02-14 17:29:15 +00:00
Peter Schrammel 272ff50339 Merge pull request #415 from thk123/feature/lint-check-multi-line-function-call
Lint checks nested function calls broken over multiple lines
2017-01-11 18:30:14 +00:00
Peter Schrammel 60ec17195c Merge pull request #417 from thk123/feature/lint-throw-check
Adding check for throw formatting
2017-01-11 16:02:17 +00:00
thk123 2ce995d73e Adding check for throw formatting
Throw statements should not have the bracket and the first character of
the error message should be lower case. Added a check to the linter to
verify this. Added regression tests to check this.
2017-01-10 11:49:50 +00:00
thk123 648116ce9e Require a word character immediately before space
Modified the inital regex to require a word character immediately
(except spaces) before the bracket. This ensures we are not just a order
of operations bracket but in fact a function call. Added a regression
test that checks the case that this is required for
2017-01-10 10:44:57 +00:00
thk123 3c48404dc4 Deal with multi-line function calls with nothing on the first line
Previously the regex was checking for the first parameter being on the
first line, but this isn't required for the function call to be wrong.

Added the check for each of the lines if there is no nested function
call.
2017-01-10 10:44:57 +00:00
thk123 eb4597d04a Replaced regex for matching multi-line function calls
Instead use a more complex system that finds the matching closing
bracket and checks all the lines in between to check one parameter only
on each line.

It handles nested function calls by skipping over their whole parameter
list (since we don't require nested functions be separated onto
individual lines just because the outer call is. Instead these get
checked when we get to this function call separately.
2017-01-10 10:44:57 +00:00
thk123 6b4a54111f Corrected regex for member operator functions
The regex for finding operator functions didn't work if the function
belonged to a class as it wasn't matching the :: correctly. Extended the
regression test to cover this
2017-01-09 12:22:10 +00:00
thk123 548195f084 Added check for position of &/* for types
We attempt to validate that the */& for pointer/reference types are
attached to the variable rather than the type. For example should be int
*x; rather than int* x;

We attempt to check this by looking for things that are at the very
start of the line and not in brackets to avoid picking up cases where
the * or & is used as a binary operator.

We can still miss cases inside a function declaration.

Updated the coding standard to also explicityl mention this preference
2017-01-06 11:11:28 +00:00
thk123 47106fb4df Removed check for <<
Previously we were only allowing << around digits, but this produces
false positives as there are plenty of uses of the shift operator that
use variables. At this stage, I believe it is better to just remove this
check.
2017-01-06 11:11:28 +00:00
thk123 6193f95bb5 Correctly deal with non-t terminated type names
The old way of checking for classes ended in t was confusing as used a
negative match. As such it was difficult to check that it ended in a t
but count & or * as the terminator of the type. We start the search at
a bounardy to deal with classes inside brackets but not when class is
part of a larger word.

Instead we now just try and match the name since this will greedly
consume the whole name and nothing more.

The template check also uses boundary rather than the start line anchor
since sometimes template statements can be indendented. However in
these cases we still don't want to check the type ends in a t.

This stops us incorrectly reporting types not ending in t as we don't
erronousely treat other chartacers as the final charatcer of the type.

Added some extra tests to deal with the variety of ways that the class
keyword can appear in the codebase.
2017-01-06 11:08:49 +00:00
thk123 d590db4127 Don't think function declarations should have function header comments
Previously we would always checkf for function header comments if we
found a function. Now if we find a ; before a { then we assume it is a
function declaration, otherwise we assume it is a function
implementation and therefore should have the function header comment.

This does mean that functions with bodies in header files are going to
require a function header comment.
2016-12-23 15:19:22 +01:00
thk123 7374c77b00 Handle operator functions when looking for function comment headers
Since operator functions can have non-word characters as part of their
name (specifically, can have an opening bracket) we deal with these
seperately in the explicit case where the functions name is operator.

Since the function name can now contain non-word characters (e.g. an
opening bracket) we must escape it before using it in the regex.
2016-12-23 15:19:22 +01:00
thk123 7638907c04 Don't include * or & in function name
When checking for function comments we don't want to include the * or &
in the name. Instead we allow after the space of the return type an
optional * or & before accepting the function name.
2016-12-23 15:19:22 +01:00
thk123 fa53b71ba5 Removing tests for indentation 2016-12-23 15:19:21 +01:00
thk123 e24f045549 Lint script checks for the function comment header
Each function with a body should have a function comment header directly
above it. Modified the lint script to check for its presence and
validate that it meeds certain requirements.

Updated existing tests to include the funciton header so they don't
generate warnings for its absence. Also updated the test description as
the line numbers of the deliberate errors have changed.

Added new tests for the different ways the function header can be wrong
2016-12-23 15:19:20 +01:00
thk123 60cb406822 Don't warn about spacing around << as difficult to know if we should
Since we can't in general (without type analysis I think) tell the
difference between a bit shift operator << and a stream manipulator <<
we don't warn about it. In some instances we can tell if it is a stream
manipulator so we check for spaces there. I've added a known bug
operator-spacing3 that would be the perfect report of errors.
2016-12-23 15:19:20 +01:00
thk123 76193a2a23 Use elided lines when checking bracket indentation
This fixes previous bug with brackets in comments (in a cleaner and more
consistent way) as well as addressing the bug to do with brackets in
comments. Weirdly, it was claiming to be using lines with strings
removed, but printing the line clearly shows that
`lines_without_raw_strings` still contains at least some strings.
2016-12-23 15:19:20 +01:00
thk123 4f803c604e Added test for spacing error that wasn't being triggered 2016-12-23 15:19:20 +01:00
thk123 13b7639d55 Don't demand removing space if operator starts a line
To deal with splitting lines containing operators up, if the operator
starts the new line, we shouldn't require white space before it be
removed. Instead, we only check for white space on the left side of
operators if we've encountered some non-white-space characters that
line.

There are about 500 cases in the code where the operator starts the new
line and 250 where it ends the previous line so not practical to require
one over the other.
2016-12-23 15:19:20 +01:00
thk123 e6a50931e2 Disabled test for redundant override final specifier 2016-12-23 15:19:19 +01:00
thk123 df109bc5ae Further developments on if lint checking
Removed most of the old lint if checking as they want braces on the same
line so was mostly the opposite of what we wanted (which is in fact much
simpler).

Removed the old check for if(...) { as this is already picked up by the
braces at the end of line checks.

Added additional tests for different ways the if statement can be wrong
or right.
2016-12-23 15:19:19 +01:00
thk123 773cdb7aca Else statement with brace on same line
Tidied up the if/else if/else errors (needs more tests)
2016-12-23 15:19:19 +01:00
thk123 cca2e2da88 Handle template argument lists that run on to multiple lines
When checking for spacing around operators, we need to be careful with
<, > since are also brackets around template types. In these cases, a
space after the > but not before is acceptable. The approach I've taken
is to find the matching opening angled bracket and inspect the contents
between them.
2016-12-23 15:19:18 +01:00
thk123 19f29a3fe0 Check for while is on the same line as closing brace in do-while
We check for lines that look like `} while` and see if there is a
matching do statement. If there is, we advise the while be put on a
separate line.
2016-12-23 15:19:18 +01:00
thk123 19876f5df7 Linter doesn't wrong warn about empty do while statement
The linter was picking up that while(...); looks like an empty while
statement. However, unlike what the linter is expecting, we put while on
a separate line to the closing brace for a do...while statement. Instead
the linter now searches previous lines for a matching do statement. If
it finds a while before the do then it obviously isn't related to this
while.
2016-12-23 15:19:18 +01:00
thk123 c50e81df0c Adding missed make file
The make file runs the linter script found in the scripts/ folder on the
CPP file found in the test folder.
2016-12-23 15:19:18 +01:00
thk123 d1af0e1cc2 Added regression test for the prefix iterator in for loop
This has been fixed, but previously it would complain about whitespace
before the +
2016-12-23 15:19:18 +01:00
thk123 08bdc6e524 Don't trigger the multi-line parameter warning in comments
If the line being tested is a single line comment, we don't bother
checking whether the previous line is an incomplete function
declaration).
2016-12-23 15:19:17 +01:00
thk123 9078c92f07 Corrected lint error on classes decl that have space after identifier
In class declarations, it was previously warnining that the class
identifier didn't end with a t because there was a space between the end
of the identifier and the : (for inheritance). Now provides a warning
that this space shouldn't be present and doesn't warn about the
identifier.
2016-12-23 15:19:17 +01:00
thk123 50eac162ad Fixed linter bug where was thinking catch was a C style cast
The linter script has exceptions to exclude incorrect detection of C
style casts. Added the keyword catch to this list. Added a regression
test to verify this.
2016-12-23 15:19:17 +01:00