Browse Source

Fix and improve mftest

Scott Lahteine 5 years ago
parent
commit
d4c210f21b
1 changed files with 36 additions and 16 deletions
  1. 36
    16
      buildroot/share/git/mftest

+ 36
- 16
buildroot/share/git/mftest View File

@@ -14,8 +14,10 @@ TESTPATH=buildroot/share/tests
14 14
 
15 15
 shopt -s extglob nocasematch
16 16
 
17
-# Get test, allowing shorthand
18
-TESTENV=${1:-"mega"}
17
+# Get test
18
+TESTENV=${1:-'-'}
19
+
20
+# Allow shorthand for test name
19 21
 case $TESTENV in
20 22
      due) TESTENV='DUE' ;;
21 23
      esp) TESTENV='esp32' ;;
@@ -26,6 +28,7 @@ case $TESTENV in
26 28
      stm) TESTENV='STM32F1' ;;
27 29
      t35) TESTENV='teensy35' ;;
28 30
   teensy) TESTENV='teensy35' ;;
31
+       -) ;;
29 32
 esac
30 33
 
31 34
 # Matching patterns
@@ -34,7 +37,7 @@ ISCMD='^(restore|opt|exec|use|pins|env)_'
34 37
 ISEXEC='^exec_'
35 38
 
36 39
 # List available tests and ask for selection
37
-if [[ $1 == '-' ]]; then
40
+if [[ $TESTENV == '-' ]]; then
38 41
   IND=0
39 42
   NAMES=()
40 43
   for FILE in $( ls -1 $TESTPATH/*-tests )
@@ -43,6 +46,7 @@ if [[ $1 == '-' ]]; then
43 46
     TNAME=${FILE/-tests/}
44 47
     TNAME=${TNAME/$TESTPATH\//}
45 48
     NAMES+=($TNAME)
49
+    (( IND < 10 )) && echo -n " "
46 50
     echo " $IND) $TNAME"
47 51
   done
48 52
 
@@ -50,8 +54,8 @@ if [[ $1 == '-' ]]; then
50 54
   for (( ; ; ))
51 55
   do
52 56
     read -p "Select a test to apply (1-$IND) : " NAMEIND
53
-    [[ -z "$NAMEIND" ]] && { echo "Quitting." ; exit 1 ; }
54
-    [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; break ; }
57
+    [[ -z "$NAMEIND" ]] && { echo '(canceled)' ; exit 1 ; }
58
+    [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
55 59
     echo "Invalid selection."
56 60
   done
57 61
 fi
@@ -66,17 +70,33 @@ TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
66 70
 # Get the entered or interactive test index
67 71
 CHOICE=${2:-0}
68 72
 
69
-if [[ $TESTCOUNT > 1 && ( $CHOICE == 0 || $1 == '-' ) ]]; then
70
-  for (( ; ; ))
71
-  do
72
-    read -p "Test '$TESTENV' index (1-$TESTCOUNT) : " CHOICE
73
-    [[ -z "$CHOICE" ]] && CHOICE=1
74
-    [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
75
-    echo "Invalid test index '$CHOICE'."
76
-  done
77
-else
78
-  # Confirm a manually-entered test index
79
-  ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) || { echo "Invalid test index '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
73
+# User entered a number?
74
+(( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test index '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
75
+
76
+if [[ $CHOICE == 0 ]]; then
77
+  # List test descriptions with numbers
78
+  echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
79
+    IND=0
80
+    SED=$(which gsed || which sed)
81
+    while IFS= read -r LINE
82
+    do
83
+      if [[ $LINE =~ $ISEXEC ]]; then
84
+        DESC=$( "$SED" -E 's/^.+"(.*)".*$/\1/g' <<<"$LINE" )
85
+        (( ++IND < 10 )) && echo -n " "
86
+        echo " $IND) $DESC"
87
+      fi
88
+    done
89
+  }
90
+  CHOICE=1
91
+  if [[ $TESTCOUNT > 1 ]]; then
92
+    for (( ; ; ))
93
+    do
94
+      read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
95
+      [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
96
+      [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
97
+      echo ">>> Invalid test index '$CHOICE'."
98
+    done
99
+  fi
80 100
 fi
81 101
 
82 102
 # Finally, run the specified test lines

Loading…
Cancel
Save