mirror of
https://github.com/vlang/v.git
synced 2025-09-15 02:18:47 -04:00
vdoc: cleanup get_module_list
, add unit tests (#21057)
This commit is contained in:
parent
604eb6517f
commit
a6087d01a2
@ -26,19 +26,6 @@ fn get_ignore_paths(path string) ![]string {
|
|||||||
return res.map(it.replace('/', os.path_separator))
|
return res.map(it.replace('/', os.path_separator))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_included(path string, ignore_paths []string) bool {
|
|
||||||
if path == '' {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
for ignore_path in ignore_paths {
|
|
||||||
if !path.contains(ignore_path) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_modules_list(opath string, ignore_paths2 []string) []string {
|
fn get_modules_list(opath string, ignore_paths2 []string) []string {
|
||||||
path := opath.trim_right('/\\')
|
path := opath.trim_right('/\\')
|
||||||
names := os.ls(path) or { return [] }
|
names := os.ls(path) or { return [] }
|
||||||
@ -46,15 +33,11 @@ fn get_modules_list(opath string, ignore_paths2 []string) []string {
|
|||||||
ignore_paths << ignore_paths2
|
ignore_paths << ignore_paths2
|
||||||
mut dirs := map[string]int{}
|
mut dirs := map[string]int{}
|
||||||
for name in names {
|
for name in names {
|
||||||
if name == 'testdata' {
|
if name in ['testdata', 'tests'] {
|
||||||
continue
|
|
||||||
}
|
|
||||||
if name == 'tests' {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fpath := os.join_path(path, name)
|
fpath := os.join_path(path, name)
|
||||||
fmeta := os.inode(fpath)
|
if os.is_dir(fpath) && !ignore_paths.any(fpath.contains(it)) {
|
||||||
if fmeta.typ == .directory && is_included(fpath, ignore_paths) {
|
|
||||||
current_ignore_paths := ignore_paths.filter(it.starts_with(fpath))
|
current_ignore_paths := ignore_paths.filter(it.starts_with(fpath))
|
||||||
for k in get_modules_list(fpath, current_ignore_paths) {
|
for k in get_modules_list(fpath, current_ignore_paths) {
|
||||||
dirs[k]++
|
dirs[k]++
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
module main
|
|
||||||
|
|
||||||
fn test_trim_doc_node_description() {
|
|
||||||
mod := 'foo'
|
|
||||||
mut readme := '## Description
|
|
||||||
|
|
||||||
`foo` is a module that provides tools and utility functions to assist in working with bar.
|
|
||||||
It also assists with composing and testing baz.'
|
|
||||||
expected := 'is a module that provides tools and utility functions to assist in working with'
|
|
||||||
res := trim_doc_node_description(mod, readme).trim_space()
|
|
||||||
assert res == expected
|
|
||||||
|
|
||||||
readme = '# Foo
|
|
||||||
`foo` is a module that provides tools and utility functions to assist in working with bar.
|
|
||||||
It also assists with composing and testing baz.'
|
|
||||||
res2 := trim_doc_node_description(mod, readme).trim_space()
|
|
||||||
assert res2 == res
|
|
||||||
}
|
|
58
cmd/tools/vdoc/vdoc_test.v
Normal file
58
cmd/tools/vdoc/vdoc_test.v
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import os
|
||||||
|
import arrays
|
||||||
|
|
||||||
|
fn test_trim_doc_node_description() {
|
||||||
|
mod := 'foo'
|
||||||
|
mut readme := '## Description
|
||||||
|
|
||||||
|
`foo` is a module that provides tools and utility functions to assist in working with bar.
|
||||||
|
It also assists with composing and testing baz.'
|
||||||
|
expected := 'is a module that provides tools and utility functions to assist in working with'
|
||||||
|
res := trim_doc_node_description(mod, readme).trim_space()
|
||||||
|
assert res == expected
|
||||||
|
|
||||||
|
readme = '# Foo
|
||||||
|
`foo` is a module that provides tools and utility functions to assist in working with bar.
|
||||||
|
It also assists with composing and testing baz.'
|
||||||
|
res2 := trim_doc_node_description(mod, readme).trim_space()
|
||||||
|
assert res2 == res
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_get_module_list() {
|
||||||
|
tpath := os.join_path(os.vtmp_dir(), 'vod_test_module')
|
||||||
|
os.rmdir_all(tpath) or {}
|
||||||
|
os.mkdir_all(tpath)!
|
||||||
|
defer {
|
||||||
|
os.rmdir_all(tpath) or {}
|
||||||
|
}
|
||||||
|
|
||||||
|
os.chdir(tpath)!
|
||||||
|
|
||||||
|
/* Create some submodules.
|
||||||
|
Modules inside `testdata` and `tests` directories and modules that
|
||||||
|
only contain `_test.v` files should be ignored by default. */
|
||||||
|
submodules_no_ignore := ['alpha', 'charly', 'charly/alpha']
|
||||||
|
submodules_to_ignore := ['alpha/bravo', 'bravo', 'tests', 'testdata', 'testdata/echo']
|
||||||
|
for p in arrays.append(submodules_no_ignore, submodules_to_ignore) {
|
||||||
|
os.mkdir(p)!
|
||||||
|
mod_name := p.all_after('/')
|
||||||
|
os.write_file(os.join_path(p, '${mod_name}.v'), 'module ${mod_name}')!
|
||||||
|
}
|
||||||
|
// Create a module that only contains a `_test.v` file.
|
||||||
|
os.mkdir('delta')!
|
||||||
|
os.write_file(os.join_path('delta', 'delta_test.v'), 'module delta')!
|
||||||
|
|
||||||
|
os.write_file('.vdocignore', 'bravo\nalpha/bravo\n')!
|
||||||
|
ignore_paths := get_ignore_paths(tpath)!
|
||||||
|
assert os.join_path(tpath, 'bravo') in ignore_paths
|
||||||
|
assert os.join_path(tpath, 'alpha/bravo') in ignore_paths
|
||||||
|
// Only `bravo` modules are part of `.vdocignore`. Ensure that no others are ignored.
|
||||||
|
assert ignore_paths.all(it.contains('bravo'))
|
||||||
|
|
||||||
|
// `get_modules_list` uses `get_ignore_paths` internally.
|
||||||
|
mod_list := get_modules_list(tpath, []string{})
|
||||||
|
assert mod_list.len == submodules_no_ignore.len
|
||||||
|
assert mod_list.all(it.contains('alpha') || it.contains('charly')), mod_list.str()
|
||||||
|
}
|
@ -84,7 +84,7 @@ const essential_list = [
|
|||||||
]
|
]
|
||||||
const skip_test_files = [
|
const skip_test_files = [
|
||||||
'do_not_remove',
|
'do_not_remove',
|
||||||
'cmd/tools/vdoc/utils_test.v', // markdown not installed
|
'cmd/tools/vdoc/vdoc_test.v', // markdown not installed
|
||||||
'vlib/context/deadline_test.v', // sometimes blocks
|
'vlib/context/deadline_test.v', // sometimes blocks
|
||||||
'vlib/context/onecontext/onecontext_test.v', // backtrace_symbols is missing
|
'vlib/context/onecontext/onecontext_test.v', // backtrace_symbols is missing
|
||||||
'vlib/db/mysql/mysql_orm_test.v', // mysql not installed
|
'vlib/db/mysql/mysql_orm_test.v', // mysql not installed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user