-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitunit
executable file
·47 lines (38 loc) · 1.48 KB
/
gitunit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
#@author Francisco Marcos fmarcos83@gmail.com
#@description executes phpunit -c phpunitgit.xml
# such configuration file must be stored
# in the root repository
function gitunit(){
configurationFilePath=$( git rev-parse --show-toplevel 2> /dev/null )
configurationFile="$configurationFilePath/phpunitgit.xml"
tmpOutput="/home/francisco/.gitunit/tmpoutput"
title="PHPUnit"
okIcon="/home/francisco/bin/.gitresources/tick.png"
wrIcon="/home/francisco/bin/.gitresources/warn.png"
message1="Not a git repository"
message2="It seems not a default php project"
message3="Wrong, please review your code"
message4="Green, you can commit now"
if [ $? -ne 0 ]; then
notify-send "$title" "$message1"
exit 1
fi
if [ ! -f $configurationFile ]; then
notify-send "$title" "$message2"
exit 1
fi
$( phpunit -c $configurationFile &> $tmpOutput )
if [ $? -ne 0 ]; then
notify-send "$title" "$message3" -i "$wrIcon"
exit 1
else
timeTaken=$( tail -n 3 $tmpOutput | grep -P 'Time: \d+ \w+' -o )
memoryTaken=$( tail -n 3 $tmpOutput | grep -P 'Memory: \d+\.\d+\w*' -o )
testsTaken=$( tail -n 3 $tmpOutput | grep -P '\d+ tests' -o )
assertionsTaken=$( tail -n 3 $tmpOutput | grep -P '\d+ assertions' -o )
notify-send "$title" "$message4\n$timeTaken
\n$memoryTaken\n$testsTaken\n$assertionsTaken" -i "$okIcon"
exit 0
fi
}