tests/test-notify
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
Fri, 13 Aug 2010 17:21:06 +0200
branchstable
changeset 11889 3b65c3c3cc8d
parent 8142 912bfef12ba6
permissions -rwxr-xr-x
test-notify: make it pass on Mac OS X (again) Changeset 25e74cd3f023 (from 2008) introduced a hack to handle the very long values of $TMPDIR typically seen on Mac OS X. This hack expected continuation lines to begin with a tab. However, as a result of a change in Python 2.7, changeset 594b98846ce1 made it so continuation lines began with a tab. Since then, `test-notify' has been broken on Mac OS X. Merely replacing the tab in the regular expression with a space will not work: not only do tab continuations still occur in the message, but other lines -- in the body of the message -- also start with a space. Luckily, all broken up lines appear to end with either a colon or an n, so we can match those, and reinsert them in the replacement.

#!/bin/sh

cat <<EOF >> $HGRCPATH
[extensions]
notify=

[hooks]
incoming.notify = python:hgext.notify.hook

[notify]
sources = pull
diffstat = False

[usersubs]
foo@bar = *

[reposubs]
* = baz
EOF

hg help notify
hg init a
echo a > a/a
echo % commit
hg --traceback --cwd a commit -Ama -d '0 0'

echo % clone
hg --traceback clone a b

echo a >> a/a
echo % commit
hg --traceback --cwd a commit -Amb -d '1 0'

# on Mac OS X 10.5 the tmp path is very long so would get stripped in the subject line
cat <<EOF >> $HGRCPATH
[notify]
maxsubject = 200
EOF

# the python call below wraps continuation lines, which appear on Mac OS X 10.5 because
# of the very long subject line
echo '% pull (minimal config)'
hg --traceback --cwd b pull ../a 2>&1 |
  python -c 'import sys,re; print re.sub("([n:])\\n[\\t ]", "\\1 ", sys.stdin.read()),' |
  sed -e 's/\(Message-Id:\).*/\1/' \
  -e 's/changeset \([0-9a-f]* *\)in .*test-notif/changeset \1in test-notif/' \
  -e 's/^details: .*test-notify/details: test-notify/' \
  -e 's/^Date:.*/Date:/'

cat <<EOF >> $HGRCPATH
[notify]
config = $HGTMP/.notify.conf
domain = test.com
strip = 3
template = Subject: {desc|firstline|strip}\nFrom: {author}\nX-Test: foo\n\nchangeset {node|short} in {webroot}\ndescription:\n\t{desc|tabindent|strip}

[web]
baseurl = http://test/
EOF

echo % fail for config file is missing
hg --cwd b rollback
hg --cwd b pull ../a 2>&1 | grep 'error.*\.notify\.conf' > /dev/null && echo pull failed

touch "$HGTMP/.notify.conf"

echo % pull
hg --cwd b rollback
hg --traceback --cwd b pull ../a 2>&1 | sed -e 's/\(Message-Id:\).*/\1/' \
  -e 's/changeset \([0-9a-f]*\) in .*/changeset \1/' \
  -e 's/^Date:.*/Date:/'

cat << EOF >> $HGRCPATH
[hooks]
incoming.notify = python:hgext.notify.hook

[notify]
sources = pull
diffstat = True
EOF

echo % pull
hg --cwd b rollback
hg --traceback --cwd b pull ../a 2>&1 | sed -e 's/\(Message-Id:\).*/\1/' \
  -e 's/changeset \([0-9a-f]*\) in .*/changeset \1/' \
  -e 's/^Date:.*/Date:/'

echo % test merge
cd a
hg up -C 0
echo a >> a
hg ci -Am adda2 -d '2 0'
hg merge
hg ci -m merge -d '3 0'
cd ..

hg --traceback --cwd b pull ../a 2>&1 | sed -e 's/\(Message-Id:\).*/\1/' \
  -e 's/changeset \([0-9a-f]*\) in .*/changeset \1/' \
  -e 's/^Date:.*/Date:/'