comparison tests/test-fix.t @ 37560:41ba336d9f1e

fix: use a portable python script instead of sed in test Differential Revision: https://phab.mercurial-scm.org/D2988
author Danny Hooper <hooper@google.com>
date Fri, 30 Mar 2018 17:01:12 -0700
parents ded5ea279a93
children 314f39e5fa86
comparison
equal deleted inserted replaced
37559:c4a0626f6b6e 37560:41ba336d9f1e
1 A script that implements uppercasing of specific lines in a file. This
2 approximates the behavior of code formatters well enough for our tests.
3
4 $ UPPERCASEPY="$TESTTMP/uppercase.py"
5 $ cat > $UPPERCASEPY <<EOF
6 > import sys
7 > from mercurial.utils.procutil import setbinary
8 > setbinary(sys.stdin)
9 > setbinary(sys.stdout)
10 > lines = set()
11 > for arg in sys.argv[1:]:
12 > if arg == 'all':
13 > sys.stdout.write(sys.stdin.read().upper())
14 > sys.exit(0)
15 > else:
16 > first, last = arg.split('-')
17 > lines.update(range(int(first), int(last) + 1))
18 > for i, line in enumerate(sys.stdin.readlines()):
19 > if i + 1 in lines:
20 > sys.stdout.write(line.upper())
21 > else:
22 > sys.stdout.write(line)
23 > EOF
24 $ TESTLINES="foo\nbar\nbaz\nqux\n"
25 $ printf $TESTLINES | $PYTHON $UPPERCASEPY
26 foo
27 bar
28 baz
29 qux
30 $ printf $TESTLINES | $PYTHON $UPPERCASEPY all
31 FOO
32 BAR
33 BAZ
34 QUX
35 $ printf $TESTLINES | $PYTHON $UPPERCASEPY 1-1
36 FOO
37 bar
38 baz
39 qux
40 $ printf $TESTLINES | $PYTHON $UPPERCASEPY 1-2
41 FOO
42 BAR
43 baz
44 qux
45 $ printf $TESTLINES | $PYTHON $UPPERCASEPY 2-3
46 foo
47 BAR
48 BAZ
49 qux
50 $ printf $TESTLINES | $PYTHON $UPPERCASEPY 2-2 4-4
51 foo
52 BAR
53 baz
54 QUX
55
1 Set up the config with two simple fixers: one that fixes specific line ranges, 56 Set up the config with two simple fixers: one that fixes specific line ranges,
2 and one that always fixes the whole file. They both "fix" files by converting 57 and one that always fixes the whole file. They both "fix" files by converting
3 letters to uppercase. They use different file extensions, so each test case can 58 letters to uppercase. They use different file extensions, so each test case can
4 choose which behavior to use by naming files. 59 choose which behavior to use by naming files.
5 60
8 > fix = 63 > fix =
9 > [experimental] 64 > [experimental]
10 > evolution.createmarkers=True 65 > evolution.createmarkers=True
11 > evolution.allowunstable=True 66 > evolution.allowunstable=True
12 > [fix] 67 > [fix]
13 > uppercase-whole-file:command=sed -e 's/.*/\U&/' 68 > uppercase-whole-file:command=$PYTHON $UPPERCASEPY all
14 > uppercase-whole-file:fileset=set:**.whole 69 > uppercase-whole-file:fileset=set:**.whole
15 > uppercase-changed-lines:command=sed 70 > uppercase-changed-lines:command=$PYTHON $UPPERCASEPY
16 > uppercase-changed-lines:linerange=-e '{first},{last} s/.*/\U&/' 71 > uppercase-changed-lines:linerange={first}-{last}
17 > uppercase-changed-lines:fileset=set:**.changed 72 > uppercase-changed-lines:fileset=set:**.changed
18 > EOF 73 > EOF
19 74
20 Help text for fix. 75 Help text for fix.
21 76
876 931
877 $ printf "foo\nbar\nbaz\n" > foo.changed 932 $ printf "foo\nbar\nbaz\n" > foo.changed
878 $ hg commit -Aqm "foo" 933 $ hg commit -Aqm "foo"
879 $ printf "Foo\nbar\nBaz\n" > foo.changed 934 $ printf "Foo\nbar\nBaz\n" > foo.changed
880 $ hg --debug fix --working-dir 935 $ hg --debug fix --working-dir
881 subprocess: sed -e '1,1 s/.*/\U&/' -e '3,3 s/.*/\U&/' 936 subprocess: * $TESTTMP/uppercase.py 1-1 3-3 (glob)
882 937
883 $ cd .. 938 $ cd ..
884 939
885 Fixing an obsolete revision can cause divergence, so we abort unless the user 940 Fixing an obsolete revision can cause divergence, so we abort unless the user
886 configures to allow it. This is not yet smart enough to know whether there is a 941 configures to allow it. This is not yet smart enough to know whether there is a