|
1 |
| -#!/bin/bash |
| 1 | +#!/bin/bash |
2 | 2 |
|
3 | 3 | # Test helper script for jprops
|
4 | 4 | #
|
5 | 5 | # Kishan Thomas <kishan.thomas@gmail.com>
|
6 | 6 |
|
7 | 7 | RED='\033[0;31m'
|
8 | 8 | GREEN='\033[0;32m'
|
9 |
| -NC='\033[0m' # No Color |
| 9 | +NC='\033[0m' |
10 | 10 |
|
11 | 11 | # Import jprops from parent folder
|
12 | 12 | export PYTHONPATH="../:$PYTHONPATH"
|
13 | 13 |
|
14 |
| -# The expected properties |
15 |
| -PROPERTY_COUNT=$(wc -l test.properties|awk '{ print $1}') |
16 |
| - |
17 | 14 | # Use Java and get all the properties ordered by key from test.properties
|
18 | 15 | javac Test.java
|
19 | 16 | java Test > java.props.out
|
20 | 17 | # Use Python jprops and get all the properties ordered by key from test.properties
|
| 18 | +#python test.py > python.props.out |
21 | 19 | python test.py > python.props.out
|
22 | 20 |
|
23 | 21 | JAVA_COUNT=$( expr $(wc -l java.props.out|awk '{ print $1}') - 2 )
|
24 | 22 | PYTHON_COUNT=$( expr $(wc -l python.props.out|awk '{ print $1}') - 2 )
|
25 | 23 |
|
26 |
| -# Check both Java and Python jprops found the same number of properties from the same test.properties |
27 |
| -echo "Expected $PROPERTY_COUNT, Java found $JAVA_COUNT, Python jprops found $PYTHON_COUNT" |
| 24 | +# Check both Java and Python jprops found the same number of properties from the same test.properties |
| 25 | +echo "Java found $JAVA_COUNT properties, Python jprops found $PYTHON_COUNT properties from test.properties" |
28 | 26 |
|
29 |
| -if [ $JAVA_COUNT != $PROPERTY_COUNT ] || [ $PYTHON_COUNT != $PROPERTY_COUNT ] |
30 |
| -then |
31 |
| - diff java.props.out python.props.out |
32 |
| - echo -e "${RED}Test Fail: The properties count $JAVA_COUNT (Java) and/or $PYTHON_COUNT (jprops) do not match the expected count $PROPERTY_COUNT ${NC}" |
| 27 | +if [ $JAVA_COUNT != $PYTHON_COUNT ] |
| 28 | +then |
| 29 | + diff java.props.out python.props.out |
| 30 | + echo -e "${RED}Test Fail: The properties counted by Java $JAVA_COUNT, does not math the count from Python jprops $PYTHON_COUNT${NC}" |
33 | 31 | exit 1
|
34 | 32 | else
|
35 |
| - echo -e "${GREEN}Test Pass: The properties count $PYTHON_COUNT match the expected count $PROPERTY_COUNT ${NC}" |
36 |
| -fi |
| 33 | + echo -e "${GREEN}Test Pass: The properties count $PYTHON_COUNT match the expected count $JAVA_COUNT ${NC}" |
| 34 | +fi |
37 | 35 |
|
38 |
| -# Both outputs are ordered by key and formatted in matching format (json) |
| 36 | +# Both outputs are ordered by key and formatted in matching format (json) |
39 | 37 | # So a simple diff can find if they both match TODO: Use a json tool for matching
|
40 |
| -if diff java.props.out python.props.out; then |
41 |
| - echo -e "${GREEN}Test Pass: All $PROPERTY_COUNT properties match${NC}" |
| 38 | +if diff java.props.out python.props.out; then |
| 39 | + echo -e "${GREEN}Test Pass: All $JAVA_COUNT properties match${NC}" |
42 | 40 | else
|
43 |
| - echo -e "${RED}Test Fail: Not all $PROPERTY_COUNT properties match${NC}" |
| 41 | + echo -e "${RED}Test Fail: Not all $JAVA_COUNT properties match${NC}" |
44 | 42 | exit 1
|
45 | 43 | fi
|
0 commit comments