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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
|
# -*- tcl -*-
# doctools.test: tests for the doctools package.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright (c) 2003-2019 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.5
testsNeedTcltest 1.0
support {
use textutil/expander.tcl textutil::expander
use fileutil/fileutil.tcl fileutil
}
testing {
useLocal doctools.tcl doctools
}
# -------------------------------------------------------------------------
array_unset env LANG*
array_unset env LC_*
set env(LANG) C ; # Usually default if nothing is set, OS X requires this.
# -------------------------------------------------------------------------
namespace import ::doctools::new
# ---------------------------------------------------
# search paths .............................................................
test doctools-1.0 {default search paths} {
llength $::doctools::paths
} 1
test doctools-1.1 {extend package search paths} {
::doctools::search [file dirname [info script]]
set res [list]
lappend res [llength $::doctools::paths]
lappend res [lindex $::doctools::paths 0]
set res
} [list 2 [file dirname [info script]]]
test doctools-1.2 {extend package search paths, error} {
catch {::doctools::search foo} result
set result
} {doctools::search: path does not exist}
# format help .............................................................
test doctools-2.0 {format help} {
string length [doctools::help]
} 2213
# doctools .............................................................
test doctools-3.0 {doctools errors} {
catch {new} msg
set msg
} [tcltest::wrongNumArgs "new" "name args" 0]
test doctools-3.1 {doctools errors} {
catch {new set} msg
set msg
} "command \"set\" already exists, unable to create doctools object"
test doctools-3.2 {doctools errors} {
new mydoctools
catch {new mydoctools} msg
mydoctools destroy
set msg
} "command \"mydoctools\" already exists, unable to create doctools object"
test doctools-3.3 {doctools errors} {
catch {new mydoctools -foo} msg
set msg
} {wrong # args: doctools::new name ?opt val...??}
# doctools methods ......................................................
test doctools-4.0 {doctools method errors} {
new mydoctools
catch {mydoctools} msg
mydoctools destroy
set msg
} "wrong # args: should be \"mydoctools option ?arg arg ...?\""
test doctools-4.1 {doctools errors} {
new mydoctools
catch {mydoctools foo} msg
mydoctools destroy
set msg
} "bad option \"foo\": must be cget, configure, destroy, format, map, search, warnings, parameters, or setparam"
# cget ..................................................................
test doctools-5.0 {cget errors} {
new mydoctools
catch {mydoctools cget} result
mydoctools destroy
set result
} [tcltest::wrongNumArgs "::doctools::_cget" "name option" 1]
test doctools-5.1 {cget errors} {
new mydoctools
catch {mydoctools cget foo bar} result
mydoctools destroy
set result
} [tcltest::tooManyArgs "::doctools::_cget" "name option"]
test doctools-5.2 {cget errors} {
new mydoctools
catch {mydoctools cget -foo} result
mydoctools destroy
set result
} {doctools::_configure: Unknown option "-foo", expected -copyright, -file, -ibase, -module, -format, or -deprecated}
foreach {na nb option default newvalue} {
3 4 -deprecated 0 1
5 6 -file {} foo
7 8 -module {} bar
9 10 -format {} latex
11 12 -copyright {} {Andreas Kupries}
} {
test doctools-5.$na {cget query} {
new mydoctools
set res [mydoctools cget $option]
mydoctools destroy
set res
} $default ; # {}
test doctools-5.$nb {cget set & query} {
new mydoctools
mydoctools configure $option $newvalue
set res [mydoctools cget $option]
mydoctools destroy
set res
} $newvalue ; # {}
}
# configure ..................................................................
test doctools-6.0 {configure errors} {
new mydoctools
catch {mydoctools configure -foo bar -glub} result
mydoctools destroy
set result
} {wrong # args: doctools::_configure name ?opt val...??}
# [tcltest::wrongNumArgs "::doctools::_configure" "name ?option?|?option value...?" 1]
test doctools-6.1 {configure errors} {
new mydoctools
catch {mydoctools configure -foo} result
mydoctools destroy
set result
} {doctools::_configure: Unknown option "-foo", expected -copyright, -file, -ibase, -module, -format, or -deprecated}
test doctools-6.2 {configure retrieval} {
new mydoctools
catch {mydoctools configure} result
mydoctools destroy
set result
} {-file {} -ibase {} -module {} -format {} -copyright {} -deprecated 0}
foreach {n option illegalvalue result} {
3 -deprecated foo {doctools::_configure: -deprecated expected a boolean, got "foo"}
4 -format barf {doctools::_configure: -format: Unknown format "barf"}
} {
test doctools-6.$n {configure illegal value} {
new mydoctools
catch {mydoctools configure $option $illegalvalue} result
mydoctools destroy
set result
} $result
}
foreach {na nb option default newvalue} {
5 6 -deprecated 0 1
7 8 -file {} foo
9 10 -module {} bar
11 12 -format {} latex
13 14 -copyright {} {Andreas Kupries}
} {
test doctools-6.$na {configure query} {
new mydoctools
set res [mydoctools configure $option]
mydoctools destroy
set res
} $default ; # {}
test doctools-6.$nb {configure set & query} {
new mydoctools
mydoctools configure $option $newvalue
set res [mydoctools configure $option]
mydoctools destroy
set res
} $newvalue ; # {}
}
test doctools-6.15 {configure full retrieval} {
new mydoctools -file foo -module bar -format latex -deprecated 1 -copyright gnarf
catch {mydoctools configure} result
mydoctools destroy
set result
} {-file foo -ibase {} -module bar -format latex -copyright gnarf -deprecated 1}
# search ..................................................................
test doctools-7.0 {search errors} {
new mydoctools
catch {mydoctools search} result
mydoctools destroy
set result
} [tcltest::wrongNumArgs "::doctools::_search" "name path" 1]
test doctools-7.1 {search errors} {
new mydoctools
catch {mydoctools search foo bar} result
mydoctools destroy
set result
} [tcltest::tooManyArgs "::doctools::_search" "name path"]
test doctools-7.2 {search errors} {
new mydoctools
catch {mydoctools search foo} result
mydoctools destroy
set result
} {mydoctools search: path does not exist}
test doctools-7.3 {search, initial} {
new mydoctools
set res [llength $::doctools::doctoolsmydoctools::paths]
mydoctools destroy
set res
} 0
test doctools-7.4 {extend object search paths} {
new mydoctools
mydoctools search [file dirname [info script]]
set res [list]
lappend res [llength $::doctools::doctoolsmydoctools::paths]
lappend res [lindex $::doctools::doctoolsmydoctools::paths 0]
mydoctools destroy
set res
} [list 1 [file dirname [info script]]]
# format & warnings .......................................................
test doctools-8.0 {format errors} {
new mydoctools
catch {mydoctools format} result
mydoctools destroy
set result
} [tcltest::wrongNumArgs "::doctools::_format" "name text" 1]
test doctools-8.1 {format errors} {
new mydoctools
catch {mydoctools format foo bar} result
mydoctools destroy
set result
} [tcltest::tooManyArgs "::doctools::_format" "name text"]
test doctools-8.2 {format errors} {
new mydoctools
catch {mydoctools format foo} result
mydoctools destroy
set result
} {mydoctools: No format was specified}
test doctools-8.3 {format} {
new mydoctools -format list
set res [mydoctools format {[manpage_begin foo n 1.0][description][strong foo][manpage_end]}]
set res [list [lindex $res 0] [dictsort [lindex $res 1]]]
lappend res [mydoctools warnings]
mydoctools destroy
set res
} {manpage {category {} desc {} fid {} file {} keywords {} module {} section n seealso {} shortdesc {} title foo version 1.0} {}}
test doctools-8.4 {format} {
new mydoctools -format list -deprecated on
set res [mydoctools format {[manpage_begin foo n 1.0][description][strong foo][manpage_end]}]
set res [list [lindex $res 0] [dictsort [lindex $res 1]]]
lappend res [mydoctools warnings]
mydoctools destroy
set res
} {manpage {category {} desc {} fid {} file {} keywords {} module {} section n seealso {} shortdesc {} title foo version 1.0} {{DocTools Warning (depr_strong): In macro at line 1, column 38 of file :
DocTools Warning (depr_strong): Deprecated command "[strong]".
DocTools Warning (depr_strong): Please consider appropriate semantic markup or [emph] instead.}}}
# doctools manpage syntax .......................................................
test doctools-9.0 {manpage syntax} {
new mydoctools -format null
catch {mydoctools format foo} result
mydoctools destroy
set result
} {Doctools Error in plain text at line 1, column 0:
[plain_text foo]
--> (FmtError) Manpage error (body), "plain_text foo" : Plain text not allowed outside of the body of the manpage.}
# -------------------------------------------------------------------------
## Series of tests for all available backends, check their formatting.
set k 11
foreach format {
html tmml nroff
latex text wiki markdown
desc list null
} {
set n 0
foreach src [TestFilesGlob tests/fmt/man/*] {
# Get the expected result
set dst [localPath [file join tests fmt $format [file tail $src]]]
set map {} ; lappend map @USR@ $tcl_platform(user)
set rem {} ; lappend rem $tcl_platform(user) @USR@
if {$format eq "nroff"} {
lappend map ".so man.macros\n" [fileutil::cat [localPath mpformats/man.macros]]
}
if {[catch {
set expected [string map $map [fileutil::cat $dst]]
}]} { set expected **missing** }
test doctools-${format}-${k}.$n "doctools backends, $format/[file tail $src]" {
new mydoctools
mydoctools configure \
-format $format \
-module .MODULE. \
-file .FILE. \
-copyright .COPYRIGHT.
if {[catch {
set res [mydoctools format [fileutil::cat $src]]
}]} {
set res $::errorInfo
}
mydoctools destroy
#fileutil::writeFile ${dst}.actual [string map $rem $res]
set res
} $expected
#fileutil::writeFile ${dst}.expected $expected
incr n
}
incr k
}
# -------------------------------------------------------------------------
## Test of special 'raw' mode available to the HTML backend.
set n 0
foreach src [TestFilesGlob tests/fmt/man/*] {
# Get the expected result
set dst [localPath [file join tests fmt html [file tail $src]]]
set map {} ; lappend map @USR@ $tcl_platform(user)
set rem {} ; lappend rem $tcl_platform(user) @USR@
if {[catch {
set expected [string map $map [fileutil::cat $dst]]
}]} { set expected **missing** }
# Transform regular output to contents of body/, i.e. raw output.
regsub {</body>.*} $expected {} expected
regsub {.*<body>} $expected {} expected
append expected \n
#if {$n == 5 || $n == 8} { set expected \n$expected }
# Run the test ...
test doctools-html-raw-11.$n "doctools backends, html-raw/[file tail $src]" {
new mydoctools
mydoctools configure \
-format html \
-module .MODULE. \
-file .FILE. \
-copyright .COPYRIGHT.
mydoctools setparam raw 1
if {[catch {
set res [mydoctools format [fileutil::cat $src]]
}]} {
set res $::errorInfo
}
mydoctools destroy
#fileutil::writeFile ${dst}.actual [string map $rem $res]
set res
} $expected
#fileutil::writeFile ${dst}.expected $expected
incr n
}
# -------------------------------------------------------------------------
## Series of tests for the frontend, cover all possible syntax errors.
set n 0
foreach src [TestFilesGlob tests/fmt/syntax/e_*] {
set dst [file join [file dirname $src] r_[string range [file tail ${src}] 2 end]]
set expected [string trim [fileutil::cat $dst]]
test doctools-syntax-error-10.$n "doctools frontend, syntax error, [file tail $src]" {
new mydoctools
mydoctools configure \
-format null \
-module .MODULE. \
-file .FILE. \
-copyright .COPYRIGHT.
catch {
mydoctools format [fileutil::cat $src]
} res
mydoctools destroy
#fileutil::writeFile ${src}.actual $msg
set res
} $expected
#fileutil::writeFile ${dst}.expected $expected
incr n
}
# -------------------------------------------------------------------------
namespace forget ::doctools::new
testsuiteCleanup
return
|