Skip to content

Commit

Permalink
Added simple tests to catch dumb breakage before releases
Browse files Browse the repository at this point in the history
  • Loading branch information
junkblocker committed Nov 11, 2013
1 parent 3f15c0a commit 2d64a28
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Makefile
@@ -0,0 +1,6 @@
.PHONY: all
.DEFAULT: all

all:
vim -U NONE -u test/test.vim
@echo "Done."
17 changes: 10 additions & 7 deletions autoload/patchreview.vim
@@ -1,14 +1,17 @@
" VIM plugin for doing single, multi-patch or diff code reviews {{{
" Home: http://www.vim.org/scripts/script.php?script_id=1563

" Version : 1.0.9 {{{
" Version : 1.1.0 {{{
" Author : Manpreet Singh < junkblocker@yahoo.com >
" Copyright : 2006-2013 by Manpreet Singh
" License : This file is placed in the public domain.
" No warranties express or implied. Use at your own risk.
"
" Changelog : {{{
"
" 1.1.0 - Added option to open diffs on the right
" - Added some basic tests (internal)
"
" 1.0.9 - Commented lines left uncommented
"
" 1.0.8 - Fix embarassing breakage
Expand Down Expand Up @@ -357,7 +360,7 @@ function! s:temp_name() "{{{
return l:temp_file_name
endfunction
" }}}
function! s:get_patchfile_lines(patchfile) " {{{
function! patchreview#get_patchfile_lines(patchfile) " {{{
"
" Throws: "File " . a:patchfile . " is not readable"
"
Expand Down Expand Up @@ -386,7 +389,7 @@ function! s:me.generate_diff(shell_escaped_cmd) "{{{
return l:diff
endfunction
" }}}
function! s:extract_diffs(lines, default_strip_count) "{{{
function! patchreview#extract_diffs(lines, default_strip_count) "{{{
" Sets g:patches = {'fail':'', 'patch':[
" {
" 'filename': filepath
Expand Down Expand Up @@ -733,7 +736,7 @@ function! patchreview#patchreview(...) "{{{
call s:wipe_message_buffer()
let s:reviewmode = 'patch'
try
let l:lines = s:get_patchfile_lines(a:1)
let l:lines = patchreview#get_patchfile_lines(a:1)
call s:generic_review([l:lines] + a:000[1:])
catch /.*/
call s:me.buflog('ERROR: ' . v:exception)
Expand Down Expand Up @@ -772,7 +775,7 @@ function! patchreview#reverse_patchreview(...) "{{{
call s:wipe_message_buffer()
let s:reviewmode = 'rpatch'
try
let l:lines = s:get_patchfile_lines(a:1)
let l:lines = patchreview#get_patchfile_lines(a:1)
call s:generic_review([l:lines] + a:000[1:])
catch /.*/
call s:me.buflog('ERROR: ' . v:exception)
Expand Down Expand Up @@ -915,7 +918,7 @@ function! s:generic_review(argslist) "{{{
call s:me.buflog('Fatal internal error in patchreview.vim plugin')
endif
try
call s:extract_diffs(l:patchlines, l:defsc)
call patchreview#extract_diffs(l:patchlines, l:defsc)
catch
call s:me.buflog('Exception ' . v:exception)
call s:me.buflog('From ' . v:throwpoint)
Expand Down Expand Up @@ -1235,7 +1238,7 @@ function! patchreview#diff_review(...) " {{{
return
endif
let s:reviewmode = 'diff'
let l:lines = s:get_patchfile_lines(l:outfile)
let l:lines = patchreview#get_patchfile_lines(l:outfile)
call s:generic_review([l:lines, l:strip_count])
else " :DiffReview
call s:init_diff_modules()
Expand Down
130 changes: 130 additions & 0 deletions test/test.vim
@@ -0,0 +1,130 @@
" Some simple tests suited to my setup.
set nocompatible

" Uses thinca/vim-prettyprint to dump information if available.

function! s:dump(something)
if exists(":PP")
echomsg PP(a:something)
endif
endfunction

unlet! s:mess
redir => s:mess
try
exe 'set runtimepath=' . expand("%:p:h")
exe 'set runtimepath+=' . expand("~/.vim/bundle/prettyprint")

set verbose=1
runtime plugin/patchreview.vim
runtime plugin/prettyprint.vim
set verbose=0

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" argument checking is not broken
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
try
PatchReview
echomsg 'Arguments check failed.'
catch /^Vim:E471:\s*Argument required:\s*PatchReview/
echomsg 'Arguments check passed.'
catch /.*/
echomsg 'Arguments check failed. Unexpected error: ' . v:exception
endtry

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Check patch parsing is not broken
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:test_parse(patchfile, expected_parse)
unlet! g:patches
let l:patchlines = patchreview#get_patchfile_lines(a:patchfile)
call patchreview#extract_diffs(l:patchlines, 0)
if g:patches !=# a:expected_parse
echomsg "Parsing" a:patchfile "failed."
call s:dump(g:patches)
else
echomsg "Parsing" a:patchfile "succeeded."
endif
endfunction

call s:test_parse('test/test1.patch', {
\ 'fail': '',
\ 'patch': [
\ {
\ 'content': [
\ '--- a/x',
\ '+++ b/x',
\ '@@ -1,7 +1,7 @@',
\ ' foo',
\ ' bar',
\ ' ',
\ '-fubar',
\ '+foobar',
\ ' baz',
\ ' quux',
\ ' hoge',
\ '@@ -9,6 +9,9 @@',
\ ' a',
\ ' b',
\ ' c',
\ '+d',
\ '+e',
\ '+f',
\ ' g',
\ ' h',
\ ' i'
\ ],
\ 'filename': 'a/x',
\ 'type': '!'
\ }
\ ]
\ })

call s:test_parse('test/test2.patch', {
\ 'fail': '',
\ 'patch': [
\ {
\ 'content': [
\ '*** ../a/b 2013-06-29 13:22:22.000000000 +0800',
\ '--- a/b 2013-10-12 20:22:22.000000000 +0800',
\ '***************',
\ '*** 1,4 ****',
\ '! " stuff.',
\ ' ',
\ ' foo',
\ ' bar',
\ '--- 1,4 ----',
\ '! other stuff',
\ ' ',
\ ' foo',
\ ' bar'
\ ],
\ 'filename': '../a/b',
\ 'type': '!'
\ },
\ {
\ 'content': [
\ '*** ../k/x/y 2013-00-01 12:36:90.000000000 +0800',
\ '--- x/y 2013-00-02 00:13:04.000000000 +0100',
\ '***************',
\ '*** 740,741 ****',
\ '--- 740,743 ----',
\ ' { /* Add new patch number below this line */',
\ '+ /**/',
\ '+ 53,',
\ ' /**/'
\ ],
\ 'filename': '../k/x/y',
\ 'type': '!'
\ }
\ ]
\ })

finally
echomsg 'All done.'
redir END
$put =s:mess
redraw!
setlocal nomodified nomodifiable
endtry
" vim: set et fdm=manual fenc=utf-8 ff=unix ft=vim sts=0 sw=2 ts=2 tw=79 nowrap :
23 changes: 23 additions & 0 deletions test/test1.patch
@@ -0,0 +1,23 @@
diff --git a/x b/x
index 5d361ad..33757f0 100644
--- a/x
+++ b/x
@@ -1,7 +1,7 @@
foo
bar

-fubar
+foobar
baz
quux
hoge
@@ -9,6 +9,9 @@
a
b
c
+d
+e
+f
g
h
i
30 changes: 30 additions & 0 deletions test/test2.patch
@@ -0,0 +1,30 @@
cruft
more cruft
------------

*** ../a/b 2013-06-29 13:22:22.000000000 +0800
--- a/b 2013-10-12 20:22:22.000000000 +0800
***************
*** 1,4 ****
! " stuff.

foo
bar
--- 1,4 ----
! other stuff

foo
bar
*** ../k/x/y 2013-00-01 12:36:90.000000000 +0800
--- x/y 2013-00-02 00:13:04.000000000 +0100
***************
*** 740,741 ****
--- 740,743 ----
{ /* Add new patch number below this line */
+ /**/
+ 53,
/**/

cruft at the end

and some more

0 comments on commit 2d64a28

Please sign in to comment.