github.com/clysto/awgo@v0.15.0/run-tests.sh (about) 1 #!/usr/bin/env zsh 2 3 # URL of icon generator 4 root="$( cd "$( dirname "$0" )"; pwd )" 5 testdir="${root}/testenv" 6 iplist="${root}/info.plist" 7 covfile="${root}/coverage.out" 8 9 verbose=false 10 opencover=false 11 cover=false 12 mkip=false 13 vopt= 14 gopts=() 15 16 # log <arg>... | Echo arguments to STDERR 17 log() { 18 echo "$@" >&2 19 } 20 21 # info <arg>.. | Write args to STDERR if VERBOSE is true 22 info() { 23 $verbose && log $(print -P "%F{blue}.. %f") "$@" 24 return 0 25 } 26 27 # success <arg>.. | Write green "ok" and args to STDERR if VERBOSE is true 28 success() { 29 # $verbose && log $(print -P "%F{green}ok %f") "$@" 30 log $(print -P "%F{green}#####################################%f") 31 log $(print -P "%F{green}# $@ %f") 32 log $(print -P "%F{green}#####################################%f") 33 return 0 34 } 35 36 # error <arg>.. | Write red "error" and args to STDERR 37 error() { 38 log $(print -P '%F{red}err%f') "$@" 39 } 40 41 # fail <arg>.. | Write red "error" and args to STDERR, then exit with status 1 42 fail() { 43 log $(print -P "%F{red}#####################################%f") 44 log $(print -P "%F{red}# $@ %f") 45 log $(print -P "%F{red}#####################################%f") 46 # error "$@" 47 exit 1 48 } 49 50 usage() { 51 cat <<EOF 52 run-tests.sh [options] [<module>...] 53 54 Run unit tests in a workflow-like environment. 55 56 Usage: 57 run-tests.sh [-v|-V] [-c] [-i] [-H] 58 run-tests.sh -h 59 60 Options: 61 -c Write coverage report 62 -i Create a dummy info.plist 63 -H Open HTML coverage report 64 -h Show this help message and exit 65 -v Be verbose 66 -V Be even more verbose 67 EOF 68 } 69 70 while getopts ":HchivV" opt; do 71 case $opt in 72 c) 73 cover=true 74 ;; 75 H) 76 opencover=true 77 cover=true 78 ;; 79 i) 80 mkip=true 81 ;; 82 V) 83 gopts+=(-v) 84 verbose=true 85 vopt='-v' 86 ;; 87 V) 88 gopts+=(-v) 89 verbose=true 90 ;; 91 h) 92 usage 93 exit 0 94 ;; 95 \?) 96 fail "invalid option: -$OPTARG";; 97 esac 98 done 99 shift $((OPTIND-1)) 100 101 $cover && gopts+=(-coverprofile="$covfile") 102 103 command mkdir $vopt -p "${testdir}"/{data,cache} 104 $mkip && touch $vopt "$iplist" 105 106 # Absolute bare-minimum for AwGo to function... 107 export alfred_workflow_bundleid="net.deanishe.awgo" 108 export alfred_workflow_cache="${testdir}/cache" 109 export alfred_workflow_data="${testdir}/data" 110 111 # Expected by ExampleNew 112 export alfred_workflow_version="0.14" 113 export alfred_workflow_name="AwGo" 114 115 cd "$root" 116 117 go test $gopts "$@" 118 st=$? 119 120 cd - 121 122 command rm $vopt -rf "$testdir"/* 123 test -f "$iplist" && command rm $vopt -f "$iplist" 124 125 [[ st -eq 0 ]] || { 126 fail "go test failed with $st" 127 } 128 129 success "tests passed" 130 131 $opencover && go tool cover -html="$covfile" 132 133 exit 0 134 135 # vim: set ft=zsh ts=2 sw=2 tw=100 et :