File: spreadJ

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (119 lines) | stat: -rwxr-xr-x 2,682 bytes parent folder | download | duplicates (2)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash

show_help() {
    echo "usage: spreadJ rerun [--suite SUITE] <RESULTS-PATH>"
    echo "       spreadJ show [--suite SUITE] <TARGET> <RESULTS-PATH>"
    echo "       spreadJ stats [--suite SUITE] <RESULTS-PATH>"
    echo "       spreadJ list [--suite SUITE] <TARGET> <RESULTS-PATH>"
    echo ""
    echo "Available options:"
    echo "  -h --help   show this help message."
    echo ""
    echo "TARGET:"
    echo "  all,failed,passed,aborted"
    echo ""
    echo "Tool used to help with functions that are not already implemented in spread"
}

_filter_suite() {
    local suite="$1"
    if [ -z "$suite" ]; then
        echo ".testsuites[]"
    else
        echo ".testsuites[] | select(.name == \"$suite\")"
    fi
}

rerun() {
    local suite=""
    if [ "$1" == "--suite" ]; then
        suite="$2"
        shift 2
    fi
    local res_path="$1"
    if [ ! -e "$res_path" ]; then
        echo "spreadJ: results path not found: $res_path"
        exit 1
    fi

    local query
    query="$(_filter_suite $suite).tests[] | select((.result == \"failed\") or (.result == \"aborted\")).name"
    jq -r "$query" "$res_path"
}

stats() {
    local suite=""
    if [ "$1" == "--suite" ]; then
        suite="$2"
        shift 2
    fi
    local res_path="$1"

    if [ ! -e "$res_path" ]; then
        echo "spreadJ: results path not found: $res_path"
        exit 1
    fi

    local query
    if [ -z "$suite" ]; then
        query="del(.testsuites)"
    else
        query="$(_filter_suite $suite) | del(.tests) | del(.name)"
    fi
    jq -r "$query" "$res_path"
}

list() {
    local suite=""
    if [ "$1" == "--suite" ]; then
        suite="$2"
        shift 2
    fi
    local target="$1"
    local res_path="$2"

    if [ ! -e "$res_path" ]; then
        echo "spreadJ: results path not found: $res_path"
        exit 1
    fi

    if [ -z "$target" ]; then
        echo "spreadJ: result target cannot be empty"
        exit 1  
    fi

    local query
    if [ "$target" == "all" ]; then
        query="$(_filter_suite $suite).tests[]).name"
    else
        query="$(_filter_suite $suite).tests[] | select((.result == \"$target\")).name"
    fi
    jq -r "$query" "$res_path"
}

main() {
    if [ $# -eq 0 ]; then
        show_help
        exit 0
    fi

    local subcommand="$1"
    local action=
    if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
        show_help
        exit 0
    else
        action=$(echo "$subcommand" | tr '-' '_')
        shift
    fi

    if [ -z "$(declare -f "$action")" ]; then
        echo "spreadJ: no such command: $subcommand" >&2
        show_help
        exit 1
    fi
    
    "$action" "$@"
}

main "$@"