File: extract_test_examples.sh

package info (click to toggle)
openvdb 10.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,092 kB
  • sloc: cpp: 293,853; ansic: 2,268; python: 776; objc: 714; sh: 527; yacc: 382; lex: 348; makefile: 176
file content (92 lines) | stat: -rwxr-xr-x 3,380 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env bash
#################################################################################
# This script extracts all code blocks from AX documentation which are NOT      #
# marked as cpp/sh/unparsed and attempts to parse or compile them through the   #
# vdb_ax command line binary. Code blocks can be marked with a preceding        #
# notation to determine compilation mode:                                       #
#    <!--- P --->  = points                                                     #
#    <!--- V --->  = volumes                                                    #
#    <!--- A --->  = all                                                        #
# If not marked, code is only parsed (though ideally all code blocks should be  #
# compiled)                                                                     #
#################################################################################
set -e

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../"
VDB_AX=$ROOT/build/openvdb_cmd/vdb_ax/vdb_ax

DOCS=()
DOCS+=($ROOT/doc/ax/ax.txt)
DOCS+=($ROOT/doc/ax/axcplusplus.txt)
DOCS+=($ROOT/doc/ax/axexamples.txt)
# DOCS+=($ROOT/doc/ax/axfunctionlist.txt) do not test this file
DOCS+=($ROOT/doc/ax/doc.txt)

uncompiled=0

for DOC in "${DOCS[@]}"; do
    echo "Checking doxygen code in '$DOC...'"
    # Make sure the file exists
    if [ ! -f $DOC ]; then
        echo "Could not find '$DOC.'"
        exit -1
    fi

    # Extract all code segments from doxygen documentation in between @code and @endcode
    data=$(sed -n '/@code.* *$/,/^ *@endcode *$/p' $DOC)

    str=""
    compile=""
    skip=false
    count=0
    # For each extracted line, rebuild each code segment from @code and @endcode and
    # run it through a vdb_ax binary if necessary
    while IFS= read -r line; do
        # If the code is marked as unparsed, c++ or shell, skip
        if [[ "$line" == "@code{.unparsed}" ]]; then
            skip=true
        elif [[ "$line" == "@code{.cpp}" ]]; then
            skip=true
        elif [[ "$line" == "@code{.sh}" ]]; then
            skip=true
        elif [[ $line == @code* ]]; then
            str=""
            compile="none"
        elif [[ $line == "<!-- V -->@code"* ]]; then
            str=""
            compile="volumes"
        elif [[ $line == "<!-- P -->@code"* ]]; then
            str=""
            compile="points"
        elif [[ $line == "<!-- A -->@code"* ]]; then
            str=""
            compile=""
        elif [[ $line == @endcode ]]; then
            echo -e "\nTesting [$count]:"
            if [ "$skip" = true ]; then
                echo "Skipping the following unparsed/c++/shell code:"
                echo -e "$str" | sed 's/^/    /'
            else
                # parse
                if [ "$compile" = "none" ]; then
                    $VDB_AX analyze -s "$str" -v
                    uncompiled=$((uncompiled+1))
                else
                    $VDB_AX analyze -s "$str" --try-compile $compile -v
                fi
            fi
            skip=false
            count=$((count+1))
            str=""
            compile="none"
        else
            str+="$line"$'\n'
        fi
    done <<< "$data"
done

echo ""
echo "Extract test examples completed successfully"
if [ $uncompiled -gt 0 ]; then
    echo " with $uncompiled uncompiled tests"
fi