Bladeren bron

test_markdown() without temporary files
- A much shorter test_markdown() function that compares output directly
rather than using temp files.
- Revert to using 'which' rather than 'command -v' for using the markdown binary
because 'command -v' will find the markdown() shell function.

Martijn Dekker 9 jaren geleden
bovenliggende
commit
e3cf406bd1
1 gewijzigde bestanden met toevoegingen van 3 en 18 verwijderingen
  1. 3 18
      bb.sh

+ 3 - 18
bb.sh

@@ -144,7 +144,7 @@ global_variables() {
 
 
     # Markdown location. Trying to autodetect by default.
     # Markdown location. Trying to autodetect by default.
     # The invocation must support the signature 'markdown_bin in.md > out.html'
     # The invocation must support the signature 'markdown_bin in.md > out.html'
-    markdown_bin=$(command -v Markdown.pl || command -v markdown)
+    markdown_bin=$(which Markdown.pl || which markdown)
 }
 }
 
 
 # Check for the validity of some variables
 # Check for the validity of some variables
@@ -161,23 +161,8 @@ global_variables_check() {
 
 
 # Test if the markdown script is working correctly
 # Test if the markdown script is working correctly
 test_markdown() {
 test_markdown() {
-    [[ -z $markdown_bin ]] && return 1
-    command -v diff >/dev/null || return 1
-
-    in=/tmp/md-in-${RANDOM}.md
-    out=/tmp/md-out-${RANDOM}.html
-    good=/tmp/md-good-${RANDOM}.html
-    echo -e "line 1\n\nline 2" > "$in"
-    echo -e "<p>line 1</p>\n\n<p>line 2</p>" > "$good"
-    "$markdown_bin" "$in" > "$out" 2> /dev/null
-    diff $good $out &> /dev/null # output is irrelevant, we'll check $?
-    if (($? != 0)); then
-        rm -f "$in" "$good" "$out"
-        return 1
-    fi
-    
-    rm -f "$in" "$good" "$out"
-    return 0
+    [[ -n $markdown_bin ]] &&
+        [[ $("$markdown_bin" <<< $'line 1\n\nline 2') == $'<p>line 1</p>\n\n<p>line 2</p>' ]]
 }
 }