-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v.help: fix
print_help_and_exit
, for sub topics like v fmt --help
…
…, rewrite help.v, and add more tests (vlang#19672)
- Loading branch information
Showing
2 changed files
with
61 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,51 @@ | ||
import os | ||
|
||
const vexe = os.getenv('VEXE') | ||
const vexe = os.quoted_path(@VEXE) | ||
|
||
fn test_help() { | ||
res := os.execute('${os.quoted_path(vexe)} help') | ||
res := os.execute(vexe + ' help') | ||
assert res.exit_code == 0 | ||
assert res.output.starts_with('V is a tool for managing V source code.') | ||
} | ||
|
||
fn test_help_as_short_option() { | ||
res := os.execute('${os.quoted_path(vexe)} -h') | ||
res := os.execute(vexe + ' -h') | ||
assert res.exit_code == 0 | ||
assert res.output.starts_with('V is a tool for managing V source code.') | ||
} | ||
|
||
fn test_help_as_long_option() { | ||
res := os.execute('${os.quoted_path(vexe)} --help') | ||
res := os.execute(vexe + ' --help') | ||
assert res.exit_code == 0 | ||
assert res.output.starts_with('V is a tool for managing V source code.') | ||
} | ||
|
||
fn test_all_help() { | ||
vroot := os.dir(vexe) | ||
topicdir := os.join_path(vroot, 'vlib', 'v', 'help') | ||
mut topics := os.walk_ext(topicdir, '.txt') | ||
|
||
mut items := []string{} | ||
mut delim := '' | ||
|
||
for mut item in topics { | ||
$if windows { | ||
delim = '\\' | ||
} $else { | ||
delim = '/' | ||
} | ||
mut item_rev := item.replace('.txt', '').split(delim).reverse() | ||
item_rev.trim(2) | ||
items << item_rev.reverse() | ||
fn test_all_topics() { | ||
help_dir := os.join_path(@VEXEROOT, 'vlib', 'v', 'help') | ||
topic_paths := os.walk_ext(help_dir, '.txt') | ||
topics := topic_paths.map(os.file_name(it).replace('.txt', '')) | ||
for t in topics { | ||
res := os.execute(vexe + ' help ${t}') | ||
assert res.exit_code == 0, res.output | ||
assert res.output != '' | ||
} | ||
} | ||
|
||
for topic in items { | ||
res := os.execute('${os.quoted_path(vexe)} help ${topic}') | ||
fn test_uknown_topic() { | ||
res := os.execute(vexe + ' help abc') | ||
assert res.exit_code == 1, res.output | ||
assert res.output.starts_with('error: unknown help topic "abc".') | ||
} | ||
|
||
if topic == 'help' { | ||
continue | ||
} | ||
fn test_topics_output() { | ||
res := os.execute(vexe + ' help topics') | ||
assert res.exit_code == 0, res.output | ||
assert res.output != '', res.output | ||
assert !res.output.contains('default') | ||
} | ||
|
||
assert res.exit_code == 0 | ||
assert res.output != '' | ||
} | ||
fn test_topic_sub_help() { | ||
res := os.execute(vexe + ' fmt --help') | ||
assert res.exit_code == 0, res.output | ||
assert res.output != '' | ||
} |