From 8e5274b1a2ca100e8003ac207c8590d308e4a2d2 Mon Sep 17 00:00:00 2001 From: Tinmarino Date: Sun, 23 Aug 2020 03:42:02 -0400 Subject: [PATCH] Test: Batchify all && Lint run_test.sh All tests in the same batch, in other words, no independant test --- test/config_vars.vader | 3 +- test/file_goto.vader | 6 -- test/file_system.vader | 8 -- test/html_blockquote.vader | 4 - test/html_convert_default.vader | 4 - test/html_diary_rss_feed.vader | 14 +-- test/link_generation.vader | 5 +- test/link_renaming.vader | 5 -- test/{independent_runs => }/map.vader | 85 ++++-------------- test/run_tests.sh | 106 +++++++++-------------- test/{independent_runs => }/search.vader | 0 test/tag.vader | 4 - test/vimrc | 6 +- 13 files changed, 75 insertions(+), 175 deletions(-) rename test/{independent_runs => }/map.vader (73%) rename test/{independent_runs => }/search.vader (100%) diff --git a/test/config_vars.vader b/test/config_vars.vader index 5e36f15..2442468 100644 --- a/test/config_vars.vader +++ b/test/config_vars.vader @@ -6,7 +6,6 @@ Given txt (txt): txt Execute (VimWei vars #980): - call CopyResources() " Set call UnloadVimwiki() let wiki = {} @@ -52,7 +51,7 @@ Execute (VimWei vars #980): bprevious Log 'Path (Current): ' . getcwd() Log 'File (Buffer):' . @% - bdelete index.md + bwipeout index.md " Clean Log 'Clean up' diff --git a/test/file_goto.vader b/test/file_goto.vader index e46f619..6c1397a 100644 --- a/test/file_goto.vader +++ b/test/file_goto.vader @@ -5,11 +5,6 @@ # So I used C-L -Execute (Copy Wiki's Resources): - Log "Start: Copy Resources" - call CopyResources() - - Execute (VimwikiGoto buzz_bozz && Assert): VimwikiIndex 2 VimwikiGoto buzz_bozz @@ -78,7 +73,6 @@ Execute (:VimwikiGoto + Completion in directory): Execute (Clean): call DeleteFile("$HOME/testmarkdown/dir1/dir2/test_goto_file.md") - call DeleteFile("$HOME/testmarkdown/index.md") call system("rm $HOME/testmarkdown/dir1") # vim: sw=2 foldmethod=indent foldlevel=30 foldignore= diff --git a/test/file_system.vader b/test/file_system.vader index 7c02071..e64cd7e 100644 --- a/test/file_system.vader +++ b/test/file_system.vader @@ -1,10 +1,5 @@ # Travel thought files -Execute (Copy Wiki's Resources): - Log "Start: Copy Resources" - call CopyResources() - - Given (Void for Accessing other files within vimwiki #979 {{{1): @@ -29,7 +24,4 @@ Do (At Index: Create and goto markdownfile): dd :call DeleteFile('mdfile.md')\ -Execute (Clean): - call DeleteFile("$HOME/testmarkdown/index.md") - # vim: sw=2:foldmethod=marker:foldlevel=30:foldignore=: diff --git a/test/html_blockquote.vader b/test/html_blockquote.vader index 7d4a413..a779f33 100644 --- a/test/html_blockquote.vader +++ b/test/html_blockquote.vader @@ -1,9 +1,5 @@ # Blockquotes in html convertion -Execute (Copy Wiki's Resources): - Log "Start: Copy Resources" - call CopyResources() - Given (Void): Execute (Edit TestHtml Wiki): diff --git a/test/html_convert_default.vader b/test/html_convert_default.vader index 049c214..8a09fd3 100644 --- a/test/html_convert_default.vader +++ b/test/html_convert_default.vader @@ -1,9 +1,5 @@ # Conertion: Wiki -> Html -Execute (Copy Wiki's Resources): - Log "Start: Copy Resources" - call CopyResources() - ################################################# Given vimwiki (Comments): This is some text diff --git a/test/html_diary_rss_feed.vader b/test/html_diary_rss_feed.vader index f14e260..83e3600 100644 --- a/test/html_diary_rss_feed.vader +++ b/test/html_diary_rss_feed.vader @@ -1,9 +1,5 @@ # Feature to generate a diray RSS feed (PR #934) -Execute (Copy Wiki's Resources): - Log "Start: Copy Resources" - call CopyResources() - Given (Void): Execute (Generate HTML and RSS feed): @@ -21,8 +17,9 @@ Do (Get HTML file): kdgg # Delete everything below jdG -# Save (Not necessary) - :write +# Save (Not necessary) => Actually make rest of batch freeze, do you really want +# to quit buffer +# :write Expect (RSS link in HTML): @@ -34,7 +31,7 @@ Do (Get RSS feed): # Replace pubDate with dummy as it's based on file modification time :%s@.*@...@g\ # Save (Not necessary) - :write +# :write Expect (RSS): # TODO the next line is deleted with -Es @@ -107,3 +104,6 @@ Expect (RSS): + +Execute (Clean buffer modification): + edit! $HOME/testwiki/index.wiki diff --git a/test/link_generation.vader b/test/link_generation.vader index 31f957a..c361055 100644 --- a/test/link_generation.vader +++ b/test/link_generation.vader @@ -4,9 +4,7 @@ # - buffer list insertion (see: vimwiki#base#update_listing_in_buffer) -Execute (Copy Wiki's Resources): - Log "Start: Copy Resources" - call CopyResources() +Execute (Reset sw to default (due to batch)): set sw=8 # 1 VimwikiGenerateLinks {{{1 @@ -198,7 +196,6 @@ Expect (diary index generated): Execute (Clean): - call DeleteFile("$HOME/testmarkdown/index.md") call DeleteFile('$HOME/testmarkdown/diary/2019-12-10.md') call DeleteFile('$HOME/testmarkdown/diary/2019-07-13.md') call DeleteFile('$HOME/testmarkdown/diary/2019-03-01.md') diff --git a/test/link_renaming.vader b/test/link_renaming.vader index 5686b59..54392d4 100644 --- a/test/link_renaming.vader +++ b/test/link_renaming.vader @@ -6,11 +6,6 @@ # Create directories I remove at end {{{1 ########################################## -Execute (Copy Wiki's Resources): - Log "Start: Copy Resources" - call CopyResources() - - Execute (Mkdir dir1 dir2 dir11 dir12): call system("mkdir $HOME/testmarkdown/dir1") call system("mkdir $HOME/testmarkdown/dir1/dir11") diff --git a/test/independent_runs/map.vader b/test/map.vader similarity index 73% rename from test/independent_runs/map.vader rename to test/map.vader index d8f51ee..e9e937c 100644 --- a/test/independent_runs/map.vader +++ b/test/map.vader @@ -6,63 +6,16 @@ # 0 Configure {{{1 ################## -Execute (Configure: Set vimwiki list to markdown resource): - Log "Let mapleader = ," - let mapleader = ',' - - Log "Destroy vimrc or previous run heritage" - call DestroyVar('g:vimwiki_list') - call DestroyVar('g:vimwiki_global_vars') - call DestroyVar('g:vimwiki_wikilocal_vars') - - Log "Destroy vimrc variable, works better that way" - call DestroyVar('g:vimwiki_default') - call DestroyVar('g:vimwiki_markdown') - call DestroyVar('g:vimwiki_mediawiki') - - Log "Declare my vimwiki_list" - let g:vimwiki_list = [{ - \ 'path': 'test/resources/testmarkdown', - \ 'syntax': 'markdown', - \ 'ext': '.md' - \ }] - - Log "Declare my extension for temporary wiki" - let g:vimwiki_ext2syntax = {'.md': 'markdown'} - - Log "Reload vimwiki" - nmapclear - - " UNlet what can be - for i in ['g:vimwiki_commentstring', - \ 'b:did_ftplugin', - \ 'g:loaded_vimwiki', - \ 'g:vimwiki_global_vars', - \ 'g:vimwiki_wikilocal_vars', - \ 'g:vimwiki_syntaxlocal_vars', - \ ] - if exists(i) - exe 'unlet ' . i - endif - endfor - - " Source plugin: Go - runtime! plugin/vimwiki.vim - -Execute (Assert: 2 wiki in Index): - AssertEqual 2, len(vimwiki_wikilocal_vars) - Execute (VimwikiIndex): - VimwikiIndex 1 + VimwikiIndex 2 AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr') AssertEqual 'vimwiki', &filetype - AssertEqual 'test/resources/testmarkdown/', vimwiki_wikilocal_vars[0]['path'] - AssertEqual 'test/resources/testmarkdown/index.md', expand('%') + AssertEqual $HOME . '/testmarkdown/', vimwiki_wikilocal_vars[0]['path'] + AssertEqual $HOME . 'testmarkdown/index.md', expand('%') Execute (Open buzz bozz): - edit test/resources/testmarkdown/buzz_bozz.md - AssertEqual 'test/resources/testmarkdown/buzz_bozz.md', expand('%') - + edit $HOME/testmarkdown/buzz_bozz.md + AssertEqual $HOME . '/testmarkdown/buzz_bozz.md', expand('%') # 1 Global {{{1 ############### @@ -72,28 +25,28 @@ Execute (===========================================================): Do (,ww -> open index [Assert]): ,ww - :AssertEqual 'test/resources/testmarkdown/index.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/index.md', expand('%') \ :call AssertTab(1) \ Do (,wt -> open index in tab [Assert]): ,wt - :AssertEqual 'test/resources/testmarkdown/index.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/index.md', expand('%') \ :call AssertTab(2) \ Do (,w,w -> open diary [Assert]): ,w,w - :AssertEqual 'test/resources/testmarkdown/diary/' . strftime('%Y-%m-%d') . '.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/diary/' . strftime('%Y-%m-%d') . '.md', expand('%') \ :call AssertTab(1) \ Do (,w,t -> open diary in tab [Assert]): ,w,t - :AssertEqual 'test/resources/testmarkdown/diary/' . strftime('%Y-%m-%d') . '.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/diary/' . strftime('%Y-%m-%d') . '.md', expand('%') \ :call AssertTab(2) \ @@ -102,28 +55,28 @@ Do (,ws -> list and select wiki [Assert]): ,ws 1 \ - :AssertEqual 'test/resources/testmarkdown/index.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/index.md', expand('%') \ :call AssertTab(1) \ Do (,wi -> open diary index [Assert]): ,wi - :AssertEqual 'test/resources/testmarkdown/diary/diary.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/diary/diary.md', expand('%') \ :call AssertTab(1) \ Do (,w,y -> open yesterday [Assert]): ,w,y - :AssertEqual 'test/resources/testmarkdown/diary/' . strftime('%Y-%m-%d', localtime() - 60*60*24) . '.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/diary/' . strftime('%Y-%m-%d', localtime() - 60*60*24) . '.md', expand('%') \ :call AssertTab(1) \ Do (,w,m -> open tomorrow [Assert]): ,wm - :AssertEqual 'test/resources/testmarkdown/diary/' . strftime('%Y-%m-%d', localtime() + 60*60*24) . '.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/diary/' . strftime('%Y-%m-%d', localtime() + 60*60*24) . '.md', expand('%') \ :call AssertTab(1) \ @@ -144,13 +97,13 @@ Do (,wn -> Create new wiki [Assert]): ,wn new_file1 \ - :AssertEqual 'test/resources/testmarkdown/new_file1.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/new_file1.md', expand('%') \ :call AssertTab(1) \ Do (,wd -> Delete wiki yes [Assert]): - :edit 'test/resources/testmarkdown/file_new1.md' + :edit $HOME . '/testmarkdown/file_new1.md' \ ,wn @@ -163,11 +116,11 @@ Do (,wd -> Delete wiki yes [Assert]): yes \ - :AssertEqual 'test/resources/testmarkdown/index.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/index.md', expand('%') \ Do (,wd -> Delete wiki no [Assert]): - :edit 'test/resources/testmarkdown/file_new1.md' + :edit $HOME . '/testmarkdown/file_new1.md' \ ,wn @@ -180,7 +133,7 @@ Do (,wd -> Delete wiki no [Assert]): no \ - :AssertEqual 'test/resources/testmarkdown/new_file2.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/new_file2.md', expand('%') \ Do (,wn -> Rename wiki [Assert]): @@ -194,7 +147,7 @@ Do (,wn -> Rename wiki [Assert]): new_file2 \ - :AssertEqual 'test/resources/testmarkdown/new_file2.md', expand('%') + :AssertEqual $HOME . '/testmarkdown/new_file2.md', expand('%') \ Given (Some headings): diff --git a/test/run_tests.sh b/test/run_tests.sh index 61883ed..2a0d1bb 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -4,8 +4,8 @@ # output function. # Say Hi -echo -en "Starting $(basename $0) for VimWiki\n" -start_time=`date +%s` +echo -en "Starting $(basename "$0") for VimWiki\n" +start_time=$(date +%s) # For windows: Cmder bash is appending busybox to the path and # and a smlll vim is included, so that override the windows path vim @@ -60,23 +60,16 @@ runVader() { # Parse tests files to execute if [[ -z $file_test ]]; then - ind="test/independent_runs/*.vader" res="test/*" else read -ra TEST <<< "$file_test" for i in "${TEST[@]}"; do - if [[ "$i" == "independent_runs/"*"*"* ]]; then - ind="$ind test/${i}" - elif [[ "$i" == *"*"* ]]; then + if [[ "$i" == *"*"* ]]; then res="$res test/${i}" elif [[ -f "$i" ]]; then res="$res test/${i}" elif [[ -f "${i}.vader" ]]; then res="$res test/${i}.vader" - elif [[ -f "independent_runs/${i}" ]]; then - ind="$ind test/independent_runs/${i}" - elif [[ -f "independent_runs/${i}.vader" ]]; then - ind="$ind test/independent_runs/${i}.vader" else printf "WARNING: Test \"%s\" not found.\n", "$i" fi @@ -94,10 +87,10 @@ runVader() { home_save="$HOME" # Create temporary root - mkdir -p $tmp_dir/vader_wiki - mkdir -p $tmp_dir/vader_wiki/home - mkdir -p $tmp_dir/vader_wiki/home/test - mkdir -p $tmp_dir/vader_wiki/testplugin + mkdir -p "$tmp_dir/vader_wiki" + mkdir -p "$tmp_dir/vader_wiki/home" + mkdir -p "$tmp_dir/vader_wiki/home/test" + mkdir -p "$tmp_dir/vader_wiki/testplugin" # Set vars export ROOT="$tmp_dir/vader_wiki/" @@ -127,57 +120,40 @@ runVader() { # flags=(--rm -v "$PWD/../:/testplugin" -v "$PWD/../test:/home" -w /testplugin vimwiki) echo -e "\nCopying resources to $ROOT" # Copy testplugin - cp -rf $wiki_path/* $ROOT/testplugin/ + cp -rf "$wiki_path/"* "$ROOT/testplugin/" # Copy home - cp -rf $script_path/* $HOME/test/ + cp -rf "$script_path/"* "$HOME/test/" # Copy rtp.vim - cp -rf $script_path/resources/rtp_local.vim $ROOT/rtp.vim + cp -rf "$script_path/resources/rtp_local.vim" "$ROOT/rtp.vim" # Copy vader <- internet echo 'Cloning Vader (git, do not care the fatal)' git clone --depth 10 https://github.com/junegunn/vader.vim /tmp/vader_wiki/vader 2>&1 fi # Run batch of tests + # shellcheck disable=SC2086,SC2206 if [[ "$res" != "" ]]; then if [[ "$v" == "local" ]]; then - pushd $tmp_dir/vader_wiki/testplugin + pushd "$tmp_dir/vader_wiki/testplugin" \ + || echo 'Warning pushd testplugin failed' # Run the tests - echo -e "\nStarting Batch Vim/Vader <- $res" - "$vim" $vim_opt "+Vader! ${res}" 2>&1 - ret=${PIPESTATUS[1]}; err=$(( $err + $ret )) + acmd=("$vim" $vim_opt \"+Vader! ${res}\" "2>&1") + echo -e "\nStarting Batch Vim/Vader:\n${acmd[*]}\n<- $res\n" + ${acmd[*]} + ret=${PIPESTATUS[1]}; err=$(( err + ret )) echo -e "\nReturned Batch Vim/Vader -> $ret" - popd + popd \ + || echo 'Warning popd also failed' else # In docker - echo -e "\nStarting Independant Vim/Vader <- $res" - docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${flags[@]}" \ - "$v" $vim_opt "+Vader! ${res}" 2>&1 | vader_filter | vader_color - ret=${PIPESTATUS[1]}; err=$(( $err + $ret )) - echo -e "\nReturned Independant Docker/Vim/Vader -> $ret" - fi - fi - - # Run Tests that must be run in individual vim instances - # see README.md for more information - if [[ "$ind" != "" ]]; then - test_cmd="for VF in ${ind}; do $vim $vim_opt \"+Vader! \$VF\"; done" - if [[ "$v" == "local" ]]; then - pushd $tmp_dir/vader_wiki/testplugin - - echo -e "\nStarting Vim/Vader <- $test_cmd" - bash -c "$test_cmd" 2>&1 - ret=${PIPESTATUS[1]}; err=$(( $err + $ret )) - echo -e "\nReturned Vim/Vader -> $ret" - - popd - else # In docker - echo -e "\nStarting Docker/Vim/Vader <- $test_cmd" - docker run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${flags[@]}" \ - /bin/bash -c "$test_cmd" 2>&1 | vader_filter | vader_color - ret=${PIPESTATUS[1]}; err=$(( $err + $ret )) - echo -e "\nReturned Docker/Vim/Vader -> $ret" + acmd=(docker run -a stderr -e "VADER_OUTPUT_FILE=/dev/stderr" + "${flags[@]}" "$v" $vim_opt \"+Vader! ${res}\" "2>&1") + echo -e "\nStarting Batch Vim/Vader:\n${acmd[*]}\n<- $res\n" + ${acmd[*]} | vader_filter | vader_color + ret=${PIPESTATUS[1]}; err=$(( err + ret )) + echo -e "\nReturned Batch Docker/Vim/Vader -> $ret" fi fi @@ -196,14 +172,16 @@ runVint() { cmd="vint -s . && vint -s test/vimrc" if echo "$vers" | grep "local" > /dev/null; then echo -e "\nRunning Vint: $cmd : in $wiki_path" - pushd $wiki_path > /dev/null + pushd "$wiki_path" > /dev/null \ + || echo 'Warning pushd wiki_path failed' $cmd - err=$(( $err | $? )) - popd > /dev/null + err=$(( err | $? )) + popd > /dev/null \ + || echo 'Warning popd also failed' else echo -e "\nStarting Docker container and running Vint: $cmd" docker run -a stdout "${flags[@]}" bash -c "$cmd" - err=$(( $err | $? )) + err=$(( err | $? )) fi return $err } @@ -287,10 +265,10 @@ vader_color() { } # path of the script, supposing no spaces -script_file="$(dirname $0)" -script_path="$( realpath $script_file )" -wiki_path="$( realpath $script_path/.. )" -tmp_dir=$(dirname $(mktemp -u)) +script_file="$(dirname "$0")" +script_path="$( realpath "$script_file" )" +wiki_path="$( realpath "$script_path/.." )" +tmp_dir="$(dirname "$(mktemp -u)")" # list of vim/nvim versions vers="$(getVers)" @@ -358,20 +336,20 @@ case $type in "vader" ) runVader ; err=$? echo "Main Vader: returned $err" - o_error=$(( $err | $o_error )) + o_error=$(( err | o_error )) ;; "vint" ) runVint ; err=$? echo "Main Vint: returned $err" - o_error=$(( $err | $o_error )) + o_error=$(( err | o_error )) ;; "all" ) runVint ; err=$? echo "Main Vint: returned $err" - o_error=$(( $err | $o_error )) + o_error=$(( err | o_error )) runVader ; err=$? echo "Main Vader: returned $err" - o_error=$(( $err | $o_error )) + o_error=$(( err | o_error )) ;; * ) echo "Error: invalid type - '$type'" 1>&2 @@ -379,10 +357,10 @@ case $type in esac # Calcultate time -end_time=`date +%s` +end_time=$(date +%s) sec_time=$((end_time - start_time)) -printf -v script_time '%dh:%dm:%ds' $(($sec_time/3600)) $(($sec_time%3600/60)) $(($sec_time%60)) +printf -v script_time '%dh:%dm:%ds' $((sec_time/3600)) $((sec_time%3600/60)) $((sec_time%60)) # Exit -echo -ne "Script $(basename $0), in $script_time, Returned -> $o_error\n\n" +echo -ne "Script $(basename "$0"), in $script_time, Returned -> $o_error\n\n" exit $o_error diff --git a/test/independent_runs/search.vader b/test/search.vader similarity index 100% rename from test/independent_runs/search.vader rename to test/search.vader diff --git a/test/tag.vader b/test/tag.vader index d9f08b2..109ecc8 100644 --- a/test/tag.vader +++ b/test/tag.vader @@ -1,10 +1,6 @@ # Tag generation and navigation # Note: The Generate must be in Execute -Execute (Copy Wiki's Resources): - Log "Start: Copy Resources" - call CopyResources() - Execute (Setup): set sw=4 AssertEqual 4, &sw diff --git a/test/vimrc b/test/vimrc index 7505130..4bd9757 100644 --- a/test/vimrc +++ b/test/vimrc @@ -200,7 +200,7 @@ " Write current file: helper to hide `set bt=` function! WriteMe() set buftype= - write % + write! % endfunction " Delete a file <- path @@ -293,4 +293,8 @@ AssertEqual a:one, a:two endfunction + +" Copy Wiki's Resources +call CopyResources() + " vim: ft=vim:sw=2