| 1 | import os |
| 2 | |
| 3 | const vexe = os.quoted_path(@VEXE) |
| 4 | |
| 5 | fn test_help() { |
| 6 | res := os.execute(vexe + ' help') |
| 7 | assert res.exit_code == 0 |
| 8 | assert res.output.starts_with('V is a tool for managing V source code.') |
| 9 | } |
| 10 | |
| 11 | fn test_help_as_short_option() { |
| 12 | res := os.execute(vexe + ' -h') |
| 13 | assert res.exit_code == 0 |
| 14 | assert res.output.starts_with('V is a tool for managing V source code.') |
| 15 | } |
| 16 | |
| 17 | fn test_help_as_long_option() { |
| 18 | res := os.execute(vexe + ' --help') |
| 19 | assert res.exit_code == 0 |
| 20 | assert res.output.starts_with('V is a tool for managing V source code.') |
| 21 | } |
| 22 | |
| 23 | fn test_run_help_text() { |
| 24 | res := os.execute(vexe + ' help') |
| 25 | assert res.exit_code == 0, res.output |
| 26 | assert res.output.contains('executable if V created it for this run.') |
| 27 | assert res.output.contains('Compile and run a V program, keeping the') |
| 28 | assert res.output.contains('executable for reuse.') |
| 29 | } |
| 30 | |
| 31 | fn test_run_topic_mentions_conditional_cleanup() { |
| 32 | res := os.execute(vexe + ' help run') |
| 33 | assert res.exit_code == 0, res.output |
| 34 | assert res.output.contains('If `v run` created the executable for this run') |
| 35 | assert res.output.contains('If the executable already existed before the command') |
| 36 | } |
| 37 | |
| 38 | fn test_all_topics() { |
| 39 | help_dir := os.join_path(@VEXEROOT, 'vlib', 'v', 'help') |
| 40 | topic_paths := os.walk_ext(help_dir, '.txt') |
| 41 | topics := topic_paths.map(os.file_name(it).replace('.txt', '')) |
| 42 | for t in topics { |
| 43 | res := os.execute(vexe + ' help ${t}') |
| 44 | assert res.exit_code == 0, res.output |
| 45 | assert res.output != '' |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | fn test_unknown_topic() { |
| 50 | res := os.execute(vexe + ' help abc') |
| 51 | assert res.exit_code == 1, res.output |
| 52 | assert res.output.starts_with('error: unknown help topic "abc".') |
| 53 | } |
| 54 | |
| 55 | fn test_topics_output() { |
| 56 | res := os.execute(vexe + ' help topics') |
| 57 | assert res.exit_code == 0, res.output |
| 58 | assert res.output != '', res.output |
| 59 | assert !res.output.contains('default') |
| 60 | } |
| 61 | |
| 62 | fn test_topic_sub_help() { |
| 63 | res := os.execute(vexe + ' fmt --help') |
| 64 | assert res.exit_code == 0, res.output |
| 65 | assert res.output != '' |
| 66 | } |
| 67 | |
| 68 | fn test_help_topic_with_cli_mod() { |
| 69 | res := os.execute_or_exit(vexe + ' help init') |
| 70 | assert res.output.contains('Usage: v init [flags]') |
| 71 | assert res.output.contains('Sets up a V project within the current directory.') |
| 72 | assert res.output.contains('Flags:') |
| 73 | assert res.output.contains('--bin Use the template for an executable application [default]') |
| 74 | assert res.output.contains('--lib Use the template for a library project.') |
| 75 | } |
| 76 | |