]> Sergey Matveev's repositories - bfs.git/blobdiff - tests/getopts.sh
tests: Run test cases in parallel
[bfs.git] / tests / getopts.sh
index 7d3ef4b056c189f1bc1301726878e6f65b829548..d34df4f8bbc7138f3d7cce1896b0d19b171dc790 100644 (file)
@@ -52,6 +52,7 @@ EOF
 
 # Parse the command line
 parse_args() {
+    JOBS=0
     PATTERNS=()
     SUDO=()
     STOP=0
@@ -64,6 +65,9 @@ parse_args() {
 
     for arg; do
         case "$arg" in
+            -j*)
+                JOBS="${arg#-j}"
+                ;;
             --bfs=*)
                 BFS="${arg#*=}"
                 ;;
@@ -127,6 +131,14 @@ parse_args() {
         esac
     done
 
+    if ((JOBS == 0)); then
+        if command -v nproc &>/dev/null; then
+            JOBS=$(nproc)
+        else
+            JOBS=1
+        fi
+    fi
+
     # Try to resolve the path to $BFS before we cd, while also supporting
     # --bfs="./bin/bfs -S ids"
     read -a BFS <<<"${BFS:-$BIN/bfs}"