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,19 +603,21 @@ __xcase__plan() {
603 603
     # Enumerate and validate cases
604 604
     #
605 605
     local id    # each case id
606
+    local lines=()  # output lines
606 607
     __xcase__has enum || {
607 608
         jat__log_error "case ID enumerator handler not implemented: xcase__enum"
608 609
         return 3
609 610
     }
610 611
     xcase__enum > "$__xcase__tmp/enum"
611 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 615
     while IFS= read -r id;
615 616
     do
616
-        jat__log_info "    $id"
617
+        lines+=("    $id")
617 618
     done <"$__xcase__tmp/enum"
618
-    jat__log_info ""
619
+    lines+=("")
620
+    jat__log_info "${lines[@]}"
619 621
     __xcase__validate_enum || return $?
620 622
     test "$__xcase__ttl" -eq 0 && {
621 623
         jat__log_error "no cases enumerated, nothing to do"
@@ -682,11 +684,12 @@ __xcase__run_all() {
682 684
 
683 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 693
         echo >&2
691 694
 
692 695
         __xcase__varcode=$(__xcase__mkvarcode) || {
@@ -812,16 +815,20 @@ __xcase__upload_note() {
812 815
     #
813 816
     # Provide note about file uploads (if applicable)
814 817
     #
818
+    local items     # of filename list
815 819
     local item      # of filename list
820
+    local lines=()  # output lines
816 821
     $__xcase__rball     || return 0
817 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 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 832
     echo >&2
826 833
 }
827 834
 
@@ -934,7 +941,6 @@ __xcase__summary() {
934 941
     #
935 942
     # Show summary phase
936 943
     #
937
-    local logfunc       # log function for a row
938 944
     local id            # case id
939 945
     local r_setup       # handler result: setup
940 946
     local r_test        #              ^^ test
@@ -942,12 +948,15 @@ __xcase__summary() {
942 948
     local r_cleanup     #              ^^ cleanup
943 949
     local hdata         # path to cached handler data
944 950
     local num=0         # row number
951
+    local lines=()      # output lines
945 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 960
         for id in $(<"$__xcase__tmp/enum");
952 961
         do
953 962
             ((num++))
@@ -956,21 +965,15 @@ __xcase__summary() {
956 965
             r_test=$(<"$hdata/test/result")
957 966
             r_diag=$(<"$hdata/diag/result")
958 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 969
                 __xcase__sumrow \
968 970
                     "$r_setup" "$r_test" "$r_diag" "$r_cleanup" \
969 971
                     "$num" "$(wc -l < "$__xcase__tmp/enum")" \
970 972
                     "$id"
971
-            )"
973
+            )")
972 974
         done
973
-        jat__log_info "============================================="
975
+        lines+=("=============================================")
976
+        jat__log_info "${lines[@]}"
974 977
         __xcase__stats
975 978
         jat__log_info ""
976 979
     jat__pend
@@ -1087,6 +1090,7 @@ __xcase__stats() {
1087 1090
     local tests     # tests       ^^
1088 1091
     local diags     # diags       ^^
1089 1092
     local cleanups  # cleanups    ^^
1093
+    local lines=()  # output lines
1090 1094
     results=$(find "$__xcase__tmp/data/id/" -path "*/handler/*/result" -exec grep -H . {} +)
1091 1095
     for result in pass fail abort axerr;
1092 1096
     do
@@ -1095,8 +1099,9 @@ __xcase__stats() {
1095 1099
         diags=$(grep -c "diag/result:$result$" <<<"$results")
1096 1100
         cleanups=$(grep -c "cleanup/result:$result$" <<<"$results")
1097 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 1103
     done
1104
+    jat__log_info "${lines[@]}"
1100 1105
 }
1101 1106
 
1102 1107
 __xcase__results() {
@@ -1135,28 +1140,34 @@ __xcase__validate_enum() {
1135 1140
     #
1136 1141
     local allowed='[:alnum:]._,+%=-'    # allowed chars in case id
1137 1142
     local es=                           # exit status of this function
1143
+    local lines=()                      # error message lines
1138 1144
     if grep "[^$allowed]" "$__xcase__tmp/enum";
1139 1145
     then
1140 1146
         if $__xcase__leaves || $__xcase__vars;
1141 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 1160
             es=2
1153 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 1163
             es=0
1156 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 1171
     fi
1161 1172
     return $es
1162 1173
 }