summaryrefslogtreecommitdiff
path: root/check
blob: d41c9aee0b96cfbec6dfaa5f1cf2fc29170f021e (plain)
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
#!/bin/sh

set -eu

verbose=false
if [ "$#" -gt 0 ]
then
    case "$1" in
	verbose | -v | --verbose)
	    verbose=true
	    ;;
    esac
fi

hideok=
if command -v chronic > /dev/null
then
    hideok=chronic
fi
quiet=-q
if $verbose
then
    quiet=
    hideok=
fi

TOPDIR=$(pwd)

_codegen() {
    $hideok cargo run $quiet --package subplot --bin sp-codegen -- \
           "$1" --output "$2" --resources "${TOPDIR}/share"
}

codegen() {
    _codegen "$1" "$2"
    rm -f test.log
    template="$(sed -n '/^template: /s///p' "$1" | tail -n1)"
    case "$template" in
	python) $hideok python3 "$2" --log test.log ;;
	bash) $hideok bash "$2" ;;
	*) echo "Don't know interpreter for $2" ; exit 1 ;;
    esac
}

docgen() {
    cargo run $quiet --package subplot --bin sp-docgen -- "$1" --output "$2" --resources "${TOPDIR}/share"
}

# Run unit tests for the Python template.
(set -eu
 cd share/python/template
 for x in *_tests.py
 do
     $hideok echo "Unit tests: $x"
     $hideok python3 "$x"
     $hideok echo
 done)

if command -v flake8 > /dev/null
then
    $hideok flake8 share/python/template share/python/lib/*.py
fi

if command -v shellcheck > /dev/null
then
    shellcheck check ./*.sh
    find share/bash/template -name '*.sh' -exec shellcheck '{}' +
fi

$hideok cargo build --all-targets
if cargo --list | awk '{ print $1 }' | grep 'clippy$' > /dev/null
then
    cargo clippy $quiet
fi
$hideok cargo test $quiet

if command -v rustfmt > /dev/null
then
    cargo fmt --all -- --check
fi

if command -v black > /dev/null
then
    $hideok find . -type f -name '*.py' ! -name template.py ! -name test.py \
	    -exec black --check '{}' +
fi

(cd subplotlib;
    $hideok cargo test --lib
    for md in [!CR]*.md; do
        $hideok echo "subplotlib/$md ====================================="
        $hideok mkdir -p tests
        _codegen "$md" "tests/$(basename "$md" .md).rs" ""
        # This formatting is fine because we checked --all earlier
        # so all it'll do is tidy up the test suite
        cargo fmt
        docgen "$md" "$(basename "$md" .md).pdf"
        docgen "$md" "$(basename "$md" .md).html"
        $hideok cargo test --test "$(basename "$md" .md)"
        $hideok echo
    done
)

for md in [!CR]*.md share/python/lib/*.md
do
    $hideok echo "$md ====================================="
    codegen "$md" test.py
    docgen "$md" "$(basename "$md" .md).pdf"
    docgen "$md" "$(basename "$md" .md).html"
    $hideok echo
done

echo "Everything seems to be in order."