一、脚本说明
1. 应用场景
身为QA的女友,有一堆自动化的测试用例跑,随着自动化case的增加,导致每次回归测试过程时间过长。
有些时候上线功能只是修改了某些业务逻辑,仅仅只需要执行一部分case即可。
因此,需要从一堆现有case里选取若干文件即可。
2. 脚本内容
脚本主要分为二部分内容:文件遍历和文件选择。
文件遍历:将指定路径下特定后缀的case选取出来,存入到数组files中,并以序号、数组内容格式输出。
文件选择:等待用户输入序号(多个使用空格隔开),然后根据用户输入的多个序号从数组files中选取对应的文件即可。
二、选取脚本
1. 脚本源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #!/bin/bash
BASE_PATH=/Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article FEATURE='*.md'
if [[ $# -ge 1 && $1 != '-' ]] then BASE_PATH=$1 fi
if [[ $# -ge 2 && $2 != '-' ]] then FEATURE=$2 fi
echo "BASE_PATH: $BASE_PATH" echo "FEATURE: $FEATURE"
declare -a files
function file_traverse { echo "-----------------------------------------" IFS=$'\n'
files=($(find $BASE_PATH -name "$FEATURE")) for str in ${!files[@]} do echo -e "$str\t${files[$str]}" done }
function choose_file { echo "-----------------------------------------" read -p "请通过序号选择文件:" ids echo "你选择的序号为:${ids[@]}"
IFS=$' \t' for id in ${ids[@]} do if [ $id -lt ${#files[@]} ] then echo "文件: "${files[$id]} fi done }
file_traverse choose_file
|
2. 脚本输出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| yerba-buena:shell yeshaoting$ sh print_blog_file.sh /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/ BASE_PATH: /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/ FEATURE: *.md yerba-buena:shell yeshaoting$ sh print_blog_file.sh /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/ BASE_PATH: /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/ FEATURE: *.md ----------------------------------------- 0 /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/shell关联数组基本用法.md 1 /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/了解IFS.md 2 /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/遍历博客文章.md ----------------------------------------- 请通过序号选择文件:2 0 你选择的序号为:2 0 文件: /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/遍历博客文章.md 文件: /Users/yeshaoting/java/workspace/github/hexo-blog/source/_posts/article/shell/shell关联数组基本用法.md
|