How to parse the console on travis-ci and find the number of passed words
I am using github + travis-ci for continuous integration. I have a maven project with a lot of tests. I want to parse the whole console and find the special word xpath. If this word is present x times my work is OK, otherwise my work is KO.
how to parse the console on travis-ci and find the number of the passed word xpath or another method?
source to share
I am trying to use travis API =>
travis logs
But it is not possible with this API because I have an infinite loop (this command copies logs to logs to copy logs to logs to copy a copy ...). This API is good if you only read the logs of other builds !!!
And I find a solution:
in the .travis.yml file:
script:
- test/run.sh
in the run.sh file:
curl -s "https://api.travis-ci.org/jobs/${TRAVIS_JOB_ID}/log.txt?deansi=true" > nonaui.log
expectation=`sed -n 's:.*<EXPECTED_RESULTS>\(.*\)</EXPECTED_RESULTS>.*:\1:p' nonaui.log | head -n 1`
nb_expectation=`sed -n ":;s/$expectation//p;t" nonaui.log | sed -n '$='`
# 3 = 1 (real) + 2 counters (Excel and CSV)
if [ "$nb_expectation" == "3" ]; then
echo "******** All counter is SUCCESS"
else
echo "******** All counter is FAIL"
exit 255
fi
exit 0
source to share
Provided log.txt as input and required input lines like these:
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.957 sec - in TestSuite
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0
Assuming we just want to test "10", this might do:
n=5
awk -F '[ ,]*' '/^Tests run:/ \
{ if ($3>'$n') { print "OK found " $3 ; x=$3 ; exit} } \
END {if (x<'$n') print "Fail."} ' log.txt
Output:
OK found 10
source to share