Fossil SCM
Add tests for the mimetype on wiki command. Update help text to list valid mimetypes
dave.vines
2016-05-06 14:08
Commit
6fa5570b9a2cc6e6b4e7a5c4ad8dfed1d61d7df1
Parent
e9d7c5aa29c3fca…
2 files changed
+4
+58
+4
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -1188,10 +1188,14 @@ | ||
| 1188 | 1188 | ** Options: |
| 1189 | 1189 | ** -M|--mimetype TEXT-FORMAT The mime type of the update. |
| 1190 | 1190 | ** Defaults to the type used by |
| 1191 | 1191 | ** the previous version of the |
| 1192 | 1192 | ** page, or text/x-fossil-wiki. |
| 1193 | +** Valid values are: text/x-fossil-wiki, | |
| 1194 | +** text/markdown and text/plain. fossil, | |
| 1195 | +** markdown or plain can be specified as | |
| 1196 | +** synonyms of these values. | |
| 1193 | 1197 | ** -t|--technote DATETIME Specifies the timestamp of |
| 1194 | 1198 | ** the technote to be created or |
| 1195 | 1199 | ** updated. When updating a tech note |
| 1196 | 1200 | ** the most recently modified tech note |
| 1197 | 1201 | ** with the specified timestamp will be |
| 1198 | 1202 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1188,10 +1188,14 @@ | |
| 1188 | ** Options: |
| 1189 | ** -M|--mimetype TEXT-FORMAT The mime type of the update. |
| 1190 | ** Defaults to the type used by |
| 1191 | ** the previous version of the |
| 1192 | ** page, or text/x-fossil-wiki. |
| 1193 | ** -t|--technote DATETIME Specifies the timestamp of |
| 1194 | ** the technote to be created or |
| 1195 | ** updated. When updating a tech note |
| 1196 | ** the most recently modified tech note |
| 1197 | ** with the specified timestamp will be |
| 1198 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1188,10 +1188,14 @@ | |
| 1188 | ** Options: |
| 1189 | ** -M|--mimetype TEXT-FORMAT The mime type of the update. |
| 1190 | ** Defaults to the type used by |
| 1191 | ** the previous version of the |
| 1192 | ** page, or text/x-fossil-wiki. |
| 1193 | ** Valid values are: text/x-fossil-wiki, |
| 1194 | ** text/markdown and text/plain. fossil, |
| 1195 | ** markdown or plain can be specified as |
| 1196 | ** synonyms of these values. |
| 1197 | ** -t|--technote DATETIME Specifies the timestamp of |
| 1198 | ** the technote to be created or |
| 1199 | ** updated. When updating a tech note |
| 1200 | ** the most recently modified tech note |
| 1201 | ** with the specified timestamp will be |
| 1202 |
+58
| --- test/wiki.test | ||
| +++ test/wiki.test | ||
| @@ -29,10 +29,41 @@ | ||
| 29 | 29 | set y [read_file $b] |
| 30 | 30 | regsub -all { +\n} $y \n y |
| 31 | 31 | regsub -all {\n$} $y {} y |
| 32 | 32 | return [expr {$x==$y}] |
| 33 | 33 | } |
| 34 | + | |
| 35 | +# Return the mime type in the manifest for a given wiki page | |
| 36 | +# Defaults to "error: some text" if the manifest can't be located and | |
| 37 | +# "text/x-fossil-wiki" (the default mimetype for rendering) | |
| 38 | +# if the N card is omitted in the manifest. | |
| 39 | +# Note: Makes fossil calls, so $CODE and $RESULT will be corrupted | |
| 40 | +proc get_mime_type {name} { | |
| 41 | + global CODE RESULT | |
| 42 | + fossil http << "GET /wiki?name=$name" | |
| 43 | + if {$CODE != 0} { | |
| 44 | + return error: /wiki?name=$name $CODE $RESULT" | |
| 45 | + } | |
| 46 | + set CODE [regexp {href="/info/([0-9a-f]+)"} $RESULT match info] | |
| 47 | + if {$CODE == 0} { | |
| 48 | + return "error: No info link found for wiki page $name" | |
| 49 | + } | |
| 50 | + fossil http << "GET /artifact/$info" | |
| 51 | + if {$CODE != 0} { | |
| 52 | + return "error: /artifact/$info $CODE $RESULT" | |
| 53 | + } | |
| 54 | + set CODE [regexp {<pre>(.*)</pre>} $RESULT match pre] | |
| 55 | + if {$CODE == 0} { | |
| 56 | + return "error: No pre block in /artifact/$info" | |
| 57 | + } | |
| 58 | + set CODE [regexp -line {^N (.*)$} $pre match mimetype] | |
| 59 | + if {$CODE == 0} { | |
| 60 | + return "text/x-fossil-wiki" | |
| 61 | + } | |
| 62 | + return $mimetype | |
| 63 | +} | |
| 64 | + | |
| 34 | 65 | |
| 35 | 66 | ############################################################################### |
| 36 | 67 | # Initially there should be no wiki entries |
| 37 | 68 | fossil wiki list |
| 38 | 69 | test wiki-0 {[normalize_result] eq {}} |
| @@ -333,9 +364,36 @@ | ||
| 333 | 364 | # And we get an error for the ambiguous tech note id |
| 334 | 365 | fossil wiki commit {Old tech note} f15 --technote $duplicateid -expectError |
| 335 | 366 | test wiki-47 {$CODE != 0} |
| 336 | 367 | fossil attachment add fa --technote $duplicateid -expectError |
| 337 | 368 | test wiki-48 {$CODE != 0} |
| 369 | + | |
| 370 | +############################################################################### | |
| 371 | +# Check the default mimetype is text/x-fossil-wiki | |
| 372 | +test wiki-49 {[get_mime_type tcltest] == "text/x-fossil-wiki"} | |
| 373 | + | |
| 374 | +############################################################################### | |
| 375 | +# Check long form of the mimetypes are recorded correctly | |
| 376 | +fossil wiki create tcltest-x-fossil f1 -mimetype text/x-fossil-wiki | |
| 377 | +test wiki-50 {[get_mime_type tcltest-x-fossil] == "text/x-fossil-wiki"} | |
| 378 | +fossil wiki create tcltest-x-markdown f1 -mimetype text/x-markdown | |
| 379 | +test wiki-51 {[get_mime_type tcltest-x-markdown] == "text/x-markdown"} | |
| 380 | +fossil wiki create tcltest-plain f1 -mimetype text/plain | |
| 381 | +test wiki-52 {[get_mime_type tcltest-plain] == "text/plain"} | |
| 382 | +fossil wiki create tcltest-x-random f1 -mimetype text/x-random | |
| 383 | +test wiki-53 {[get_mime_type tcltest-x-random] == "text/x-fossil-wiki"} | |
| 384 | + | |
| 385 | +############################################################################### | |
| 386 | +# Check short form of the mimetypes are recorded correctly | |
| 387 | +fossil wiki create tcltest-x-fossil-short f1 -mimetype wiki | |
| 388 | +test wiki-54 {[get_mime_type tcltest-x-fossil-short] == "text/x-fossil-wiki"} | |
| 389 | +fossil wiki create tcltest-x-markdown-short f1 -mimetype markdown | |
| 390 | +test wiki-55 {[get_mime_type tcltest-x-markdown-short] == "text/x-markdown"} | |
| 391 | +fossil wiki create tcltest-plain-short f1 -mimetype plain | |
| 392 | +test wiki-56 {[get_mime_type tcltest-plain-short] == "text/plain"} | |
| 393 | +fossil wiki create tcltest-x-random-short f1 -mimetype random | |
| 394 | +test wiki-57 {[get_mime_type tcltest-x-random-short] == "text/x-fossil-wiki"} | |
| 395 | + | |
| 338 | 396 | |
| 339 | 397 | ############################################################################### |
| 340 | 398 | test_cleanup |
| 341 | 399 | |
| 342 | 400 |
| --- test/wiki.test | |
| +++ test/wiki.test | |
| @@ -29,10 +29,41 @@ | |
| 29 | set y [read_file $b] |
| 30 | regsub -all { +\n} $y \n y |
| 31 | regsub -all {\n$} $y {} y |
| 32 | return [expr {$x==$y}] |
| 33 | } |
| 34 | |
| 35 | ############################################################################### |
| 36 | # Initially there should be no wiki entries |
| 37 | fossil wiki list |
| 38 | test wiki-0 {[normalize_result] eq {}} |
| @@ -333,9 +364,36 @@ | |
| 333 | # And we get an error for the ambiguous tech note id |
| 334 | fossil wiki commit {Old tech note} f15 --technote $duplicateid -expectError |
| 335 | test wiki-47 {$CODE != 0} |
| 336 | fossil attachment add fa --technote $duplicateid -expectError |
| 337 | test wiki-48 {$CODE != 0} |
| 338 | |
| 339 | ############################################################################### |
| 340 | test_cleanup |
| 341 | |
| 342 |
| --- test/wiki.test | |
| +++ test/wiki.test | |
| @@ -29,10 +29,41 @@ | |
| 29 | set y [read_file $b] |
| 30 | regsub -all { +\n} $y \n y |
| 31 | regsub -all {\n$} $y {} y |
| 32 | return [expr {$x==$y}] |
| 33 | } |
| 34 | |
| 35 | # Return the mime type in the manifest for a given wiki page |
| 36 | # Defaults to "error: some text" if the manifest can't be located and |
| 37 | # "text/x-fossil-wiki" (the default mimetype for rendering) |
| 38 | # if the N card is omitted in the manifest. |
| 39 | # Note: Makes fossil calls, so $CODE and $RESULT will be corrupted |
| 40 | proc get_mime_type {name} { |
| 41 | global CODE RESULT |
| 42 | fossil http << "GET /wiki?name=$name" |
| 43 | if {$CODE != 0} { |
| 44 | return error: /wiki?name=$name $CODE $RESULT" |
| 45 | } |
| 46 | set CODE [regexp {href="/info/([0-9a-f]+)"} $RESULT match info] |
| 47 | if {$CODE == 0} { |
| 48 | return "error: No info link found for wiki page $name" |
| 49 | } |
| 50 | fossil http << "GET /artifact/$info" |
| 51 | if {$CODE != 0} { |
| 52 | return "error: /artifact/$info $CODE $RESULT" |
| 53 | } |
| 54 | set CODE [regexp {<pre>(.*)</pre>} $RESULT match pre] |
| 55 | if {$CODE == 0} { |
| 56 | return "error: No pre block in /artifact/$info" |
| 57 | } |
| 58 | set CODE [regexp -line {^N (.*)$} $pre match mimetype] |
| 59 | if {$CODE == 0} { |
| 60 | return "text/x-fossil-wiki" |
| 61 | } |
| 62 | return $mimetype |
| 63 | } |
| 64 | |
| 65 | |
| 66 | ############################################################################### |
| 67 | # Initially there should be no wiki entries |
| 68 | fossil wiki list |
| 69 | test wiki-0 {[normalize_result] eq {}} |
| @@ -333,9 +364,36 @@ | |
| 364 | # And we get an error for the ambiguous tech note id |
| 365 | fossil wiki commit {Old tech note} f15 --technote $duplicateid -expectError |
| 366 | test wiki-47 {$CODE != 0} |
| 367 | fossil attachment add fa --technote $duplicateid -expectError |
| 368 | test wiki-48 {$CODE != 0} |
| 369 | |
| 370 | ############################################################################### |
| 371 | # Check the default mimetype is text/x-fossil-wiki |
| 372 | test wiki-49 {[get_mime_type tcltest] == "text/x-fossil-wiki"} |
| 373 | |
| 374 | ############################################################################### |
| 375 | # Check long form of the mimetypes are recorded correctly |
| 376 | fossil wiki create tcltest-x-fossil f1 -mimetype text/x-fossil-wiki |
| 377 | test wiki-50 {[get_mime_type tcltest-x-fossil] == "text/x-fossil-wiki"} |
| 378 | fossil wiki create tcltest-x-markdown f1 -mimetype text/x-markdown |
| 379 | test wiki-51 {[get_mime_type tcltest-x-markdown] == "text/x-markdown"} |
| 380 | fossil wiki create tcltest-plain f1 -mimetype text/plain |
| 381 | test wiki-52 {[get_mime_type tcltest-plain] == "text/plain"} |
| 382 | fossil wiki create tcltest-x-random f1 -mimetype text/x-random |
| 383 | test wiki-53 {[get_mime_type tcltest-x-random] == "text/x-fossil-wiki"} |
| 384 | |
| 385 | ############################################################################### |
| 386 | # Check short form of the mimetypes are recorded correctly |
| 387 | fossil wiki create tcltest-x-fossil-short f1 -mimetype wiki |
| 388 | test wiki-54 {[get_mime_type tcltest-x-fossil-short] == "text/x-fossil-wiki"} |
| 389 | fossil wiki create tcltest-x-markdown-short f1 -mimetype markdown |
| 390 | test wiki-55 {[get_mime_type tcltest-x-markdown-short] == "text/x-markdown"} |
| 391 | fossil wiki create tcltest-plain-short f1 -mimetype plain |
| 392 | test wiki-56 {[get_mime_type tcltest-plain-short] == "text/plain"} |
| 393 | fossil wiki create tcltest-x-random-short f1 -mimetype random |
| 394 | test wiki-57 {[get_mime_type tcltest-x-random-short] == "text/x-fossil-wiki"} |
| 395 | |
| 396 | |
| 397 | ############################################################################### |
| 398 | test_cleanup |
| 399 | |
| 400 |