Skip to content

Commit

Permalink
Added script to list tests in a json file with specified result status
Browse files Browse the repository at this point in the history
  • Loading branch information
wspear committed Jun 15, 2023
1 parent 9f486ba commit 90abf91
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions process-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

# Function to print script usage
print_usage() {
echo "Usage: $0 [options] <json_file> [key (setup, clean, compile, run{default})] [value (pass{default}, fail, missing)]"
echo "Options:"
echo " -l Print output on a single line"
echo " -h Print this help message"
}

# Function to parse JSON and extract the test values
parse_json() {
local json_file="$1"
local print_on_single_line="$2"
local key="$3"
local value="$4"

# Read the JSON file
local json_data=$(cat "$json_file")

# Check if -l option is passed
local output_separator=$'\n'
if [[ "$print_on_single_line" == "-l" ]]; then
output_separator=" "
fi

# Extract relevant entries and filter them
local filtered_entries=$(echo "$json_data" | jq -c --arg key "$key" --arg value "$value" '.[] | select(.test_stages[$key] == $value and .test != null)')

# Loop through each filtered entry and print the directory path
while IFS= read -r entry; do
local test_value=$(echo "$entry" | jq -r '.test')
local directory_path=$(basename "$test_value")
echo -n "$directory_path$output_separator"
done <<< "$filtered_entries"

echo # Print a new line after the output
}

# Check if -h option is passed
if [[ "$1" == "-h" ]]; then
print_usage
exit 0
fi

# Check if a JSON file argument is provided
if [[ -z "$1" ]]; then
print_usage
exit 1
fi

# Check if -l option is passed
if [[ "$1" == "-l" ]]; then
if [[ -n "$2" ]]; then
parse_json "$2" "-l" "${3:-run}" "${4:-pass}"
else
print_usage
exit 1
fi
else
if [[ -n "$1" ]]; then
parse_json "$1" "" "${2:-run}" "${3:-pass}"
else
print_usage
exit 1
fi
fi

0 comments on commit 90abf91

Please sign in to comment.