summaryrefslogtreecommitdiff
path: root/test/run_tests.sh
blob: 4146b3ecf456efaf63098c39848ab7cc6d221307 (plain)
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
48
#!/usr/bin/env bash

testBin="../build/test/yajl_test"

if [[ ! -x $testBin ]] ; then
  echo "cannot execute test binary: '$testBin'"  
  exit 1;
fi

let testsSucceeded=0
let testsTotal=0 

for file in cases/*.json ; do
  allowComments="-c"

  # if the filename starts with dc_, we disallow comments for this test
  if [[ $(basename $file) == dc_* ]] ; then
    allowComments=""
  fi
  echo -n " test case: '$file': "
  let iter=1
  success="success"

  # parse with a read buffer size ranging from 1-31 to stress stream parsing
  while (( $iter < 32 )) && [ $success == "success" ] ; do
    $testBin $allowComments -b $iter < $file > ${file}.test  2>&1
    diff -u ${file}.gold ${file}.test
    if [[ $? == 0 ]] ; then
      if (( $iter == 31 )) ; then let testsSucceeded+=1 ; fi
    else 
      success="FAILURE"
      let iter=32
    fi
    let iter+=1
    rm ${file}.test
  done

  echo $success
  let testsTotal+=1
done

echo $testsSucceeded/$testsTotal tests successful

if [[ $testsSucceeded != $testsTotal ]] ; then
  exit 1
fi

exit 0