Replace sed with python script

sed escaping is wrong: e.g. re.escape() will escape `+`, but with BRE escaped 
plus is quantifier
This commit is contained in:
ZyX 2014-01-13 22:37:33 +04:00
parent 03245f192b
commit 0f0a5e92d3
3 changed files with 35 additions and 6 deletions

32
tests/test_shells/postproc.py Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
from __future__ import unicode_literals
import os
import socket
import sys
import codecs
fname = sys.argv[1]
new_fname = fname + '.new'
pid_fname = 'tests/shell/3rd/pid'
with open(pid_fname, 'r') as P:
pid = P.read().strip()
hostname = socket.gethostname()
user = os.environ['USER']
with codecs.open(fname, 'r', encoding='utf-8') as R:
with codecs.open(new_fname, 'w', encoding='utf-8') as W:
found_cd = False
for line in R:
if not found_cd:
found_cd = ('cd tests/shell/3rd' in line)
continue
line = line.replace(pid, 'PID')
line = line.replace(hostname, 'HOSTNAME')
line = line.replace(user, 'USER')
W.write(line)
os.rename(new_fname, fname)

View File

@ -24,12 +24,8 @@ run_test() {
while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do
sleep 1s
done
sed -i -e "1,3 d" \
-e s/$(cat tests/shell/3rd/pid)/PID/g \
-e "s/$(python -c 'import re, socket; print (re.escape(socket.gethostname()))')/HOSTNAME/g" \
-e "s/$(python -c 'import os, re; print (re.escape(os.environ["USER"]))')/USER/g" \
tests/shell/screen.log
if ! diff -u tests/test_shells/${SH}.ok tests/shell/screen.log ; then
./tests/test_shells/postproc.py tests/shell/screen.log
if ! diff -u tests/test_shells/${SH}.ok tests/shell/screen.log | cat -v ; then
return 1
fi
return 0

View File

@ -1,3 +1,4 @@
 USER  ⋯  tests  shell  3rd  POWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly )
 USER   BRANCH  ⋯  tests  shell  3rd  cd .git
 USER   BRANCH  ⋯  shell  3rd  .git  cd ..