tests/test-mq-eol
author Renato Cunha <renatoc@gmail.com>
Tue, 03 Aug 2010 13:41:47 -0300
changeset 11747 40d5633889bb
parent 10190 9c2c94934f0d
permissions -rwxr-xr-x
hgfixes: add a fixer to convert plain strings to bytestrings This patch implements a 2to3 fixer that converts all plain strings in a python source file to byte strings syntax. Example: foo = 'Normal string' would become foo = b'Normal string' The motivation behind this fixer can be found in http://selenic.com/pipermail/mercurial-devel/2010-June/022363.html or, in other words: the current hg source assumes that _most_ strings are "meant" to be byte sequences, so it makes sense to make the convertion implemented by this patch. As mentioned above, not all mercurial modules want to use strings as bytes, examples include i18n (which uses unicode), and demandimport (in py3k, module names are normal strings, thus unicode, and there's no need for a convertion). Therefore, these modules are blacklisted in the fixer. There are also a few functions that can take only unicode arguments, thus the convertion shouldn't be done for those.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8811
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     1
#!/bin/sh
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     2
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     3
# Test interactions between mq and patch.eol
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     4
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     5
echo "[extensions]" >> $HGRCPATH
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     6
echo "mq=" >> $HGRCPATH
10190
9c2c94934f0d mq: upgrade to git patch when necessary (issue767)
Patrick Mezard <pmezard@gmail.com>
parents: 10129
diff changeset
     7
echo "[diff]" >> $HGRCPATH
9c2c94934f0d mq: upgrade to git patch when necessary (issue767)
Patrick Mezard <pmezard@gmail.com>
parents: 10129
diff changeset
     8
echo "nodates=1" >> $HGRCPATH
8811
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     9
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    10
cat > makepatch.py <<EOF
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    11
f = file('eol.diff', 'wb')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    12
w = f.write
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    13
w('test message\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    14
w('diff --git a/a b/a\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    15
w('--- a/a\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    16
w('+++ b/a\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    17
w('@@ -1,5 +1,5 @@\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    18
w(' a\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    19
w('-b\r\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    20
w('+y\r\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    21
w(' c\r\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    22
w(' d\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    23
w('-e\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    24
w('\ No newline at end of file\n')
10129
900ccbd79ef7 diffhelpers: handle CRLF in hunk last line without EOL
Patrick Mezard <pmezard@gmail.com>
parents: 10128
diff changeset
    25
w('+z\r\n')
8811
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    26
w('\ No newline at end of file\r\n')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    27
EOF
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    28
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    29
cat > cateol.py <<EOF
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    30
import sys
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    31
for line in file(sys.argv[1], 'rb'):
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    32
    line = line.replace('\r', '<CR>')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    33
    line = line.replace('\n', '<LF>')
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    34
    print line
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    35
EOF
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    36
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    37
hg init repo
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    38
cd repo
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    39
echo '\.diff' > .hgignore
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    40
echo '\.rej' >> .hgignore
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    41
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    42
# Test different --eol values
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    43
python -c 'file("a", "wb").write("a\nb\nc\nd\ne")'
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    44
hg ci -Am adda
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    45
python ../makepatch.py
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    46
hg qimport eol.diff
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    47
echo % should fail in strict mode
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    48
hg qpush
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    49
hg qpop
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    50
echo % invalid eol
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    51
hg --config patch.eol='LFCR' qpush
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    52
hg qpop
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    53
echo % force LF
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    54
hg --config patch.eol='CRLF' qpush
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    55
hg qrefresh
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    56
python ../cateol.py .hg/patches/eol.diff
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    57
python ../cateol.py a
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    58
hg qpop
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    59
echo % push again forcing LF and compare revisions
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    60
hg --config patch.eol='CRLF' qpush
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    61
python ../cateol.py a
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    62
hg qpop
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    63
echo % push again without LF and compare revisions
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    64
hg qpush
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    65
python ../cateol.py a
8b35b08724eb Make mq, record and transplant honor patch.eol
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    66
hg qpop