File: test-doc-format.sh

package info (click to toggle)
xlbiff 4.6.8-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 248 kB
  • sloc: ansic: 754; sh: 609; python: 389; xml: 67; perl: 45; makefile: 44
file content (84 lines) | stat: -rwxr-xr-x 2,791 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
#! /bin/bash
# Test that the manual pages examples format correctly.

# Tests a variety of "man page" formatters,
# samples their output, and verifies that they emit no warnings.

. "$(dirname "$0")"/utilities.sh

util_check_dependencies groff groff man man-db
util_check_dependencies mandoc mandoc man2html man2html-base

create_test_tmpdir

exit_status=0

main() {
    local xlbiff_man_out='<Button1Press>:  popdown()$'
    local preview_man_out='^ *mailbox-preview imap.example.com$'

    run_man_test 'man' "$xlbiff_man_out" "$preview_man_out"
    run_man_test 'nroff -man' "$xlbiff_man_out" "$preview_man_out"
    run_man_test 'groff -man -Tpdf' '/Courier'
    run_man_test 'groff -man -Thtml' '<pre[ >]'
    run_man_test 'mandoc -T lint' ''
    run_man_test 'mandoc -T html' '<pre[ >]'
    run_man_test 'man2html' '<pre[ >]'
    # man2texi does not have a Debian package; test only if we find the binary.
    if hash man2texi 2> /dev/null; then
        run_man_test 'man2texi' '@display'
    fi
}


# Run all manual pages through one formatter
run_man_test() {
    local formatting_cmd="$1"
    local expect_in_xlbiff_out="$2"
    local expect_in_preview_out="$3"

    printf '%q: testing %s\n' "$0" "$formatting_cmd"
    local pre='./' post=".man"
    if [[ "$formatting_cmd" = man ]]; then
        pre=''
        post=''
    fi
    if [[ -z "$expect_in_preview_out" ]]; then
        expect_in_preview_out=$expect_in_xlbiff_out
    fi
    run_man_test_1 "${pre}xlbiff${post}" "$formatting_cmd" "$expect_in_xlbiff_out"
    run_man_test_1 "${pre}mailbox-preview${post}" "$formatting_cmd" \
                   "$expect_in_preview_out"
}

# Run 1 manual page through one formatter
run_man_test_1() {
    local input_file="$1"
    local formatting_command="$2"
    local expected_in_output="$3"

    local command_parts=($formatting_command) # not quoted, want word expand
    "${command_parts[@]}" "$input_file" \
                          > "$test_tmpdir"/stdout 2> "$test_tmpdir"/stderr
    # test is case insensitive:  <PRE> == <pre>
    if ! grep -i -- "$expected_in_output" "$test_tmpdir"/stdout > /dev/null
    then
        printf '%q: text "%s" not found in output of %s %s\n' \
               "$0" "$expected_in_output" "$formatting_command" "$input_file"
        exit_status=1
    fi
    if [[ "$formatting_command" =~ lint ]]; then
        # mandoc lint incorrectly/uselessly flags
        # "WARNING: skipping paragraph macro: IP empty"
        grep -v 'IP empty' "$test_tmpdir/stdout" >> "$test_tmpdir/stderr"
    fi
    if [[ -s "$test_tmpdir/stderr" ]]; then
        printf '%q: unexpected error output running %s %s\n' \
               "$0" "$formatting_command" "$input_file"
        cat "$test_tmpdir/stderr"
        exit_status=1
    fi
}

main "$@"
exit "$exit_status"