Project

General

Profile

test_9727.sh

Roger Borrello, 10/12/2026 06:18 PM

Download (4.27 KB)

 
1
#!/bin/bash
2
#
3
# Smoke tests for #9727: -? syntax help and clean exits on early fatal errors in
4
# ConversionDriver, ProgressTransformDriver and ReportDriver.
5
#
6
# Usage: test_9727.sh [fwd_branch_dir] [project_dir]
7
#   fwd_branch_dir  FWD branch with a completed build (default ~/projects/fwd/9727a)
8
#   project_dir     converted project with cfg/p2j.cfg.xml (default ~/projects/hotel_gui_dev)
9
#
10
# A full conversion and a report run are not done here; run those separately.
11

    
12
FWD=${1:-~/projects/fwd/9727a}
13
PROJ=${2:-~/projects/hotel_gui_dev}
14
CP="$FWD/build/lib/*"
15

    
16
CD=com.goldencode.p2j.convert.ConversionDriver
17
PTD=com.goldencode.p2j.convert.ProgressTransformDriver
18
RD=com.goldencode.p2j.report.ReportDriver
19

    
20
WORK=$(mktemp -d)
21
trap 'rm -rf "$WORK"' EXIT
22

    
23
PASS=0
24
FAIL=0
25

    
26
# check <description> <expected rc> <help stream: out|err|none> <expected text or ""> <dir> <class> [args...]
27
check()
28
{
29
   local desc=$1 exp_rc=$2 help=$3 text=$4 dir=$5
30
   shift 5
31

    
32
   (cd "$dir" && timeout 120 java -cp "$CP" -DP2J_HOME=. "$@" > "$WORK/out" 2> "$WORK/err")
33
   local rc=$?
34
   local why=""
35

    
36
   [ "$rc" -eq "$exp_rc" ] || why="rc=$rc (expected $exp_rc)"
37
   cat "$WORK/out" "$WORK/err" > "$WORK/all"
38

    
39
   case $help in
40
      out) grep -q "^Syntax:" "$WORK/out" || why="$why; no help on stdout" ;;
41
      err) grep -q "^Syntax:" "$WORK/err" || why="$why; no help on stderr" ;;
42
   esac
43

    
44
   if [ -n "$text" ] && ! grep -qF -- "$text" "$WORK/all"; then
45
      why="$why; missing \"$text\""
46
   fi
47
   if grep -q "Exception" "$WORK/all"; then
48
      why="$why; exception in output"
49
   fi
50
   if grep -q "Syntax:_" "$WORK/all"; then
51
      why="$why; help text flattened by the logger"
52
   fi
53

    
54
   if [ -z "$why" ]; then
55
      PASS=$((PASS + 1))
56
      echo "PASS  $desc"
57
   else
58
      FAIL=$((FAIL + 1))
59
      echo "FAIL  $desc: ${why#; }"
60
      sed 's/^/        | /' "$WORK/all" | head -8
61
   fi
62
}
63

    
64
if ! ls $CP > /dev/null 2>&1; then
65
   echo "No jars found in $FWD/build/lib; build the branch first."
66
   exit 2
67
fi
68

    
69
# 1. no project at all (no cfg/ directory)
70
NOPROJ="$WORK/noproj"
71
mkdir -p "$NOPROJ"
72
echo "--- no project ($NOPROJ)"
73
check "CD -?"                    0   out  ""                                  "$NOPROJ" $CD  '-?'
74
check "PTD -?"                   0   out  ""                                  "$NOPROJ" $PTD '-?'
75
check "RD -?"                    0   out  ""                                  "$NOPROJ" $RD  '-?'
76
check "CD -D2 -?"                0   out  ""                                  "$NOPROJ" $CD  -D2 '-?'
77
check "PTD -D2 -?"               0   out  ""                                  "$NOPROJ" $PTD -D2 '-?'
78
check "RD -D2 -?"                0   out  ""                                  "$NOPROJ" $RD  -D2 '-?'
79
check "CD no args"               255 err  ""                                  "$NOPROJ" $CD
80
check "PTD no args"              255 err  ""                                  "$NOPROJ" $PTD
81
check "CD options only"          252 err  "Missing mode parameter."           "$NOPROJ" $CD  -D2
82
check "PTD options only"         252 err  "Missing mode parameter."           "$NOPROJ" $PTD -D2
83
check "CD no config"             249 err  "Unable to load the project configuration" "$NOPROJ" $CD  F2 x.p
84
check "PTD no config"            249 err  "Unable to load the project configuration" "$NOPROJ" $PTD F2 x.p
85
check "RD no args, no config"    248 err  "Unable to load the project configuration" "$NOPROJ" $RD
86
check "RD -D2, no config"        248 err  "Unable to load the project configuration" "$NOPROJ" $RD  -D2
87

    
88
# 2. cfg/ directory without p2j.cfg.xml
89
NOCFG="$WORK/nocfg"
90
mkdir -p "$NOCFG/cfg"
91
echo "--- cfg/ without p2j.cfg.xml ($NOCFG)"
92
check "CD missing p2j.cfg.xml"   249 err  "No data file found"                "$NOCFG"  $CD  F2 x.p
93
check "RD missing p2j.cfg.xml"   248 err  "No data file found"                "$NOCFG"  $RD
94

    
95
# 3. real project (regression)
96
if [ -f "$PROJ/cfg/p2j.cfg.xml" ]; then
97
   echo "--- real project ($PROJ)"
98
   check "CD -? with config"     0   out  ""                                  "$PROJ"   $CD  '-?'
99
   check "CD dry run (-SL F0)"   0   none ""                                  "$PROJ"   $CD  -SL F0 abl "*.p"
100
   check "CD bad mode"           251 err  "Unrecognized mode 'XX'."           "$PROJ"   $CD  XX abl/some.p
101
else
102
   echo "--- skipping real project checks, no $PROJ/cfg/p2j.cfg.xml"
103
fi
104

    
105
echo
106
echo "passed: $PASS  failed: $FAIL"
107
[ "$FAIL" -eq 0 ]