Last active
August 29, 2015 14:15
-
-
Save phillipberndt/cc3e7e38d8c77b564aef to your computer and use it in GitHub Desktop.
autorandr test environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a small test environment for autorandr, that can be added as a | |
pre-commit git hook in local copies of the repository. | |
How-to: | |
Run `generate_fixtures.sh` to build all xrandr versions and generate fixtures. | |
Fixtures are a set of two files, FOO.version and FOO.verbose, that are the output | |
of `xrandr -v` and `xrandr --verbose -q`. You can also write more elaborate | |
tests by placing a script into the dynamic/ subfolder. It will be executed instead | |
of xrandr by tests. | |
Then run the test script. It will then run autorandr with | |
all the fixtures as input. If the expected output is known, it will compare the | |
outputs and complain if it differs. If it is not, it will ask you to confirm | |
that the output is as expected and if it is store the output away into the | |
"expect" folder. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
[ -d binaries ] || mkdir binaries | |
[ -d fixtures ] || mkdir fixtures | |
[ -d xrandr.git ] || git clone http://cgit.freedesktop.org/xorg/app/xrandr/ xrandr.git || exit 1 | |
cd xrandr.git || exit 1 | |
for TAG in $(git tag | grep "^xrandr-"); do | |
[ -e ../binaries/$TAG ] && continue | |
git reset --hard HEAD | |
git clean -fx | |
echo | |
echo "\033[1;31m--- $TAG ---\033[0m" | |
git checkout $TAG | |
mv configure.ac configure.ac~ | |
grep -vE "(m4_ifndef|m4_fatal|XORG_MACROS_VERSION|XORG_MANPAGE_SECTIONS)" configure.ac~ > configure.ac | |
./autogen.sh | |
make | |
mv xrandr ../binaries/$TAG | |
done | |
cd .. | |
LAST_FIXTURE=.nonexistant | |
for BINARY in binaries/xrandr-*; do | |
FIXNAME=fixtures/`hostname`-`basename $BINARY` | |
[ -e "$FIXNAME" ] && continue | |
$BINARY --verbose -q >> ${FIXNAME}.verbose | |
if [ -e "$LAST_FIXTURE" ] && diff ${FIXNAME}.verbose $LAST_FIXTURE >/dev/null; then | |
rm -f ${FIXNAME}.verbose | |
echo "\033[1m$BINARY\033[0m creates the same output as is in \033[1m${LAST_FIXTURE}\033[0m. Skipping." | |
continue | |
fi | |
LAST_FIXTURE=${FIXNAME}.verbose | |
$BINARY -v >> ${FIXNAME}.version | |
echo "Created fixture \033[1m$FIXNAME\033[0m for binary \033[1m$BINARY\033[0m" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
export PATH=`pwd`:$PATH | |
export RV=0 | |
test() { | |
ID=`basename $1` | |
${PYTHON:-} ../autorandr.py --config >output 2>&1 | |
if [ -e expect/$ID ]; then | |
if ! diff output expect/$ID >/dev/null 2>&1; then | |
echo "\033[31;1;4m$1\033[0m" | |
diff -Nru expect/$ID output | sed -re "s#^\+#\\x1b[34m+#; s#^\-#\\x1b[33m-#; s#^#\\x1b[0m#" | |
export RV=1 | |
else | |
echo "\033[32;1m$1\033[0m" | |
fi | |
rm -f output | |
else | |
echo "\033[33;1m$1\033[0m" | |
cat output | |
echo "Ok? (<C-c> to cancel, or I'll store this as expect/$ID)" | |
read ok | |
mv output expect/$ID | |
fi | |
} | |
generate_xrandr() { | |
rm -f xrandr | |
cat > xrandr <<EOF | |
#!/bin/sh | |
if [ "\$1" = "-v" ]; then | |
[ -e "${1}.version" ] && cat ${1}.version | |
else | |
cat ${1}.verbose | |
fi | |
EOF | |
chmod +x xrandr | |
} | |
[ -d expect ] || mkdir expect | |
for FIXTURE in fixtures/*.verbose; do | |
FIXTURE=${FIXTURE%.verbose} | |
generate_xrandr $FIXTURE | |
test $FIXTURE | |
done | |
for SCRIPT in dynamic/*; do | |
[ -x $SCRIPT ] || continue | |
rm -f xrandr | |
ln -s $SCRIPT xrandr | |
test $SCRIPT | |
done | |
rm -f xrandr | |
exit $RV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment