mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
check-code: enfore checking before using common foreign extensions
Summary: It's a common mistake that our tests require foreign extensions (namely evolve and remotenames) without checking them first. This diff adds checks to catch these mistakes, adds missing checks, and unifies our checking logic using `require-ext.sh`, which is aware of `hgext3rd` and prints skip message. This affects `arc lint` so hopefully our new testing code would be free of this kind of mistakes. Test Plan: `arc lint` would catch errors Reviewers: #mercurial, ttung, rmcelroy Reviewed By: rmcelroy Subscribers: rmcelroy, mjpieters Differential Revision: https://phabricator.intern.facebook.com/D3550977 Signature: t1:3550977:1468455857:e849dfd9e3cbc446cc6e6c662050ee88a3366e6c
This commit is contained in:
parent
c04d72741a
commit
3884602d28
60
tests/check-foreignext.py
Executable file
60
tests/check-foreignext.py
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
"""
|
||||
Check if a test is using foreign extensions without proper checks
|
||||
"""
|
||||
|
||||
# foreign extensions
|
||||
exts = ['directaccess', 'evolve', 'inhibit', 'remotenames']
|
||||
extre = re.compile(r'(%s)' % '|'.join(exts))
|
||||
|
||||
checkres = [
|
||||
(re.compile(r'^\s*>\s*%s\s*=\s*$' % extre.pattern),
|
||||
'use "$ . $TESTDIR/require-ext.sh %(name)s" to skip the test'
|
||||
' if %(name)s is not available'),
|
||||
(re.compile(r'^\s*\$.*--config[ =\']*extensions.%s=' % extre.pattern),
|
||||
'use "$ . $TESTDIR/require-ext.sh %(name)s" to skip the test'
|
||||
' if %(name)s is not available'),
|
||||
]
|
||||
|
||||
# $ . $TESTDIR/require-ext.sh foreignext
|
||||
requirere = re.compile(r'require-ext\.sh ((?:%s|\s+)+)' % extre.pattern)
|
||||
|
||||
def checkfile(path):
|
||||
errors = []
|
||||
with open(path) as f:
|
||||
required = set()
|
||||
for i, line in enumerate(f):
|
||||
msg = None
|
||||
m = requirere.search(line)
|
||||
if m:
|
||||
required.update(m.group(1).split())
|
||||
for regex, msg in checkres:
|
||||
m = regex.search(line)
|
||||
if not m:
|
||||
continue
|
||||
name = m.group(1)
|
||||
if name in required:
|
||||
continue
|
||||
# line[:-1] is to remove the last "\n"
|
||||
errors.append((path, i + 1, line[:-1], msg % {'name': name}))
|
||||
# only one error per extension per file
|
||||
required.add(name)
|
||||
return errors
|
||||
|
||||
def checkfiles(paths):
|
||||
errors = []
|
||||
for path in sys.argv[1:]:
|
||||
errors += checkfile(path)
|
||||
return sorted(set(errors))
|
||||
|
||||
def printerrors(errors):
|
||||
# same format with check-code.py
|
||||
for fname, lineno, line, msg in errors:
|
||||
print('%s:%d:\n > %s\n %s' % (fname, lineno, line, msg))
|
||||
|
||||
printerrors(checkfiles(sys.argv[1:]))
|
@ -48,3 +48,7 @@ New errors are not allowed. Warnings are strongly discouraged.
|
||||
Skipping cfastmanifest/tree_path.h it has no-che?k-code (glob)
|
||||
Skipping cfastmanifest/tree_test.c it has no-che?k-code (glob)
|
||||
Skipping hgext3rd/statprof.py it has no-che?k-code (glob)
|
||||
|
||||
Check foreign extensions are only used after checks
|
||||
|
||||
$ hg locate 'test-*.t' | xargs $TESTDIR/check-foreignext.py
|
||||
|
@ -1,8 +1,9 @@
|
||||
$ . $TESTDIR/require-ext.sh remotenames
|
||||
|
||||
Setup
|
||||
|
||||
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
|
||||
$ export PYTHONPATH
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
|
||||
$ mkcommit() {
|
||||
> echo "$1" > "$1"
|
||||
|
@ -298,7 +298,7 @@ Test that --addremove/-A works
|
||||
|
||||
Test that the extension disables itself when evolution is enabled
|
||||
|
||||
$ $PYTHON -c 'import evolve' 2> /dev/null || $PYTHON -c 'import hgext.evolve' 2> /dev/null || exit 80
|
||||
$ . $TESTDIR/require-ext.sh evolve
|
||||
$ cat >> .hg/hgrc <<EOF
|
||||
> [extensions]
|
||||
> evolve=
|
||||
@ -476,7 +476,7 @@ Test hg amend works with a logfile
|
||||
$ rm alogfile
|
||||
|
||||
Test fbamend with inhibit
|
||||
$ $PYTHON -c 'import inhibit' 2> /dev/null || $PYTHON -c 'import hgext.inhibit' 2> /dev/null || exit 80
|
||||
$ . $TESTDIR/require-ext.sh inhibit
|
||||
$ cat >> .hg/hgrc <<EOF
|
||||
> [extensions]
|
||||
> inhibit=
|
||||
@ -593,6 +593,7 @@ Make sure that unamend does not work without inhibit
|
||||
[255]
|
||||
|
||||
Make sure that unamend works as expected with inhibit
|
||||
$ . $TESTDIR/require-ext.sh directaccess
|
||||
$ cat >> .hg/hgrc <<EOF
|
||||
> [extensions]
|
||||
> inhibit=
|
||||
|
@ -258,6 +258,7 @@ test 'execr' executing in the current directory
|
||||
$ cd ..
|
||||
|
||||
Test that we can recover exec with evolve on
|
||||
$ . $TESTDIR/require-ext.sh evolve
|
||||
$ cat >> .hg/hgrc <<EOF
|
||||
> [extensions]
|
||||
> evolve=
|
||||
|
@ -1,3 +1,4 @@
|
||||
$ . $TESTDIR/require-ext.sh directaccess evolve inhibit
|
||||
$ . "$TESTDIR/histedit-helpers.sh"
|
||||
|
||||
Setup
|
||||
|
@ -1,3 +1,5 @@
|
||||
$ . $TESTDIR/require-ext.sh directaccess evolve inhibit
|
||||
|
||||
Test of warning for evolve users when inhibit is enabled
|
||||
$ cat >> $HGRCPATH <<EOF
|
||||
> [ui]
|
||||
|
@ -1,10 +1,11 @@
|
||||
$ . $TESTDIR/require-ext.sh directaccess evolve inhibit remotenames
|
||||
|
||||
Setup
|
||||
|
||||
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
|
||||
$ export PYTHONPATH
|
||||
|
||||
Test that hg pull creates obsolescence markers for landed diffs
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
$ cat >> $HGRCPATH <<EOF
|
||||
> [ui]
|
||||
> username = nobody <no.reply@fb.com>
|
||||
|
@ -1,10 +1,11 @@
|
||||
$ . $TESTDIR/require-ext.sh directaccess evolve inhibit remotenames
|
||||
|
||||
Setup
|
||||
|
||||
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
|
||||
$ export PYTHONPATH
|
||||
|
||||
Test that hg pull creates obsolescence markers for landed diffs
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
$ cat >> $HGRCPATH <<EOF
|
||||
> [ui]
|
||||
> username = nobody <no.reply@fb.com>
|
||||
|
@ -1,9 +1,10 @@
|
||||
$ . $TESTDIR/require-ext.sh remotenames
|
||||
|
||||
Setup
|
||||
|
||||
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
|
||||
$ export PYTHONPATH
|
||||
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
$ cat >> $HGRCPATH << EOF
|
||||
> [ui]
|
||||
> ssh = python "$RUNTESTDIR/dummyssh"
|
||||
|
@ -1,9 +1,10 @@
|
||||
$ . $TESTDIR/require-ext.sh remotenames
|
||||
|
||||
Setup
|
||||
|
||||
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
|
||||
$ export PYTHONPATH
|
||||
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
$ extpath=`dirname $TESTDIR`
|
||||
$ cat > $TESTTMP/pretxnchangegroup.sh << EOF
|
||||
> #!/bin/bash
|
||||
|
@ -1,4 +1,4 @@
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
$ . $TESTDIR/require-ext.sh remotenames
|
||||
$ extpath=`dirname $TESTDIR`
|
||||
$ cp $extpath/hgext3rd/reset.py $TESTTMP # use $TESTTMP substitution in message
|
||||
$ cat >> $HGRCPATH << EOF
|
||||
|
@ -150,6 +150,7 @@ Verify file status after reset
|
||||
|
||||
Reset + Evolve tests
|
||||
|
||||
$ . $TESTDIR/require-ext.sh evolve
|
||||
$ cat >> .hg/hgrc <<EOF
|
||||
> [extensions]
|
||||
> evolve=
|
||||
@ -193,6 +194,7 @@ a new hash for them
|
||||
|
||||
Reset + Inhibit tests, with inhibit reset revives the same commit
|
||||
|
||||
$ . $TESTDIR/require-ext.sh directaccess inhibit
|
||||
$ cat >> .hg/hgrc <<EOF
|
||||
> [extensions]
|
||||
> evolve =
|
||||
|
@ -1,4 +1,4 @@
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
$ . $TESTDIR/require-ext.sh remotenames
|
||||
$ extpath=`dirname $TESTDIR`
|
||||
$ cp $extpath/hgext3rd/smartlog.py $TESTTMP # use $TESTTMP substitution in message
|
||||
$ cat >> $HGRCPATH << EOF
|
||||
|
@ -1,5 +1,5 @@
|
||||
Skip test if remotenames not present
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
$ . $TESTDIR/require-ext.sh remotenames
|
||||
|
||||
Set up extensions (order is important here, we must test tweakdefaults loading last)
|
||||
$ extpath=`dirname $TESTDIR`
|
||||
|
@ -1,5 +1,5 @@
|
||||
Check for remotenames and skip if not present
|
||||
$ $PYTHON -c 'import remotenames' || exit 80
|
||||
$ . $TESTDIR/require-ext.sh remotenames
|
||||
|
||||
Set up
|
||||
$ extpath=`dirname $TESTDIR`
|
||||
|
@ -464,6 +464,7 @@ Test non-remotenames use of pull --rebase and --update requires --dest
|
||||
|
||||
Prepare a repo for testing divergence warnings with respect to inhibit extension
|
||||
and allowance of prune rebases
|
||||
$ . $TESTDIR/require-ext.sh directaccess evolve
|
||||
$ hg init repodiv && cd repodiv
|
||||
$ cat >> .hg/hgrc << EOF
|
||||
> [experimental]
|
||||
|
Loading…
Reference in New Issue
Block a user