Skip to content

Commit

Permalink
Merge branch 'update-coding-rule' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
thinca committed Nov 23, 2020
2 parents 91669b1 + 126a51c commit 922f81b
Show file tree
Hide file tree
Showing 38 changed files with 475 additions and 602 deletions.
33 changes: 13 additions & 20 deletions autoload/themis.vim
Expand Up @@ -2,9 +2,6 @@
" Author : thinca <thinca+vim@gmail.com>
" License: zlib License

let s:save_cpo = &cpo
set cpo&vim

" If user makes a typo such as "themis#sutie()",
" this script will be reloaded. Then the following error occurs.
" E127: Cannot redefine function themis#run: It is in use
Expand All @@ -17,11 +14,11 @@ let g:themis#vital = vital#themis#new()

let s:version = '1.5.5'

function! themis#version() abort
function themis#version() abort
return s:version
endfunction

function! themis#run(paths, ...) abort
function themis#run(paths, ...) abort
let s:current_runner = themis#runner#new()
try
let options = get(a:000, 0, themis#option#empty_options())
Expand All @@ -33,30 +30,30 @@ endfunction

" -- Utilities for test

function! s:runner() abort
function s:runner() abort
if !exists('s:current_runner')
throw 'themis: Test is not running.'
endif
return s:current_runner
endfunction

function! themis#bundle(title) abort
function themis#bundle(title) abort
let base_bundle = s:runner().get_loading_bundle()
let new_bundle = themis#bundle#new(a:title)
call base_bundle.add_child(new_bundle)
return new_bundle
endfunction

function! themis#suite(...) abort
function themis#suite(...) abort
let title = get(a:000, 0, '')
return themis#bundle(title).suite
endfunction

function! themis#helper(name) abort
function themis#helper(name) abort
return themis#helper#{a:name}#new(s:runner())
endfunction

function! themis#option(...) abort
function themis#option(...) abort
if !exists('s:custom_options')
let s:custom_options = themis#option#default()
endif
Expand All @@ -77,20 +74,20 @@ function! themis#option(...) abort
endif
endfunction

function! themis#func_alias(dict) abort
function themis#func_alias(dict) abort
call themis#util#func_alias(a:dict, [])
endfunction

function! themis#exception(type, message) abort
function themis#exception(type, message) abort
return printf('themis: %s: %s', a:type, themis#message(a:message))
endfunction

function! themis#log(expr, ...) abort
function themis#log(expr, ...) abort
let mes = themis#message(a:expr) . "\n"
call call('themis#logn', [mes] + a:000)
endfunction

function! themis#logn(expr, ...) abort
function themis#logn(expr, ...) abort
let string = themis#message(a:expr)
if !empty(a:000)
let string = call('printf', [string] + a:000)
Expand All @@ -104,18 +101,14 @@ function! themis#logn(expr, ...) abort
endif
endfunction

function! themis#message(expr) abort
function themis#message(expr) abort
let t = type(a:expr)
return
\ t == type('') ? a:expr :
\ t == type([]) ? join(map(copy(a:expr), 'themis#message(v:val)'), "\n") :
\ string(a:expr)
endfunction

function! themis#failure(expr) abort
function themis#failure(expr) abort
return 'themis: report: failure: ' . themis#message(a:expr)
endfunction


let &cpo = s:save_cpo
unlet s:save_cpo
47 changes: 20 additions & 27 deletions autoload/themis/bundle.vim
Expand Up @@ -2,33 +2,30 @@
" Author : thinca <thinca+vim@gmail.com>
" License: zlib License

let s:save_cpo = &cpo
set cpo&vim

let s:Bundle = {
\ 'suite': {},
\ 'suite_descriptions': {},
\ 'children': [],
\ }

function! s:Bundle.get_title() abort
function s:Bundle.get_title() abort
return get(self, 'title', '')
endfunction

function! s:Bundle.get_test_full_title(entry) abort
function s:Bundle.get_test_full_title(entry) abort
return themis#util#get_full_title(self, [self.get_test_title(a:entry)])
endfunction

function! s:Bundle.get_test_title(entry) abort
function s:Bundle.get_test_title(entry) abort
let description = self.get_description(a:entry)
return description !=# '' ? description : a:entry
endfunction

function! s:Bundle.get_description(entry) abort
function s:Bundle.get_description(entry) abort
return get(self.suite_descriptions, a:entry, '')
endfunction

function! s:Bundle.get_style() abort
function s:Bundle.get_style() abort
if has_key(self, 'style')
return self.style
endif
Expand All @@ -38,23 +35,23 @@ function! s:Bundle.get_style() abort
return {}
endfunction

function! s:Bundle.has_parent() abort
function s:Bundle.has_parent() abort
return has_key(self, 'parent')
endfunction

function! s:Bundle.get_parent() abort
function s:Bundle.get_parent() abort
return get(self, 'parent', {})
endfunction

function! s:Bundle.add_child(bundle) abort
function s:Bundle.add_child(bundle) abort
if has_key(a:bundle, 'parent')
call a:bundle.parent.remove_child(a:bundle)
endif
let self.children += [a:bundle]
let a:bundle.parent = self
endfunction

function! s:Bundle.get_child(title) abort
function s:Bundle.get_child(title) abort
for child in self.children
if child.title ==# a:title
return child
Expand All @@ -63,7 +60,7 @@ function! s:Bundle.get_child(title) abort
return {}
endfunction

function! s:Bundle.remove_child(child) abort
function s:Bundle.remove_child(child) abort
for i in range(len(self.children))
if self.children[i] is a:child
call remove(a:child, 'parent')
Expand All @@ -73,53 +70,53 @@ function! s:Bundle.remove_child(child) abort
endfor
endfunction

function! s:Bundle.total_test_count() abort
function s:Bundle.total_test_count() abort
return len(self.get_test_entries())
\ + s:sum(map(copy(self.children), 'v:val.total_test_count()'))
endfunction

function! s:Bundle.get_test_entries() abort
function s:Bundle.get_test_entries() abort
if !has_key(self, 'test_entries')
let self.test_entries = self.all_test_entries()
endif
return self.test_entries
endfunction

function! s:Bundle.select_tests_recursive(pattern) abort
function s:Bundle.select_tests_recursive(pattern) abort
for child in self.children
call child.select_tests_recursive(a:pattern)
endfor
call self.select_tests(a:pattern)
return !self.is_empty()
endfunction

function! s:Bundle.select_tests(pattern) abort
function s:Bundle.select_tests(pattern) abort
let test_entries = self.all_test_entries()
call filter(test_entries, 'self.get_test_full_title(v:val) =~# a:pattern')
let self.test_entries = test_entries
endfunction

function! s:Bundle.all_test_entries() abort
function s:Bundle.all_test_entries() abort
let style = self.get_style()
if empty(style)
return []
endif
return style.get_test_names(self)
endfunction

function! s:Bundle.is_empty() abort
function s:Bundle.is_empty() abort
return self.total_test_count() == 0
endfunction

function! s:Bundle.run_test(entry) abort
function s:Bundle.run_test(entry) abort
call self.suite[a:entry]()
endfunction

function! s:sum(list) abort
function s:sum(list) abort
return empty(a:list) ? 0 : eval(join(a:list, '+'))
endfunction

function! themis#bundle#new(...) abort
function themis#bundle#new(...) abort
let bundle = deepcopy(s:Bundle)
let bundle.title = 1 <= a:0 ? a:1 : ''
if 2 <= a:0 && has_key(a:2, 'add_child')
Expand All @@ -128,13 +125,9 @@ function! themis#bundle#new(...) abort
return bundle
endfunction

function! themis#bundle#is_bundle(obj) abort
function themis#bundle#is_bundle(obj) abort
return type(a:obj) == type({}) &&
\ get(a:obj, 'run_test') is get(s:Bundle, 'run_test')
endfunction

call themis#func_alias({'themis/Bundle': s:Bundle})


let &cpo = s:save_cpo
unlet s:save_cpo
30 changes: 12 additions & 18 deletions autoload/themis/command.vim
Expand Up @@ -2,10 +2,7 @@
" Author : thinca <thinca+vim@gmail.com>
" License: zlib License

let s:save_cpo = &cpo
set cpo&vim

function! themis#command#start(args) abort
function themis#command#start(args) abort
let [paths, options] = s:parse_args(a:args)
if get(options, 'exit', 0)
return
Expand All @@ -24,7 +21,7 @@ let s:short_options = {
\ 'r': 'recursive',
\ 'v': 'version',
\ }
function! s:parse_args(args) abort
function s:parse_args(args) abort
let paths = []
let options = themis#option#empty_options()
let args = copy(a:args)
Expand All @@ -47,49 +44,49 @@ function! s:parse_args(args) abort
endfunction

let s:options = {}
function! s:options.exclude(args, options) abort
function s:options.exclude(args, options) abort
if empty(a:args)
throw 'themis: --exclude option requires {pattern}'
endif
let a:options.exclude += [remove(a:args, 0)]
endfunction

function! s:options.target(args, options) abort
function s:options.target(args, options) abort
if empty(a:args)
throw 'themis: --target option requires {pattern}'
endif
let a:options.target += [remove(a:args, 0)]
endfunction

function! s:options.recursive(args, options) abort
function s:options.recursive(args, options) abort
let a:options.recursive = 1
endfunction

function! s:options.reporter(args, options) abort
function s:options.reporter(args, options) abort
if empty(a:args)
throw 'themis: --reporter option requires {name}'
endif
let a:options.reporter = remove(a:args, 0)
endfunction

function! s:options.reporter_list(args, options) abort
function s:options.reporter_list(args, options) abort
let reporters = themis#module#list('reporter')
call themis#log(join(reporters, "\n"))
let a:options.exit = 1
endfunction

function! s:options.runtimepath(args, options) abort
function s:options.runtimepath(args, options) abort
if empty(a:args)
throw 'themis: --runtime option requires {path}'
endif
let a:options.runtimepath += [remove(a:args, 0)]
endfunction

function! s:options.debug(args, options) abort
function s:options.debug(args, options) abort
let $THEMIS_DEBUG = 1
endfunction

function! s:options.help(args, options) abort
function s:options.help(args, options) abort
" TODO: automate options
call themis#log(join([
\ 'themis: A testing framework for Vim script.',
Expand All @@ -107,12 +104,12 @@ function! s:options.help(args, options) abort
let a:options.exit = 1
endfunction

function! s:options.version(args, options) abort
function s:options.version(args, options) abort
call themis#log('themis version ' . themis#version())
let a:options.exit = 1
endfunction

function! s:process_option(name, args, options) abort
function s:process_option(name, args, options) abort
let name = substitute(a:name, '-', '_', 'g')
if has_key(s:options, name)
call s:options[name](a:args, a:options)
Expand All @@ -121,6 +118,3 @@ function! s:process_option(name, args, options) abort
throw 'themis: Unknown option: --' . a:name
endif
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo

0 comments on commit 922f81b

Please sign in to comment.