toybox/tests/man.test
<<
>>
Prefs
   1#!/bin/bash
   2# Copyright 2019 makepost <makepost@firemail.cc>
   3
   4[ -f testing.sh ] && . testing.sh
   5
   6#testing "name" "command" "result" "infile" "stdin"
   7
   8mkdir -p banana/man{1,3,5}
   9
  10# Can't/shouldn't write to /usr/share/man so use -M to change path
  11MAN="man -M banana"
  12echo one | bzip2 >banana/man1/numbers.1.bz2
  13echo three | gzip >banana/man3/numbers.3.gz
  14echo five > banana/man5/numbers.5
  15
  16testing "man" "$MAN numbers" " one\n\n" "" ""
  17testing "man.section" "$MAN numbers.3" " three\n\n" "" ""
  18testing "section man" "$MAN 5 numbers" " five\n\n" "" ""
  19testing "/" "$MAN /" "" "" "" # Regression guard for !suf in zopen
  20
  21cat >banana/man1/toybox.1 <<EOF
  22.TP
  23.PD 0
  24.B \\-F
  25.TP
  26.PD
  27.B \\-\\^\\-foo\\-bar
  28Does something.
  29.TP
  30.PD 0
  31.B \\-\\-no\\-alias
  32Has no alias.
  33EOF
  34
  35testing "gawk alias" "$MAN toybox" " -F\n --foo-bar Does something.\n\n --no-alias Has no alias.\n\n" "" ""
  36
  37cat >banana/man1/toybox.1 <<EOF
  38\\fBsh\\fR-compatible
  39\\fIKorn\\fP
  40EOF
  41testing "bash bold,ita" "$MAN toybox" " sh-compatible Korn\n\n" "" ""
  42
  43cat >banana/man1/toybox.1 <<EOF
  44quoted \\(aqstring\\(aq
  45\\(dqserver\\(dq
  46Don\\(cq\\&t
  47EOF
  48testing "bash,rsync quote" "$MAN toybox" " quoted 'string' \"server\" Don't\n\n" "" ""
  49
  50echo "\\*(lq\\-\\^\\-\\*(rq" >banana/man1/toybox.1
  51testing "gawk quote" "$MAN toybox" " \"--\"\n\n" "" ""
  52
  53cat >banana/man1/toybox.1 <<EOF
  54.IP \\(bu
  55[\\fB|\\fP\\(bv\\fB|&\\fP]
  56EOF
  57testing "bash symbol" "$MAN toybox" " * [|||&]\n\n" "" ""
  58
  59cat >banana/man1/toybox.1 <<EOF
  60\\&\\fBfflush(...)\\fR
  61\\f(CW$ ssh ...\\fP
  62EOF
  63testing "gawk,rsync fancy" "$MAN toybox" " fflush(...) $ ssh ...\n\n" "" ""
  64
  65cat >banana/man1/toybox.1 <<EOF
  66"\\eC\\-x\\eC\\-r": re\\-read
  67must be \\(>= 1
  68EOF
  69testing "bash escape" "$MAN toybox" " \"\C-x\C-r\": re-read must be >= 1\n\n" "" ""
  70
  71echo "\\*(AK language.  The \\*(PX standard" >banana/man1/toybox.1
  72testing "gawk var" "$MAN toybox" " #AK language.  The #PX standard\n\n" "" ""
  73
  74cat >banana/man1/toybox.1 <<EOF
  75If set to
  76.BR On ,
  77(...)
  78EOF
  79testing "bash boldpunct" "$MAN toybox" " If set to On, (...)\n\n" "" ""
  80
  81cat >banana/man1/toybox.1 <<EOF
  82.IP \\fB\$endif\\fP
  83(...)
  84.IP \\fB\$else\\fP
  85(...)
  86.IP \\fB\$include\\fP
  87EOF
  88testing "bash list" "$MAN toybox" " \$endif (...)\n\n \$else (...)\n\n \$include\n\n" "" ""
  89
  90cat >banana/man1/toybox.1 <<EOF
  91asynchronously (in the
  92.IR background ),
  93it prints
  94EOF
  95testing "bash itapunct" "$MAN toybox" " asynchronously (in the background), it prints\n\n" "" ""
  96
  97cat >banana/man1/toybox.1 <<EOF
  98(...)
  99.B Bash
 100is
 101EOF
 102testing "bash bold" "$MAN toybox" " (...) Bash is\n\n" "" ""
 103
 104# TODO: Unquote.
 105cat >banana/man1/toybox.1 <<EOF
 106.PD 0
 107.BI \\-f " program-file"
 108.TP
 109EOF
 110testing "gawk boldita" "$MAN toybox" " -f \" program-file\"\n\n" "" ""
 111
 112cat >banana/man1/toybox.1 <<EOF
 113same format as
 114.FN /etc/hosts
 115(...)
 116EOF
 117testing "bash filename" "$MAN toybox" " same format as /etc/hosts (...)\n\n" "" ""
 118
 119cat >banana/man1/toybox.1 <<EOF
 120The
 121.I Internal Field Separator
 122that is used
 123EOF
 124testing "bash ita" "$MAN toybox" " The Internal Field Separator that is used\n\n" "" ""
 125
 126cat >banana/man1/toybox.1 <<EOF
 127.if n Copyright (C) 2019
 128.if t Copyright \\(co 2019
 129EOF
 130testing "bash nroff" "$MAN toybox" " Copyright (C) 2019\n\n" "" ""
 131
 132cat >banana/man1/toybox.1 <<EOF
 133.EX
 134#include <stdio.h>
 135#include <stdlib.h>
 136.EE
 137EOF
 138testing "stat example" "$MAN toybox" "#include <stdio.h>\n#include <stdlib.h>\n\n\n" "" ""
 139
 140cat >banana/man1/toybox.1 <<EOF
 141(...)
 142.PP
 143(...)
 144EOF
 145testing "bash paragraph" "$MAN toybox" " (...)\n\n (...)\n\n" "" ""
 146
 147# TODO: Find some command I saw that has a different see below.
 148cat >banana/man1/toybox.1 <<EOF
 149(see
 150.SM
 151.B INVOCATION
 152below)
 153EOF
 154testing "bash small" "$MAN toybox" " (see INVOCATION below)\n\n" "" ""
 155
 156cat >banana/man1/toybox.1 <<EOF
 157(...)
 158.SH "SHELL GRAMMAR"
 159.SS Simple Commands
 160.PP
 161(...)
 162EOF
 163testing "bash section" "$MAN toybox" " (...)\n\n\"SHELL GRAMMAR\"\n\nSimple Commands\n\n (...)\n\n" "" ""
 164
 165echo ".so man1/last.1" >banana/man1/toybox.1
 166testing "lastb" "$MAN toybox" "See last.1\n\n" "" ""
 167
 168cat >banana/man1/toybox.1 <<EOF
 169.TH TOYBOX 1 "Apr 13 2019" "Project Organization" "Document Name"
 170.PP
 171.TH "TOYBOX" "1" "04/13/2019" "Toybox 0\\&.8\\&.0" "Toybox Manual"
 172EOF
 173testing "gawk,git head" "$MAN toybox" "TOYBOX 1  Apr 13 2019   Project Organization   Document Name \n\n TOYBOX   1   04/13/2019   Toybox 0.8.0   Toybox Manual \n\n" "" ""
 174
 175cat >banana/man1/toybox.1 <<EOF
 176(...)
 177.PP
 178.PD 0
 179.TP 10
 180.B \\-c
 181If the
 182.B \\-c
 183option is present
 184EOF
 185testing "bash table" "$MAN toybox" " (...)\n\n -c If the -c option is present\n\n" "" ""
 186
 187cat >banana/man1/toybox.1 <<EOF
 188.de FN
 189.sp
 190.RE
 191'\" t
 192EOF
 193testing "bash,git garbage" "$MAN toybox" "" "" ""
 194
 195# "bash,git garbage" from above has no content, -k skips it.
 196bzip2 >banana/man1/numbers.1.bz2 <<EOF
 197.TH NUMBERS 1 "2019 Apr 28" "Toybox Manual"
 198.SH NAME
 199man \- test -k
 200.SH ANOTHER SECTION
 201.so noop.1
 202Skip this text.
 203EOF
 204echo "No dash." | gzip >banana/man3/numbers.3.gz
 205echo .so man1/numbers.1 >banana/man5/numbers.5
 206testing "-k ." "$MAN -k ." "numbers.1.bz2 - test -k\nnumbers.3.gz - No dash.\nnumbers.5 - See numbers.1\n" "" ""
 207testing "-k -k" "$MAN -k -k" "numbers.1.bz2 - test -k\n" "" ""
 208testing "-k d.*h" "$MAN -k 'd.*h'" "numbers.3.gz - No dash.\n" "" ""
 209testing "-k ers.1" "$MAN -k ers.1" "numbers.1.bz2 - test -k\nnumbers.5 - See numbers.1\n" "" ""
 210
 211mkdir -p walrus/man1
 212echo Local development override. | bzip2 >walrus/man1/numbers.1.bz2
 213testing "-M /dir:/dir0" "man -M walrus:banana numbers" " Local development override.\n\n" "" ""
 214testing "-M /dir:/dir0 -k ." "man -M walrus:banana -k ." "numbers.1.bz2 - Local development override.\nnumbers.1.bz2 - test -k\nnumbers.3.gz - No dash.\nnumbers.5 - See numbers.1\n" "" ""
 215testing "-M '' x" "man -M '' numbers 2>&1" "man: no numbers\n" "" ""
 216testing "-M '' 1 x" "man -M '' 1 numbers 2>&1" "man: section 1 no numbers\n" "" ""
 217testing "-M '' -k ." "man -M '' -k ." "" "" ""
 218
 219# TODO: emerge section header newline
 220# TODO: fdm,man-pages man1p/, .nf, rare tags
 221
 222rm -rf banana walrus
 223