help.sh (7106B)
1 #!/bin/sh 2 3 audit_help_commands='cc check build-exe build-lib build-obj build install cpp as ld ar cpio ranlib strip objcopy image objdump run dbg nm size addr2line symbolize strings cas pkg xxd cmp hash sha256sum b2sum crc32 compress gzip gunzip lz4 lz4c disas mc gram update' 4 5 audit_help_safe_name() { 6 printf '%s' "$1" | tr '-' '_' 7 } 8 9 audit_help_noargs_kind() { 10 case "$1" in 11 gram) printf '%s\n' usage2 ;; 12 dbg) printf '%s\n' repl0 ;; 13 strings|xxd|hash|sha256sum|b2sum|crc32|compress|gzip|lz4|lz4c) printf '%s\n' stdin0 ;; 14 gunzip) printf '%s\n' stdin1 ;; 15 disas|mc) printf '%s\n' help2 ;; 16 update) printf '%s\n' operation ;; 17 *) printf '%s\n' help0 ;; 18 esac 19 } 20 21 audit_help_severity() { 22 case "$1" in 23 cc|build|build-exe|build-lib|build-obj|cas|pkg|dbg|gram|update) printf '%s\n' p1 ;; 24 *) printf '%s\n' p2 ;; 25 esac 26 } 27 28 audit_help_run_noargs() { 29 audit_help_cmd=$1 30 audit_help_safe=$2 31 audit_help_kind=$(audit_help_noargs_kind "$audit_help_cmd") 32 audit_help_sev=$(audit_help_severity "$audit_help_cmd") 33 34 if ! audit_case_start "help.$audit_help_safe.noargs" help "$audit_help_cmd" help all all all "$audit_help_sev"; then 35 return 36 fi 37 38 if [ "$audit_help_cmd" = update ] && [ -n "$HARNESS_DIST" ]; then 39 audit_help_update_dist=$CASE_DIR/install/update-dist 40 if cp -R "$HARNESS_DIST" "$audit_help_update_dist" \ 41 > "$CASE_DIR/setup.stdout" 2> "$CASE_DIR/setup.stderr"; then 42 audit_case_exec "$audit_help_update_dist/bin/kit" update 43 else 44 audit_case_blocked "could not create isolated distribution copy for update" 45 return 46 fi 47 elif [ "$audit_help_cmd" = update ]; then 48 audit_case_blocked "update no-argument audit requires --dist for an isolated distribution copy" 49 return 50 else 51 audit_case_exec_kit "$audit_help_cmd" 52 fi 53 54 case "$audit_help_kind" in 55 help0) 56 audit_expect_exit 0 57 audit_expect_stdout_regex '^USAGE$' 58 audit_expect_stderr_empty 59 ;; 60 usage2) 61 audit_expect_exit 2 62 audit_expect_stderr_nonempty 63 ;; 64 repl0) 65 audit_expect_exit 0 66 audit_expect_stdout_nonempty 67 ;; 68 stdin0) 69 audit_expect_exit 0 70 ;; 71 stdin1) 72 audit_expect_exit 1 73 audit_expect_stderr_nonempty 74 ;; 75 help2) 76 audit_expect_exit 2 77 audit_expect_stdout_regex '^USAGE$' 78 ;; 79 operation) 80 audit_expect_exit_one_of 0,1 81 ;; 82 esac 83 audit_case_finish 84 } 85 86 audit_help_run_long() { 87 audit_help_cmd=$1 88 audit_help_safe=$2 89 audit_help_sev=$(audit_help_severity "$audit_help_cmd") 90 if ! audit_case_start "help.$audit_help_safe.long" help "$audit_help_cmd" help all all all "$audit_help_sev"; then 91 return 92 fi 93 audit_case_exec_kit "$audit_help_cmd" --help 94 audit_expect_exit 0 95 audit_expect_stdout_regex '^USAGE$' 96 audit_expect_stderr_empty 97 audit_expect_stdout_regex '^EXAMPLES?$' 98 audit_expect_stdout_regex '^EXIT CODES?$' 99 if [ "$audit_help_cmd" = cc ]; then 100 audit_reject_stdout_regex '[Ss]ee source|[Ss]ee the source' 101 fi 102 audit_case_finish 103 } 104 105 audit_help_run_short() { 106 audit_help_cmd=$1 107 audit_help_safe=$2 108 audit_help_sev=$(audit_help_severity "$audit_help_cmd") 109 if ! audit_case_start "help.$audit_help_safe.short" help "$audit_help_cmd" help all all all "$audit_help_sev"; then 110 return 111 fi 112 audit_case_exec_kit "$audit_help_cmd" -h 113 if [ "$audit_help_cmd" = objdump ]; then 114 audit_expect_exit 2 115 audit_expect_stderr_nonempty 116 else 117 audit_expect_exit 0 118 audit_expect_stderr_empty 119 audit_expect_stdout_equals_file "$HARNESS_RUN_DIR/cases/help.$audit_help_safe.long/stdout" 120 fi 121 audit_case_finish 122 } 123 124 audit_help_run_routed() { 125 audit_help_cmd=$1 126 audit_help_safe=$2 127 audit_help_sev=$(audit_help_severity "$audit_help_cmd") 128 if ! audit_case_start "help.$audit_help_safe.routed" help "$audit_help_cmd" help all all all "$audit_help_sev"; then 129 return 130 fi 131 audit_case_exec_kit help "$audit_help_cmd" 132 audit_expect_exit 0 133 audit_expect_stderr_empty 134 audit_expect_stdout_equals_file "$HARNESS_RUN_DIR/cases/help.$audit_help_safe.long/stdout" 135 audit_case_finish 136 } 137 138 audit_help_top() { 139 if audit_case_start help.top.long help kit inventory all all all p2; then 140 audit_case_exec_kit --help 141 audit_expect_exit 0 142 audit_expect_stdout_regex '^USAGE$' 143 audit_expect_stdout_regex '^TOOLS$' 144 audit_expect_stderr_empty 145 for audit_help_inventory_cmd in $audit_help_commands; do 146 audit_expect_stdout_regex "^ $audit_help_inventory_cmd[[:space:]]" 147 done 148 audit_reject_stdout_regex 'no args.*show help' 149 audit_case_finish 150 fi 151 152 for audit_help_top_variant in noargs short routed; do 153 if audit_case_start "help.top.$audit_help_top_variant" help kit inventory all all all p2; then 154 case "$audit_help_top_variant" in 155 noargs) audit_case_exec_kit ;; 156 short) audit_case_exec_kit -h ;; 157 routed) audit_case_exec_kit help ;; 158 esac 159 audit_expect_exit 0 160 audit_expect_stderr_empty 161 audit_expect_stdout_equals_file "$HARNESS_RUN_DIR/cases/help.top.long/stdout" 162 audit_case_finish 163 fi 164 done 165 } 166 167 audit_help_targets() { 168 if audit_case_start help.targets.long help targets inventory all all all p1; then 169 audit_case_exec_kit targets --help 170 audit_expect_exit 0 171 audit_expect_stdout_nonempty 172 audit_expect_stderr_empty 173 audit_case_finish 174 fi 175 if audit_case_start help.targets.noargs help targets inventory all all all p1; then 176 audit_case_exec_kit targets 177 audit_expect_exit 0 178 audit_expect_stdout_nonempty 179 audit_expect_stderr_empty 180 audit_case_finish 181 fi 182 if audit_case_start help.targets.short help targets inventory all all all p1; then 183 audit_case_exec_kit targets -h 184 audit_expect_exit 0 185 audit_expect_stdout_nonempty 186 audit_expect_stderr_empty 187 audit_case_finish 188 fi 189 if audit_case_start help.targets.routed help targets inventory all all all p1; then 190 audit_case_exec_kit help targets 191 audit_expect_exit 0 192 audit_expect_stdout_nonempty 193 audit_expect_stderr_empty 194 audit_case_finish 195 fi 196 } 197 198 audit_module_help() { 199 audit_help_top 200 audit_help_targets 201 for audit_help_cmd in $audit_help_commands; do 202 audit_help_safe=$(audit_help_safe_name "$audit_help_cmd") 203 audit_help_run_noargs "$audit_help_cmd" "$audit_help_safe" 204 audit_help_run_long "$audit_help_cmd" "$audit_help_safe" 205 audit_help_run_short "$audit_help_cmd" "$audit_help_safe" 206 audit_help_run_routed "$audit_help_cmd" "$audit_help_safe" 207 done 208 }