tests/test-mq-qnew
author Renato Cunha <renatoc@gmail.com>
Tue, 03 Aug 2010 13:41:47 -0300
changeset 11747 40d5633889bb
parent 11575 a5903e612f07
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.

#!/bin/sh

catpatch() {
    cat $1 | sed -e "s/^\(# Parent \).*/\1/"
}

echo "[extensions]" >> $HGRCPATH
echo "mq=" >> $HGRCPATH

runtest() {
    hg init mq
    cd mq

    echo a > a
    hg ci -Ama

    echo '% qnew should refuse bad patch names'
    hg qnew series
    hg qnew status
    hg qnew guards
    hg qnew .hgignore
    hg qnew .mqfoo
    hg qnew 'foo#bar'
    hg qnew 'foo:bar'

    hg qinit -c

    echo '% qnew with name containing slash'
    hg qnew foo/bar.patch
    hg qseries
    hg qpop
    hg qdelete foo/bar.patch

    echo '% qnew with uncommitted changes'
    echo a > somefile
    hg add somefile
    hg qnew uncommitted.patch
    hg st
    hg qseries

    echo '% qnew implies add'
    hg -R .hg/patches st

    echo '% qnew missing'
    hg qnew missing.patch missing

    echo '% qnew -m'
    hg qnew -m 'foo bar' mtest.patch
    catpatch .hg/patches/mtest.patch

    echo '% qnew twice'
    hg qnew first.patch
    hg qnew first.patch

    touch ../first.patch
    hg qimport ../first.patch

    echo '% qnew -f from a subdirectory'
    hg qpop -a
    mkdir d
    cd d
    echo b > b
    hg ci -Am t
    echo b >> b
    hg st
    hg qnew -g -f p
    catpatch ../.hg/patches/p

    echo '% qnew -u with no username configured'
    HGUSER= hg qnew -u blue red
    catpatch ../.hg/patches/red

    echo '% qnew -e -u with no username configured'
    HGUSER= hg qnew -e -u chartreuse fucsia
    catpatch ../.hg/patches/fucsia

    echo '% fail when trying to import a merge'
    hg init merge
    cd merge
    touch a
    hg ci -Am null
    echo a >> a
    hg ci -m a
    hg up -r 0
    echo b >> a
    hg ci -m b
    hg merge -f 1
    hg resolve --mark a
    hg qnew -f merge

    cd ../../..
    rm -r mq
}


echo '%%% plain headers'

echo "[mq]" >> $HGRCPATH
echo "plain=true" >> $HGRCPATH

mkdir sandbox
(cd sandbox ; runtest)
rm -r sandbox


echo '%%% hg headers'

echo "plain=false" >> $HGRCPATH

mkdir sandbox
(cd sandbox ; runtest)
rm -r sandbox


exit 0