Browse Source

Make use of multi-line logging in latest jat.sh

Alois Mahdal 6 years ago
parent
commit
4f11d8f587
1 changed files with 57 additions and 46 deletions
  1. 57
    46
      src/xcase.sh.skel

+ 57
- 46
src/xcase.sh.skel View File

603
     # Enumerate and validate cases
603
     # Enumerate and validate cases
604
     #
604
     #
605
     local id    # each case id
605
     local id    # each case id
606
+    local lines=()  # output lines
606
     __xcase__has enum || {
607
     __xcase__has enum || {
607
         jat__log_error "case ID enumerator handler not implemented: xcase__enum"
608
         jat__log_error "case ID enumerator handler not implemented: xcase__enum"
608
         return 3
609
         return 3
609
     }
610
     }
610
     xcase__enum > "$__xcase__tmp/enum"
611
     xcase__enum > "$__xcase__tmp/enum"
611
     __xcase__ttl=$(wc -l <"$__xcase__tmp/enum")
612
     __xcase__ttl=$(wc -l <"$__xcase__tmp/enum")
612
-    jat__log_info "enumerated $__xcase__ttl cases:"
613
-    jat__log_info ""
613
+    lines+=("enumerated $__xcase__ttl cases:")
614
+    lines+=("")
614
     while IFS= read -r id;
615
     while IFS= read -r id;
615
     do
616
     do
616
-        jat__log_info "    $id"
617
+        lines+=("    $id")
617
     done <"$__xcase__tmp/enum"
618
     done <"$__xcase__tmp/enum"
618
-    jat__log_info ""
619
+    lines+=("")
620
+    jat__log_info "${lines[@]}"
619
     __xcase__validate_enum || return $?
621
     __xcase__validate_enum || return $?
620
     test "$__xcase__ttl" -eq 0 && {
622
     test "$__xcase__ttl" -eq 0 && {
621
         jat__log_error "no cases enumerated, nothing to do"
623
         jat__log_error "no cases enumerated, nothing to do"
682
 
684
 
683
         ((__xcase__n++))
685
         ((__xcase__n++))
684
 
686
 
685
-        jat__log_info "  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
686
-        jat__log_info " /"
687
-        jat__log_info "o   $__xcase__n/$__xcase__ttl: $__xcase__id"
688
-        jat__log_info " \\"
689
-        jat__log_info '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
687
+        jat__log_info \
688
+             "  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" \
689
+             " /" \
690
+             "o   $__xcase__n/$__xcase__ttl: $__xcase__id" \
691
+             " \\" \
692
+             '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
690
         echo >&2
693
         echo >&2
691
 
694
 
692
         __xcase__varcode=$(__xcase__mkvarcode) || {
695
         __xcase__varcode=$(__xcase__mkvarcode) || {
812
     #
815
     #
813
     # Provide note about file uploads (if applicable)
816
     # Provide note about file uploads (if applicable)
814
     #
817
     #
818
+    local items     # of filename list
815
     local item      # of filename list
819
     local item      # of filename list
820
+    local lines=()  # output lines
816
     $__xcase__rball     || return 0
821
     $__xcase__rball     || return 0
817
     __xcase__nonempty . || return 0
822
     __xcase__nonempty . || return 0
818
-    jat__log_info "Items to be auto-collected to xcase-relics.tar.gz:"
823
+    items=$(__xcase__tmpfile "C.relist")
824
+    lines+=("Items to be auto-collected to xcase-relics.tar.gz:")
819
     find . -mindepth 1 -maxdepth 1 -printf "%P\\n" \
825
     find . -mindepth 1 -maxdepth 1 -printf "%P\\n" \
820
-      | sort \
821
-      | while read -r item;
822
-        do
823
-            jat__log_info " *  $item"
824
-        done
826
+      | sort >"$items"
827
+    while read -r item;
828
+    do
829
+        lines+=(" *  $item")
830
+    done <"$items"
831
+    jat__log_info "${lines[@]}"
825
     echo >&2
832
     echo >&2
826
 }
833
 }
827
 
834
 
934
     #
941
     #
935
     # Show summary phase
942
     # Show summary phase
936
     #
943
     #
937
-    local logfunc       # log function for a row
938
     local id            # case id
944
     local id            # case id
939
     local r_setup       # handler result: setup
945
     local r_setup       # handler result: setup
940
     local r_test        #              ^^ test
946
     local r_test        #              ^^ test
942
     local r_cleanup     #              ^^ cleanup
948
     local r_cleanup     #              ^^ cleanup
943
     local hdata         # path to cached handler data
949
     local hdata         # path to cached handler data
944
     local num=0         # row number
950
     local num=0         # row number
951
+    local lines=()      # output lines
945
     jat__pstartd "xcase summary"
952
     jat__pstartd "xcase summary"
946
-        jat__log_info "duration: $(__xcase__tstats)"
947
-        jat__log_info ""
948
-        jat__log_info "============================================="
949
-        jat__log_info "setup   test    diag    cleanup | case id";
950
-        jat__log_info "--------------------------------|------------"
953
+        lines+=(
954
+            "duration: $(__xcase__tstats)"
955
+            ""
956
+            "============================================="
957
+            "setup   test    diag    cleanup | case id"
958
+            "--------------------------------|------------"
959
+        )
951
         for id in $(<"$__xcase__tmp/enum");
960
         for id in $(<"$__xcase__tmp/enum");
952
         do
961
         do
953
             ((num++))
962
             ((num++))
956
             r_test=$(<"$hdata/test/result")
965
             r_test=$(<"$hdata/test/result")
957
             r_diag=$(<"$hdata/diag/result")
966
             r_diag=$(<"$hdata/diag/result")
958
             r_cleanup=$(<"$hdata/cleanup/result")
967
             r_cleanup=$(<"$hdata/cleanup/result")
959
-            case $r_setup:$r_test:$r_diag:$r_cleanup in
960
-                # internal error or cleanup fail: severe issue
961
-                *axerr*)    logfunc=jat__log_error ;;
962
-                *:fail)     logfunc=jat__log_error ;;
963
-                # else: ok
964
-                *)          logfunc=jat__log_info ;;
965
-            esac
966
-            $logfunc "$(
968
+            lines+=("$(
967
                 __xcase__sumrow \
969
                 __xcase__sumrow \
968
                     "$r_setup" "$r_test" "$r_diag" "$r_cleanup" \
970
                     "$r_setup" "$r_test" "$r_diag" "$r_cleanup" \
969
                     "$num" "$(wc -l < "$__xcase__tmp/enum")" \
971
                     "$num" "$(wc -l < "$__xcase__tmp/enum")" \
970
                     "$id"
972
                     "$id"
971
-            )"
973
+            )")
972
         done
974
         done
973
-        jat__log_info "============================================="
975
+        lines+=("=============================================")
976
+        jat__log_info "${lines[@]}"
974
         __xcase__stats
977
         __xcase__stats
975
         jat__log_info ""
978
         jat__log_info ""
976
     jat__pend
979
     jat__pend
1087
     local tests     # tests       ^^
1090
     local tests     # tests       ^^
1088
     local diags     # diags       ^^
1091
     local diags     # diags       ^^
1089
     local cleanups  # cleanups    ^^
1092
     local cleanups  # cleanups    ^^
1093
+    local lines=()  # output lines
1090
     results=$(find "$__xcase__tmp/data/id/" -path "*/handler/*/result" -exec grep -H . {} +)
1094
     results=$(find "$__xcase__tmp/data/id/" -path "*/handler/*/result" -exec grep -H . {} +)
1091
     for result in pass fail abort axerr;
1095
     for result in pass fail abort axerr;
1092
     do
1096
     do
1095
         diags=$(grep -c "diag/result:$result$" <<<"$results")
1099
         diags=$(grep -c "diag/result:$result$" <<<"$results")
1096
         cleanups=$(grep -c "cleanup/result:$result$" <<<"$results")
1100
         cleanups=$(grep -c "cleanup/result:$result$" <<<"$results")
1097
         test "$((setups + tests + diags + cleanups))" -eq 0 && continue
1101
         test "$((setups + tests + diags + cleanups))" -eq 0 && continue
1098
-        jat__log_info "$(printf '%-8s%-8s%-8s%-8s| x %s\n' "$setups" "$tests" "$diags" "$cleanups" $result)"
1102
+        lines+=("$(printf '%-8s%-8s%-8s%-8s| x %s\n' "$setups" "$tests" "$diags" "$cleanups" $result)")
1099
     done
1103
     done
1104
+    jat__log_info "${lines[@]}"
1100
 }
1105
 }
1101
 
1106
 
1102
 __xcase__results() {
1107
 __xcase__results() {
1135
     #
1140
     #
1136
     local allowed='[:alnum:]._,+%=-'    # allowed chars in case id
1141
     local allowed='[:alnum:]._,+%=-'    # allowed chars in case id
1137
     local es=                           # exit status of this function
1142
     local es=                           # exit status of this function
1143
+    local lines=()                      # error message lines
1138
     if grep "[^$allowed]" "$__xcase__tmp/enum";
1144
     if grep "[^$allowed]" "$__xcase__tmp/enum";
1139
     then
1145
     then
1140
         if $__xcase__leaves || $__xcase__vars;
1146
         if $__xcase__leaves || $__xcase__vars;
1141
         then
1147
         then
1142
-            jat__log_error "Sorry, when leaf directory mode (default) or variable"
1143
-            jat__log_error "setting mode is used, range of characters that"
1144
-            jat__log_error "xcase__enum() can emit is limited to:"
1145
-            jat__log_error ""
1146
-            jat__log_error "    $allowed"
1147
-            jat__log_error ""
1148
-            jat__log_error "This is to enable usage of this data as file, directory"
1149
-            jat__log_error "and variable names.  To disable these modes, use flags"
1150
-            jat__log_error "-L and -V, respectively."
1151
-            jat__log_error "illegal characters in enumerator"
1148
+            lines+=(
1149
+                "Sorry, when leaf directory mode (default) or variable"
1150
+                "setting mode is used, range of characters that"
1151
+                "xcase__enum() can emit is limited to:"
1152
+                ""
1153
+                "    $allowed"
1154
+                ""
1155
+                "This is to enable usage of this data as file, directory"
1156
+                "and variable names.  To disable these modes, use flags"
1157
+                "-L and -V, respectively."
1158
+                "illegal characters in enumerator"
1159
+            )
1152
             es=2
1160
             es=2
1153
         else
1161
         else
1154
-            jat__log_error "DEPRECATED characters in enumerator, future version will only allow: $allowed"
1162
+            lines+=("DEPRECATED characters in enumerator, future version will only allow: $allowed")
1155
             es=0
1163
             es=0
1156
         fi
1164
         fi
1157
-        jat__log_error "Note that in order to make best use of xcase, the case id"
1158
-        jat__log_error "should not hold any 'real' testing data but rather just"
1159
-        jat__log_error "simple generic words to hint *intent* of the test case."
1165
+        lines+=(
1166
+            "Note that in order to make best use of xcase, the case id"
1167
+             "should not hold any 'real' testing data but rather just"
1168
+             "simple generic words to hint *intent* of the test case."
1169
+         )
1170
+         jat__log_error "${lines[@]}"
1160
     fi
1171
     fi
1161
     return $es
1172
     return $es
1162
 }
1173
 }