tests/test-hgweb-commands
author Yuya Nishihara <yuya@tcha.org>
Sat, 07 Aug 2010 16:27:16 +0900
branchstable
changeset 11765 aff419e260f9
parent 10414 1a8df80dfdde
child 11766 a65ea28269ef
permissions -rwxr-xr-x
templatefilters: make json filter handle multibyte characters correctly It aims to fix javascript error of hgweb's graph view in Japanese 'cp932' encoding. 'cp932' contains multibyte characters ending with '\x5c' (backslash), e.g. '\x94\x5c' for Japanese Kanji 'Noh'. Due to json filter escapes '\' to '\\', multibyte string ending with '\x5c' is translated to "xxx\", resulting javascript parse error on a web browser. This patch changes json() to pass unicode to jsonescape(). Unicode decoding error handler changed to 'replace' by Patrick Mézard.

#!/bin/sh
# An attempt at more fully testing the hgweb web interface.
# The following things are tested elsewhere and are therefore omitted:
# - archive, tested in test-archive
# - unbundle, tested in test-push-http
# - changegroupsubset, tested in test-pull

echo % Set up the repo
hg init test
cd test
mkdir da
echo foo > da/foo
echo foo > foo
hg ci -Ambase
hg tag 1.0
echo another > foo
hg branch stable
hg ci -Ambranch
hg serve --config server.uncompressed=False -n test -p $HGPORT -d --pid-file=hg.pid -E errors.log
cat hg.pid >> $DAEMON_PIDS

echo % Logs and changes
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/log/?style=atom' | sed "s/http:\/\/[^/]*\//http:\/\/127.0.0.1\//"
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/log/1/?style=atom' | sed "s/http:\/\/[^/]*\//http:\/\/127.0.0.1\//"
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/log/1/foo/?style=atom' | sed "s/http:\/\/[^/]*\//http:\/\/127.0.0.1\//"
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/shortlog/'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/rev/0/'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/rev/1/?style=raw'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/log?rev=base'

echo % File-related
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/file/1/foo/?style=raw'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/annotate/1/foo/?style=raw'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/file/1/?style=raw'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/file/1/foo'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/filediff/1/foo/?style=raw'

echo % Overviews
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/raw-tags'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/raw-branches'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/summary/?style=gitweb'
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/graph/?style=gitweb'

echo % capabilities
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=capabilities'
echo % heads
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=heads'
echo % lookup
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=lookup&node=1'
echo % branches
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=branches'
echo % changegroup
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=changegroup' \
    | $TESTDIR/printrepr.py
echo % stream_out
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=stream_out'
echo % failing unbundle, requires POST request
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=unbundle'

echo % Static files
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/static/style.css'

echo % Stop and restart with HGENCODING=cp932
"$TESTDIR/killdaemons.py"
HGENCODING=cp932 hg serve --config server.uncompressed=False -n test \
    -p $HGPORT -d --pid-file=hg.pid -E errors.log
cat hg.pid >> $DAEMON_PIDS

# commit message with Japanese Kanji 'Noh', which ends with '\x5c'
echo foo >> foo
HGENCODING=cp932 hg ci -m `python -c 'print("\x94\x5c")'`

echo % Graph json escape of multibyte character
"$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/graph/' \
    | grep '^var data ='

echo % ERRORS ENCOUNTERED
cat errors.log