www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

runtests.sh (6087B)


      1 #!/bin/bash
      2 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
      3 ROOT_DIR="$( cd "$( dirname "$SCRIPT_DIR" )" && pwd )"
      4 
      5 case "$OSTYPE" in
      6   msys*|mingw*|cygwin*) IS_CYGWIN=1 ;;
      7 esac
      8 
      9 function makePath {
     10 	local __assignTo=$1
     11 	local __path=$2
     12 	if [ ! -z $IS_CYGWIN ]; then
     13 		__path="`cygpath -aw \"$__path\"`"
     14 	fi
     15 	eval $__assignTo="'$__path'"
     16 }
     17 
     18 if [ -z "$FX_EXECUTABLE" ]; then
     19 	if [ "`uname`" == "Darwin" ]; then
     20 		FX_EXECUTABLE="/Applications/Firefox Unbranded.app/Contents/MacOS/firefox"
     21 	else
     22 		FX_EXECUTABLE="firefox"
     23 	fi
     24 fi
     25 
     26 if [ -z "$DISPLAY" ]; then
     27 	FX_ARGS=""
     28 else
     29 	FX_ARGS="--class=ZTestFirefox"
     30 fi
     31 
     32 function usage {
     33 	cat >&2 <<DONE
     34 Usage: $0 [option] [TESTS...]
     35 Options
     36  -b                  skip bundled translator/style installation
     37  -c                  open JavaScript console and don't quit on completion
     38  -d LEVEL            enable debug logging
     39  -e TEST             end at the given test
     40  -f                  stop after first test failure
     41  -g                  only run tests matching the given pattern (grep)
     42  -h                  display this help
     43  -s TEST             start at the given test
     44  -t                  generate test data and quit
     45  -x FX_EXECUTABLE    path to Firefox executable (default: $FX_EXECUTABLE)
     46  TESTS               set of tests to run (default: all)
     47 DONE
     48 	exit 1
     49 }
     50 
     51 DEBUG=false
     52 DEBUG_LEVEL=5
     53 while getopts "bcd:e:fg:hs:tx:" opt; do
     54 	case $opt in
     55         b)
     56         	FX_ARGS="$FX_ARGS -ZoteroSkipBundledFiles"
     57         	;;
     58 		c)
     59 			FX_ARGS="$FX_ARGS -jsconsole -noquit"
     60 			;;
     61 		d)
     62 			DEBUG=true
     63 			DEBUG_LEVEL="$OPTARG"
     64 			;;
     65 		e)
     66 			if [[ -z "$OPTARG" ]] || [[ ${OPTARG:0:1} = "-" ]]; then
     67 				usage
     68 			fi
     69 			FX_ARGS="$FX_ARGS -stopAtTestFile $OPTARG"
     70 			;;
     71 		f)
     72 			FX_ARGS="$FX_ARGS -bail"
     73 			;;
     74 		g)
     75 			GREP="$OPTARG"
     76 			;;
     77 		h)
     78 			usage
     79 			;;
     80 		s)
     81 			if [[ -z "$OPTARG" ]] || [[ ${OPTARG:0:1} = "-" ]]; then
     82 				usage
     83 			fi
     84 			FX_ARGS="$FX_ARGS -startAtTestFile $OPTARG"
     85 			;;
     86 		t)
     87 			FX_ARGS="$FX_ARGS -makeTestData"
     88 			;;
     89 		x)
     90 			FX_EXECUTABLE="$OPTARG"
     91 			;;
     92 		*)
     93 			usage
     94 			;;
     95 	esac
     96 	shift $((OPTIND-1)); OPTIND=1
     97 done
     98 
     99 if [ -z $1 ]; then
    100 	TESTS="all"
    101 else
    102 	ARGS=("${@:1}")
    103 	function join { local IFS="$1"; shift; echo "$*"; }
    104 	TESTS="$(join , "${ARGS[@]}")"
    105 fi
    106 
    107 # Increase open files limit
    108 #
    109 # Mozilla file functions (OS.File.move()/copy(), NetUtil.asyncFetch/asyncCopy()) can leave file
    110 # descriptors open for a few seconds (even with an explicit inputStream.close() in the case of
    111 # the latter), so a source installation that copies ~500 translators and styles (with fds for
    112 # source and target) can exceed the default 1024 limit.
    113 ulimit -n 4096
    114 
    115 # Set up profile directory
    116 TEMPDIR="`mktemp -d 2>/dev/null || mktemp -d -t 'zotero-unit'`"
    117 PROFILE="$TEMPDIR/profile"
    118 mkdir -p "$PROFILE/extensions"
    119 
    120 makePath ZOTERO_PATH "$ROOT_DIR/build"
    121 echo "$ZOTERO_PATH" > "$PROFILE/extensions/zotero@chnm.gmu.edu"
    122 
    123 makePath ZOTERO_UNIT_PATH "$ZOTERO_PATH/test"
    124 echo "$ZOTERO_UNIT_PATH" > "$PROFILE/extensions/zotero-unit@zotero.org"
    125 
    126 # Create data directory
    127 mkdir "$TEMPDIR/Zotero"
    128 
    129 # Download PDF tools if not cached in the source directory and copy to profile directory
    130 PDF_TOOLS_VERSION="0.0.3"
    131 PDF_TOOLS_URL="https://zotero-download.s3.amazonaws.com/pdftools/pdftools-$PDF_TOOLS_VERSION.tar.gz"
    132 PDF_TOOLS_CACHE_DIR="$ROOT_DIR/tmp/pdftools"
    133 PDF_TOOLS_DIR="$PROFILE/pdftools"
    134 if [ ! -f "$PDF_TOOLS_CACHE_DIR/$PDF_TOOLS_VERSION" ]; then
    135 	echo "Fetching PDF tools version $PDF_TOOLS_VERSION"
    136 	echo
    137 	rm -rf "$PDF_TOOLS_CACHE_DIR"
    138 	mkdir -p "$PDF_TOOLS_CACHE_DIR"
    139 	curl -o "$PDF_TOOLS_CACHE_DIR/pdftools.tar.gz" $PDF_TOOLS_URL
    140 	tar -zxf "$PDF_TOOLS_CACHE_DIR/pdftools.tar.gz" -C $PDF_TOOLS_CACHE_DIR
    141 	rm "$PDF_TOOLS_CACHE_DIR/pdftools.tar.gz"
    142 	touch "$PDF_TOOLS_CACHE_DIR/$PDF_TOOLS_VERSION"
    143 	echo
    144 fi
    145 cp -R $PDF_TOOLS_CACHE_DIR $PDF_TOOLS_DIR
    146 
    147 cat <<EOF > "$PROFILE/prefs.js"
    148 user_pref("app.update.enabled", false);
    149 user_pref("extensions.autoDisableScopes", 0);
    150 user_pref("browser.tabs.remote.autostart", false);
    151 user_pref("browser.tabs.remote.autostart.2", false);
    152 user_pref("browser.uitour.enabled", false);
    153 user_pref("browser.shell.checkDefaultBrowser", false);
    154 user_pref("dom.max_chrome_script_run_time", 0);
    155 // It would be better to leave this on and handle it in Sinon's FakeXMLHttpRequest
    156 user_pref("extensions.zotero.sync.server.compressData", false);
    157 user_pref("extensions.zotero.debug.log", $DEBUG);
    158 user_pref("extensions.zotero.debug.level", $DEBUG_LEVEL);
    159 user_pref("extensions.zotero.debug.time", $DEBUG);
    160 user_pref("extensions.zotero.firstRun.skipFirefoxProfileAccessCheck", true);
    161 user_pref("extensions.zotero.firstRunGuidance", false);
    162 user_pref("extensions.zotero.firstRun2", false);
    163 user_pref("extensions.zotero.reportTranslationFailure", false);
    164 user_pref("extensions.zotero.httpServer.enabled", true);
    165 user_pref("extensions.zotero.backup.numBackups", 0);
    166 user_pref("extensions.zotero.sync.autoSync", false);
    167 user_pref("xpinstall.signatures.required", false);
    168 user_pref("datareporting.healthreport.uploadEnabled", false);
    169 user_pref("datareporting.healthreport.service.enabled", false);
    170 user_pref("datareporting.healthreport.service.firstRun", false);
    171 user_pref("datareporting.policy.dataSubmissionEnabled", false);
    172 user_pref("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
    173 EOF
    174 
    175 # -v flag on Windows makes Firefox process hang
    176 if [ -z $IS_CYGWIN ]; then
    177 	echo "`MOZ_NO_REMOTE=1 NO_EM_RESTART=1 \"$FX_EXECUTABLE\" -v`"
    178 fi
    179 
    180 if [ "$TRAVIS" = true ]; then
    181 	FX_ARGS="$FX_ARGS -ZoteroAutomatedTest -ZoteroTestTimeout 15000"
    182 fi
    183 
    184 # Clean up on exit
    185 trap "{ rm -rf \"$TEMPDIR\"; }" EXIT
    186 
    187 # Check if build watch process is running
    188 # If not, run now
    189 if [[ "$TRAVIS" != true ]] && ! ps | grep scripts/build.js | grep -v grep > /dev/null; then
    190 	echo
    191 	echo "Running JS build process"
    192 	cd "$ROOT_DIR"
    193 	npm run build || exit $?
    194 	echo
    195 fi
    196 
    197 makePath FX_PROFILE "$PROFILE"
    198 MOZ_NO_REMOTE=1 NO_EM_RESTART=1 "$FX_EXECUTABLE" -profile "$FX_PROFILE" \
    199     -chrome chrome://zotero-unit/content/runtests.html -test "$TESTS" -grep "$GREP" -ZoteroTest $FX_ARGS
    200 
    201 # Check for success
    202 test -e "$PROFILE/success"
    203 STATUS=$?
    204 
    205 exit $STATUS