Commit Graph

311 Commits

Author SHA1 Message Date
Mads Kiilerich
80eee013e1 tests: unify the last sh tests
This requires a slightly smarter check-code check for sed output filtering.
2012-04-25 01:35:39 +02:00
Mads Kiilerich
f4efda66d8 tests: run most check-code sh checks on continued lines too
Some false errors are degraded to warnings and whitelisted.
2012-04-25 01:35:39 +02:00
Martin Geisler
24e4bf05a3 check-code: catch unnecessary s.strip().split() calls 2012-05-07 10:02:50 +02:00
Mads Kiilerich
b7e85cefa1 tests: avoid tab indent on all kinds of lines of sh commands 2012-04-23 01:56:48 +02:00
Mads Kiilerich
f64bae7ea3 tests: use 'do sleep 0' instead of 'do true', also on first line of command
2cd44a791e66 established that '... do true ...' shouldn't be used, but that was
only enforced on continued lines.
2012-04-23 01:56:48 +02:00
Mads Kiilerich
ca99a3d167 check-code: put grouping around regexps generated from testpats
This removes the pitfall that would make the testpath r'a|b' match 'b' on all
lines in .t tests.
2012-04-23 01:56:48 +02:00
Mads Kiilerich
b1160b7ec5 tests: don't use /dev/urandom for largefiles testing
There is no need to use entropy here just to create some content that only will
be used for hashing and ignored.

This avoids a problem where dd from /dev/urandom on solaris generates too short
output.
2012-04-23 01:56:48 +02:00
Mads Kiilerich
4c1897dde5 tests: fix incorrect markup of continued lines of sh commands 2012-04-23 01:39:26 +02:00
Mads Kiilerich
9f4ca6b4df check-code: 'printf \0' is apparently fine - accept it in check-code
Nobody complained over '\0' in test-eol.t.

The too strict check becomes a problem when this check is applied to more
lines.
2012-04-23 01:39:26 +02:00
Mads Kiilerich
e5bed4bfb4 tests: solaris sh can not negate exit status with '!' 2012-04-23 01:39:26 +02:00
Mads Kiilerich
d63ff4f9a5 tests: ^ must be quoted when used on solaris sh
The check was broken when it was introduced in 8924361c0202.
2012-04-23 01:39:26 +02:00
Matt Mackall
4ca25d50f9 merge with stable 2012-04-14 01:39:35 -05:00
Patrick Mezard
bdf6ede885 mq: replace hasattr() with util.safehasattr(), update check-code.py 2012-04-13 15:07:13 +02:00
Matt Mackall
05bbeed32b check-code: avoid false-positive on ++ 2012-04-12 20:22:18 -05:00
Jim Hague
77587a4c7a tests: avoid test-hup hanging on AIX
test-hup hangs on AIX. Under ksh89 on AIX (the default shell),

echo Hello; while [ ! -s not-there ]; do true; done

produces no output while the loop executes. Replacing 'true' with 'sleep 0'
fixes, as does using a less broken shell. ksh93 is fine.

Update check-code.py to look for this, and make same change in test-serve.t.
In fact test-serve works fine, probably because of additional commands between
echo and the loop, but that's a subtlety not easy to test for.
2012-04-05 12:31:21 +01:00
Matt Mackall
560dd93d34 merge with stable 2012-04-06 15:18:14 -05:00
Matt Mackall
4325ad525f tests: remove sed -i from test-record 2012-04-01 13:59:11 -05:00
Matt Mackall
cc8b3a2b01 pvec: introduce pvecs 2012-03-12 13:37:39 -05:00
Matt Mackall
bd04c54a71 check-code: check for % inside _() 2012-03-08 15:59:44 -06:00
Jim Hague
78a686772b tests: tighten checks for octal escapes in shell printf.
printf on AIX default shell ksh (89) says \1 is an invalid escape. It insists
on at least 2 digits. This causes failures in test-keyword.t and test-status.t.

check-code.py already looks out for \NNN and recommends using Python
for outputting octal values. Extend the check to \NN and \N and fix up
resulting failures.
2012-02-08 16:56:00 +00:00
Mads Kiilerich
e347788597 tests: don't use alias
alias doesn't work in Solaris sh.
2012-01-27 03:00:03 +01:00
Mads Kiilerich
9acd1868fa tests: keep track of all check-code.py warnings 2012-01-11 01:56:05 +01:00
Matt Mackall
e82c2e671f merge with stable 2011-12-05 17:48:40 -06:00
Patrick Mezard
7a8d1bb9db test-svn-subrepo: fix reference output for svn 1.7
I modified check-code.py "$?" detection because I thought my use was legit, we
cannot test exit status of pipelines commands except for the last one without
this. So it now tolerates "[$?" which is unlikely to be added by mistake.

Tested on:
- OSX + svn 1.7.1
- Linux + svn 1.6.12
2011-12-02 16:50:48 +01:00
Mads Kiilerich
1cbfae386c check-code: fix return code initialization
Don't crash when nothing is tested, but return failure when other files than
the last one fails.
2011-11-22 01:37:26 +01:00
Mads Kiilerich
ef0024b865 check-code: add --nolineno option for hiding line numbers
This makes the output more stable when it is used as a whitelist.
2011-11-11 01:25:47 +01:00
Matt Mackall
a5d3d42e92 tests: use md5sum.py instead of sha1sum, add check 2011-10-31 14:22:11 -05:00
Matt Mackall
8971e5af3c check-code: fix issues with finding patterns in unified tests, fix tests
- old-style patterns without ^ were getting improperly anchored
- finditer was matching against beginning of line poorly
- \s was matching newlines
- [^x] was matching newlines

so we:

- remove earlier hacks for multiline matching
- fix unified test anchoring by adding .*
- replace \s with [ \t]
- replace [^x] with [^\nx]
- force all matches into multiline mode so ^ anchors work

This uncovers a number of test issues that are then repaired.
2011-10-27 17:22:04 -05:00
Matt Mackall
4b52621903 tests: fix check-code detection of anchored expressions, fix echo -n usage 2011-10-26 12:56:27 -05:00
Matt Mackall
b7430f065a check-code: catch BaseException and os.path.relpath 2011-10-21 16:52:23 -05:00
Matt Mackall
b22c536335 check-code: report suspicious string joins
This detects patterns of the form:

ui.write("this is missing"
         "a space at the join\n")
2011-10-17 17:27:33 -05:00
Matt Mackall
e1cab56645 merge with crew 2011-10-16 22:15:43 -05:00
Matt Mackall
db1431fe95 check-code: support multiline matches like try/except/finally
- match one pattern at a time against entire file
- find line containing match
- sort matches by line number
2011-10-16 20:26:20 -05:00
Mads Kiilerich
4578a9a76b tests: don't use 'test -e'
On Solaris 10:

  $ test -e f
  test: argument expected
2011-10-17 00:11:56 +02:00
Matt Mackall
d0885370c9 check-code: enable camelcase check, fix up problems 2011-11-09 16:36:54 -06:00
Augie Fackler
3a3e79d5b5 check-code: disallow use of hasattr()
The hasattr() builtin from Python < 3.2 [1] has slightly surprising
behavior: it catches all exceptions, even KeyboardInterrupt. This
causes it to have several surprising side effects, such as hiding
warnings that occur during attribute load and causing mysterious
failure modes when ^Cing an application. In later versions of Python
2.x [0], exception classes which do not inherit from Exception (such
as SystemExit and KeyboardInterrupt) are not caught, but other types
of exceptions may still silently cause returning False instead of
getting a reasonable exception.

[0] http://bugs.python.org/issue2196
[1] http://docs.python.org/dev/whatsnew/3.2.html
2011-07-25 14:59:31 -05:00
Jim Hague
f6f49b778c treediscovery: rename stop() in tests to fix failures on AIX.
It seems ksh, the default shell on AIX, does not permit the creation of a
function called stop(). test-treediscovery.t and test-treediscovery-legacy.t
both fail on AIX with error 'syntax error at line 25 : `(' unexpected'.

Fix by renaming stop() in the scripts to tstop(). For completeness
rename start() to tstart() to match. Both tests then pass on AIX.

Add check for the use of stop() in a shell script to check-code.
2011-07-05 11:53:32 +01:00
Thomas Arendsen Hein
4575d54a81 check-code: fix class style checking (with tests)
- old-style classes were only checked for one-letter class names
- add check for new-style classes with empty parent class, because
  this is not available in Python 2.4
2011-06-29 13:45:51 +02:00
Matt Mackall
f65681314b check-code: don't mark debug messages for translation 2011-06-21 15:21:57 -05:00
Matt Mackall
1b52b02896 check-code: catch misspellings of descendant
This word is fairly common in Mercurial, and easy to misspell.
2011-06-07 17:02:54 -05:00
Martin Geisler
af8a35e078 check-code: flag 0/1 used as constant Boolean expression 2011-06-01 12:38:46 +02:00
Sune Foldager
58e1e8aaa9 check-code: add /= to operator list 2011-05-12 18:19:28 +02:00
Matt Mackall
81206f7383 check-code: complain about set.isdisjoint 2011-05-08 11:39:24 -05:00
Mads Kiilerich
938d75f22d check-code: fix checking for sh style in .t tests
Restore checks after they were disabled by a1f828662ac8.
2011-05-06 00:34:10 +02:00
Dan Villiom Podlaski Christiansen
c1ff9b1ec7 check-code: disallow calling opener(...).read() and opener(..).write() 2011-05-02 10:11:24 +02:00
timeless
849f249718 check-code: check for repo in revlog and ui in util 2011-05-01 16:11:42 +02:00
timeless
153cb7a67b check-code: allow for checking multiple pattern sets per file 2011-05-01 16:10:51 +02:00
timeless
f74ce7db63 check-code: adding debug flag 2011-05-01 15:55:00 +02:00
Idan Kamara
169899ab9c check-code: separate warnings to avoid repetitive str.startswith 2011-04-25 13:03:26 +03:00
Idan Kamara
83e05de083 check-code: warn about naked except clauses 2011-04-23 00:52:21 +03:00
Dan Villiom Podlaski Christiansen
ecb9e72af1 osutil: replace #import with #include, and add a check for it 2011-03-23 23:05:32 +01:00
Matt Mackall
b156bda724 osutil: fix up check-code issues 2011-03-23 09:41:58 -05:00
Martin Geisler
e8a21642ee check-code: catch "echo > $HGRCPATH" too
Make error message consistent with the other error messages.
2011-03-02 14:52:31 +01:00
Martin Geisler
11500eaa6f check-code: better check for overwriting $HGRCPATH
Suggested by Mads Kiilerich on IRC.
2011-03-02 14:22:50 +01:00
Martin Geisler
83c27fb95f tests: don't overwrite HGRCPATH
Overwriting instead of appending to the file removes the [defaults]
section put into the file by run-tests.py.

It also defeats the --inotify option to run-tests.py.

(Nothing was broken yet, but the lack of -d "0 0" cause changeset
hashes to change unexpectedly in a test case I was editing.)
2011-03-01 17:01:17 +01:00
Dan Villiom Podlaski Christiansen
ec590d5cd4 explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
2010-12-24 15:23:01 +01:00
Martin Geisler
77e1343f88 check-code: do not complain about 'ls x | foo -v'
Such a line was introduced in test-subrepo-git.t in 686775e575f3,
which made check-code confused.
2011-01-26 12:35:02 +01:00
Matt Mackall
940fa28a3f check-code: catch os.path.relpath 2010-12-16 14:50:37 -06:00
Matt Mackall
cdcb8c0f47 check-code: catch "except as" 2010-12-16 14:50:36 -06:00
Thomas Arendsen Hein
3669dce8b1 check-code: single check for Python keywords used as a function
This replaces the specific checks for del/and/or/not/except and additionally
checks other Python keywords.
2010-12-03 12:04:31 +01:00
Thomas Arendsen Hein
31218f1044 check-code: check for gratuitous whitespace after Python keywords 2010-12-03 11:23:38 +01:00
Martin Geisler
6a3d9310ab code style: prefer 'is' and 'is not' tests with singletons 2010-11-22 18:15:58 +01:00
Adrian Buehlmann
5e2e71ea82 check-code: catch Python 'is' comparing number or string literals
The Python 'is' operator compares object identity, so it should
definitely not be applied to string or number literals, which Python
implementations are free to represent with a temporary object.

This should catch the following kinds of bogus expressions (examples):

  x is 'foo'     x is not 'foo'
  x is "bar"     x is not "bar"
  x is 42        x is not 42
  x is -36       x is not -36

As originally proposed by Martin Geisler, amended with catching
negative numbers.
2010-11-21 11:52:27 +01:00
Martin Geisler
ca016e40cb check-code: catch 'ls filename --option' case as per 8745def6e53b 2010-11-17 09:37:57 +01:00
Martin Geisler
9d82b9ed1f check-code: using and/or/not as a function is bad style 2010-11-11 00:08:09 +01:00
Matt Mackall
0f064b0796 check-code: warning and fixes for whitespace in unified tests 2010-10-20 14:57:36 -05:00
Martin Geisler
77ce66fb6a check-code: find trailing whitespace 2010-10-20 10:13:04 +02:00
Adrian Buehlmann
758fc721d8 check-code: add 'no tab indent' check for unified tests
and fix the offending tests accordingly
2010-10-16 18:09:01 +02:00
Dan Villiom Podlaski Christiansen
8e99053714 tests: compatibility fix.
'touch -d *' doesn't work on Mac OS X. In order to prevent this from
occuring again, a check for the case is added to 'check-code.py'.
2010-09-21 18:36:23 +02:00
Matt Mackall
5d9fc42983 tests: drop a bunch of sed calls from unified tests 2010-09-21 16:44:13 -05:00
Matt Mackall
0c59a109d6 check-code: add some basic support for unified tests 2010-09-21 12:41:24 -05:00
Martin Geisler
ec0bf03276 Merge with stable 2010-08-15 18:13:46 +02:00
Martin Geisler
888421d8ca check-code: catch "echo -n" in tests 2010-08-15 17:48:05 +02:00
Alecs King
00c728120d check-code: add exit status
so that we can use it in a shell command combination and/or in hg hooks.
2010-08-12 16:42:41 +08:00
Renato Cunha
f65cf06e03 check-code: added a check for calls to the builtin cmp function 2010-08-07 16:13:53 -03:00
Matt Mackall
661034417e check-code: add warning on lines over 80 characters 2010-07-25 17:10:32 -05:00
Martin Geisler
71971a8928 check-code: warn about untranslated ui.warn calls 2010-07-16 14:40:57 +02:00
Matt Mackall
6c780d7b4f check-code: add --blame switch 2010-07-16 13:26:39 -05:00
Martin Geisler
12085cad2b check-code: catch dict.has_key 2010-07-16 14:48:52 +02:00
Martin Geisler
f985c9d777 Merge with stable 2010-07-16 14:45:52 +02:00
Renato Cunha
29ee0d7c07 check-code: added check for reduce usage 2010-07-14 23:15:03 -03:00
Renato Cunha
f678753e0c check-code: check for tuple parameter unpacking (missing in py3k) 2010-07-14 23:15:00 -03:00
Martin Geisler
59385f10e8 check-code: add test for callable 2010-07-09 14:01:55 +02:00
Martin Geisler
5bd48f2f1e check-code: reformat long lines 2010-06-15 10:01:55 +02:00
Martin Geisler
28297c8184 check-code: catch format(), introduced in Python 2.6 2010-06-15 09:55:59 +02:00
Martin Geisler
5d9db0b74d check-code: fix check for any/all function
The old check would only detect any/all at the beginning of a line.
The regexp was probably just modeled after the preceding regexp which
(correctly) finds the 'with' keyword at the beginning of a line.

We now complain about 'any(' and 'all(' anywhere in a line, unless it
is preceded by 'def'. This allows us to define our own compatibility
wrapper in util and use 'util.any(' in the code.
2010-06-15 09:51:52 +02:00
Yuya Nishihara
ffeee8dfd0 check-code: add check for 'source' 2010-05-21 22:53:57 +09:00
Nicolas Dumazet
7f1a963829 pylint, pyflakes: remove unused or duplicate imports 2010-04-14 17:58:10 +09:00
Matt Mackall
062bdb8d0b check-code: add a warnings level
- demote "unwrapped ui message"
2010-04-12 17:41:32 -07:00
Matt Mackall
0726edad79 Merge with stable 2010-04-01 17:51:59 -05:00
Mads Kiilerich
6f24bc8f03 check-code.py: Check for bare ^
Solaris sh interprets ^ as some kind of piping symbol.
2010-03-31 11:07:46 +02:00
Benoit Boissinot
2fa74b1aa8 check-code: more tests and more robust python filtering 2010-03-18 16:32:03 +01:00
Matt Mackall
9ead8ddeec check-code: fix check-code complaint 2010-03-17 15:36:48 -05:00
Benoit Boissinot
4e213c5898 check-code: improve quote detection regexp, add tests 2010-03-17 14:15:33 +01:00
Pierre-Yves David
ada28ea37e check-code: add a return value to checkfile function
The checkfile function returns True if the file is correct, False
otherwise.
2010-03-17 10:51:26 +01:00
Pierre-Yves David
d5796f6daf code-code: Add a logfunc argument to checkfile
This helps external tool customisation. The logfunc argument must be a
function called to report errors. A new logger class is also added to
keep the old behaviour by default.
2010-03-16 19:53:00 +01:00
Pierre-Yves David
ffbf49397a check-code: Add a `maxerr argument to the checkfile` function
check-code.py used to halt after 15 errors. This changeset adds a new
argument to the checkfile function to control this limit.
2010-03-16 19:52:58 +01:00
Pierre-Yves David
16e40846e1 check-code: Add a `checkfile` function
The part of the code actually checking each file is moved in the
``checkfile`` function to allow external reuses.
2010-03-16 19:52:57 +01:00
Pierre-Yves David
64bcf4a5c3 check-code: Only call check-code if __name__ = "__main__".
This changeset moves the code that actually executes something to the
"if __name__ = '__main__'" section to allow the file to be imported as
a module.
2010-03-16 19:52:56 +01:00
Benoit Boissinot
57712fa835 check-code: remove simple quotes first 2010-03-16 16:39:17 +01:00
Matt Mackall
36aa3dd390 check-code: add check for any/all 2010-03-12 16:16:47 -06:00
Mads Kiilerich
badb17240e test-merge-default and check-code.py: No "export x=x" in sh 2010-03-08 03:07:35 +01:00
Matt Mackall
0bc7a87925 check-code: two more rules
- no plain Exceptions
- complain about unmarked ui messages
2010-02-13 23:20:17 -06:00
Matt Mackall
a17b73e2eb check-code: import some pylint checks 2010-02-09 13:53:24 -06:00
Martin Geisler
4817fcfe96 check-code.py: make help strings consistent 2010-02-07 10:58:51 +01:00
Mads Kiilerich
289637cadf check-code.py: escape backslash 2010-02-07 01:52:10 +01:00
Matt Mackall
1a71a75d3d check-code: del isn't a function 2010-01-28 22:44:54 -06:00
Matt Mackall
f7b37826db check-code: fix copyright date 2010-01-28 22:44:45 -06:00
Matt Mackall
6c94f28bab check-code: add some ignore hints 2010-01-28 22:44:18 -06:00
Matt Mackall
3f5075a48f check-code: check thyself 2010-01-25 01:23:34 -06:00
Matt Mackall
9b0512d1f6 Introduce check-code.py
check-code is a simple regex-based framework for checking our code and
tests for common style and portability errors. Currently, it knows a
fair amount about our Python and C style, and a little about common
shell script portability problems.
2010-01-25 00:05:22 -06:00