summaryrefslogtreecommitdiff
path: root/check
blob: a876e54a0adcaaf6c2fef6b73ee0304bc854ee07 (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
#!/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


codegen() {
    $hideok cargo run $quiet --bin sp-codegen -- "$1" --output "$2" --run \
          --templates "$(pwd)/templates"
}

docgen() {
    cargo run $quiet --bin sp-docgen -- "$1" --output "$2"
}

# Run unit tests for the Python template.
(set -eu
 cd templates/python
 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 templates/python --exclude=template.py
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
    find src -type f -name '*.rs' -exec rustfmt --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

for md in [^CR]*.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."