vim-literate-markdown

A Vim plugin to replicate a subset of Org mode's literate programming, for Markdown files.
git clone git://git.alex.balgavy.eu/vim-literate-markdown.git
Log | Files | Refs | README

run.sh (1904B)


      1 #!/bin/sh
      2 tempdir=$(mktemp -d)
      3 trap 'rm -r $tempdir' INT TERM EXIT
      4 
      5 # args: test_name
      6 run_test() {
      7   # Create a subdirectory specific to this test
      8   testdir="$tempdir"/"$1"
      9   mkdir "$testdir"
     10 
     11   # Edit the tangle targets in the test files accordingly
     12   sed "/:Tangle/s!DIRNAME!$testdir!; /:Tangle/s!FILENAME!$1!" "$1".md > "$testdir"/"$1".md
     13 
     14   # Run the tangle command
     15   vim -c "Tangle | qall" "$testdir"/"$1".md
     16 
     17   # Compare all generated files with expected files
     18   find "$testdir" -type f -not -name "$1".md | while read -r f;  do
     19     difference="$(diff "$f" "./${f##*/}")"
     20     [ -n "$difference" ] && printf "Test %s FAILED.\nDiff expected (%s) vs actual (%s):\n%s" "$1" "$f" "./${f##*/}" "$difference"
     21   done
     22 }
     23 
     24 test_block_exec() {
     25   die() { printf '%s\n' "$1" >&2 && exit 1; }
     26 
     27   testdir="$tempdir"/exec_block
     28   mkdir "$testdir"
     29   cp exec_block.md "$testdir"/exec_block.md
     30 
     31   # Run both blocks and check for expected output
     32   vim -c 'silent 9 | ExecPrevBlock | $ | ExecPrevBlock | wqall' "$testdir"/exec_block.md
     33   [ "$(sed -n 12p "$testdir"/exec_block.md)" = 'Correct!' ] || die "Test exec_block FAILED. Did not find 'Correct!'"
     34   grep "^$(whoami).*grep vim" "$testdir"/exec_block.md >/dev/null 2>&1 || die "Test exec_block FAILED. Did not find 'grep vim' in process list"
     35 
     36   # Change the second block & test for expected output
     37   vim -c '17norm A | grep -v grep' -c '17 | ExecPrevBlock | wqall' "$testdir"/exec_block.md
     38   grep "^$(whoami).*grep vim" "$testdir"/exec_block.md >/dev/null 2>&1 && die "Test exec_block FAILED. Found 'grep vim' in process list when running second time"
     39 }
     40 
     41 # Run the tests
     42 test_block_exec
     43 for i in \
     44   all_in_one_file \
     45   only_specific_language \
     46   two_different_languages \
     47   simple_macros \
     48   example_1 \
     49   example_2 \
     50   example_3 \
     51   indented_tangle_directive \
     52   macro_included_in_two_separate_blocks
     53 do run_test "$i"; done
     54 
     55 rm -r "$tempdir"
     56 trap - INT TERM EXIT