diff --git a/cmd/tools/vdoc/vdoc.v b/cmd/tools/vdoc/vdoc.v index e941441b09..4a44444b13 100644 --- a/cmd/tools/vdoc/vdoc.v +++ b/cmd/tools/vdoc/vdoc.v @@ -234,7 +234,10 @@ fn (vd &VDoc) get_readme(path string) Readme { } if fname == '' { if path.all_after_last(os.path_separator) == 'src' { - return vd.get_readme(path.all_before_last(os.path_separator)) + next_path := path.all_before_last(os.path_separator) + if next_path != '' && path != next_path && os.is_dir(next_path) { + return vd.get_readme(next_path) + } } return Readme{} } diff --git a/cmd/tools/vdoc/vdoc_test.v b/cmd/tools/vdoc/vdoc_test.v index 9017892ede..f8f272cfc1 100644 --- a/cmd/tools/vdoc/vdoc_test.v +++ b/cmd/tools/vdoc/vdoc_test.v @@ -4,6 +4,8 @@ module main import os import arrays +const vexe_path = @VEXE +const vexe_ = os.quoted_path(vexe_path) const tpath = os.join_path(os.vtmp_dir(), 'vod_test_module') fn testsuite_begin() { @@ -104,3 +106,28 @@ fn test_get_module_list() { // `delta` only contains a `_test.v` file. assert !mod_list.any(it.contains(os.join_path(tpath, 'delta'))) } + +fn test_get_readme_md_src() { + // a special testcase for `src` dir get_readme + // https://github.com/vlang/v/issues/24232 + + os.mkdir('src')! + os.write_file('v.mod', "Module { + name: 'foobar' + description: 'foobar' + version: '0.0.0' + license: 'MIT' + dependencies: [] +} +")! + os.write_file('src/foobar.v', 'module foobar + +// square calculates the second power of `x` +pub fn square(x int) int { + return x * x +} +')! + res := os.execute_opt('${vexe_} doc -m src/ -v') or { panic(err) } + assert res.exit_code == 0 + assert res.output.contains('square') +}