Skip to content

Commit afb7f8f

Browse files
authored
Separate out travis tests, one per different component to test. (EFForg#6220)
1 parent 6a64db5 commit afb7f8f

File tree

4 files changed

+106
-76
lines changed

4 files changed

+106
-76
lines changed

.travis.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ sudo: required
22
language: generic
33
services:
44
- docker
5-
before_install:
6-
- docker build -t httpse .
75
script:
8-
- docker run --rm -ti -v $(pwd):/opt -e FIREFOX=/$FIREFOX/firefox/firefox --privileged httpse bash -c "service miredo start && test/travis-ruleset-fetch.sh"
6+
- test/travis.sh
97
env:
10-
- FIREFOX=firefox-latest
11-
- FIREFOX=firefox-esr-latest
8+
- TEST=firefox FIREFOX=firefox-dev
9+
- TEST=firefox FIREFOX=firefox-latest
10+
- TEST=firefox FIREFOX=firefox-esr-latest
11+
- TEST=chromium
12+
- TEST=rules
13+
- TEST=fetch

test/fetch.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Run https-everywhere-checker for each changed ruleset
3+
# This is run from test/travis.sh, but should work just as well without travis
4+
# as long as $RULESETS_CHANGED is supplied.
5+
6+
RULETESTFOLDER="test/rules"
7+
8+
# Exclude those rulesets that do not exist.
9+
for RULESET in $RULESETS_CHANGED; do
10+
# First check if the given ruleset actually exists
11+
if [ ! -f $RULESET ]; then
12+
echo >&2 "Skipped $RULESET; file not found."
13+
continue
14+
fi
15+
TO_BE_TESTED="$TO_BE_TESTED $RULESET"
16+
done
17+
18+
if [ "$TO_BE_TESTED" ]; then
19+
# Do the actual test, using https-everywhere-checker.
20+
OUTPUT_FILE=`mktemp`
21+
trap 'rm "$OUTPUT_FILE"' EXIT
22+
python $RULETESTFOLDER/src/https_everywhere_checker/check_rules.py $RULETESTFOLDER/http.checker.config $TO_BE_TESTED 2>&1 | tee $OUTPUT_FILE
23+
# Unfortunately, no specific exit codes are available for connection
24+
# failures, so we catch those with grep.
25+
if [[ `cat $OUTPUT_FILE | grep ERROR | wc -l` -ge 1 ]]; then
26+
echo >&2 "Test URL test failed."
27+
exit 1
28+
fi
29+
fi
30+
echo >&2 "Test URL test succeeded."

test/travis-ruleset-fetch.sh

Lines changed: 0 additions & 71 deletions
This file was deleted.

test/travis.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
# Wrapper for travis tests
3+
4+
function docker_build {
5+
docker build -t httpse .
6+
}
7+
8+
# Folder paths, relative to parent
9+
RULESETFOLDER="src/chrome/content/rules"
10+
11+
# Go to git repo root; taken from ../test.sh. Note that
12+
# $GIT_DIR is .git in this case.
13+
if [ -n "$GIT_DIR" ]
14+
then
15+
# $GIT_DIR is set, so we're running as a hook.
16+
cd $GIT_DIR
17+
cd ..
18+
else
19+
# Git command exists? Cool, let's CD to the right place.
20+
git rev-parse && cd "$(git rev-parse --show-toplevel)"
21+
fi
22+
23+
# Fetch the current GitHub version of HTTPS-E to compare to its master
24+
git remote add upstream-for-travis https://github.com/EFForg/https-everywhere.git
25+
trap 'git remote remove upstream-for-travis' EXIT
26+
git fetch upstream-for-travis master
27+
COMMON_BASE_COMMIT=$(git merge-base upstream-for-travis/master HEAD)
28+
RULESETS_CHANGED=$(git diff --name-only $COMMON_BASE_COMMIT | grep $RULESETFOLDER | grep '.xml')
29+
if [ "$(git diff --name-only $COMMON_BASE_COMMIT)" != "$RULESETS_CHANGED" ]; then
30+
ONLY_RULESETS_CHANGED=false
31+
fi
32+
33+
# At this point, if anything fails, the test should fail
34+
set -e
35+
36+
if ! $ONLY_RULESETS_CHANGED; then
37+
echo >&2 "Core code changes have been made."
38+
if [ "$TEST" == "firefox" ]; then
39+
echo >&2 "Running firefox test suite."
40+
docker_build
41+
docker run --rm -ti -v $(pwd):/opt -e FIREFOX=/$FIREFOX/firefox/firefox httpse bash -c "test/firefox.sh"
42+
fi
43+
if [ "$TEST" == "chromium" ]; then
44+
echo >&2 "Running chromium test suite."
45+
docker_build
46+
# --privileged is required here because chromium requires kernel lxc access
47+
docker run --rm -ti -v $(pwd):/opt --privileged httpse bash -c "test/chromium.sh"
48+
fi
49+
fi
50+
# Only run test if something has changed.
51+
if [ "$RULESETS_CHANGED" ]; then
52+
echo >&2 "Ruleset database has changed."
53+
54+
if [ "$TEST" == "rules" ]; then
55+
echo >&2 "Performing comprehensive coverage test."
56+
docker_build
57+
docker run --rm -ti -v $(pwd):/opt httpse bash -c "test/rules.sh"
58+
fi
59+
60+
61+
if [ "$TEST" == "fetch" ]; then
62+
echo >&2 "Testing test URLs in all changed rulesets."
63+
docker_build
64+
# --privileged is required here for miredo to create a network tunnel
65+
docker run --rm -ti -v $(pwd):/opt -e RULESETS_CHANGED="$RULESETS_CHANGED" --privileged httpse bash -c "service miredo start && test/fetch.sh"
66+
fi
67+
fi
68+
69+
exit 0

0 commit comments

Comments
 (0)