Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'global' helper to register events globally #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions autoload/themis/helper/global.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
let s:event = {
\ 'globals': [],
\}

function! s:event.start(runner) abort
for global in self.globals
if has_key(global, 'initialize')
call global.initialize()
endif
endfor
endfunction

function! s:event.before_suite(bundle) abort
for global in self.globals
if has_key(global, 'before')
call global.before()
endif
endfor
endfunction

function! s:event.before_test(bundle, entry) abort
for global in self.globals
if has_key(global, 'before_each')
call global.before_each()
endif
endfor
endfunction

function! s:event.end(runner) abort
for global in self.globals
if has_key(global, 'finalize')
call global.finalize()
endif
endfor
endfunction

function! s:event.after_suite(bundle) abort
for global in self.globals
if has_key(global, 'after')
call global.after()
endif
endfor
endfunction

function! s:event.after_test(bundle, entry) abort
for global in self.globals
if has_key(global, 'after_each')
call global.after_each()
endif
endfor
endfunction


let s:helper = {
\ 'event': s:event,
\}

function! s:helper.with(globals) abort
let globals = type(a:globals) == 3 ? a:globals : [a:globals]
call extend(self.event.globals, globals)
return self
endfunction


function! themis#helper#global#new(runner) abort
let helper = deepcopy(s:helper)
call a:runner.add_event(helper.event)
return helper
endfunction
52 changes: 52 additions & 0 deletions doc/themis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,60 @@ scope.funcs({path}) *themis-helper-scope-funcs()*
let s:myfuncs = s:scope.funcs('autoload/myfuncs.vim')
call s:myfuncs.foo() " calls s:foo() in myfuncs.vim

-----------------------------------------------------------------------------
GLOBAL *themis-helper-global*

Global-helper provides a way to register before/after type events globally.
Not like |themis-style-basic-test-name|, events registered with this helper
are registered through the entire tests.

The following special situations are supported.

- initialize()
- This is called before a first test of a first suite
- before()
- This is called before a first test of each suite
- before_each()
- This is called before each test of each suite
- after_each()
- This is called after each test of each suite
- after()
- This is called after a last test of each suite
- finalize()
- This is called after a last test of a last suite

global.with({events}) *themis-helper-global-with()*
Add situations in a {events} dictionary globally.
>
let s:events = {}

function! s:events.initialize() abort
call themis#log('Initialize')
endfunction

function! s:events.before() abort
call themis#log('Before')
endfunction

function! s:events.before_each() abort
call themis#log('Before each')
endfunction

function! s:events.after_each() abort
call themis#log('After each')
endfunction

function! s:events.after() abort
call themis#log('After')
endfunction

function! s:events.finalize() abort
call themis#log('Finalize')
endfunction

" Register global event
call themis#helper('global').with(s:events)
<
==============================================================================
REPORTER *themis-reporter*

Expand Down