aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/cmd/tools/vdoc/tests
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/old/cmd/tools/vdoc/tests
downloadcli-tools-windows-master.tar.gz
cli-tools-windows-master.tar.bz2
cli-tools-windows-master.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/old/cmd/tools/vdoc/tests')
-rw-r--r--v_windows/v/old/cmd/tools/vdoc/tests/testdata/project1/main.out1
-rw-r--r--v_windows/v/old/cmd/tools/vdoc/tests/testdata/project1/main.v8
-rw-r--r--v_windows/v/old/cmd/tools/vdoc/tests/vdoc_file_test.v72
3 files changed, 81 insertions, 0 deletions
diff --git a/v_windows/v/old/cmd/tools/vdoc/tests/testdata/project1/main.out b/v_windows/v/old/cmd/tools/vdoc/tests/testdata/project1/main.out
new file mode 100644
index 0000000..41b75a2
--- /dev/null
+++ b/v_windows/v/old/cmd/tools/vdoc/tests/testdata/project1/main.out
@@ -0,0 +1 @@
+vdoc: No documentation found for /v/vmaster/cmd/tools/vdoc/tests/testdata/project1/main.v
diff --git a/v_windows/v/old/cmd/tools/vdoc/tests/testdata/project1/main.v b/v_windows/v/old/cmd/tools/vdoc/tests/testdata/project1/main.v
new file mode 100644
index 0000000..1a1b527
--- /dev/null
+++ b/v_windows/v/old/cmd/tools/vdoc/tests/testdata/project1/main.v
@@ -0,0 +1,8 @@
+const (
+ source_root = 'temp'
+)
+
+// funky - comment for function below
+fn funky() {
+ println('hi')
+}
diff --git a/v_windows/v/old/cmd/tools/vdoc/tests/vdoc_file_test.v b/v_windows/v/old/cmd/tools/vdoc/tests/vdoc_file_test.v
new file mode 100644
index 0000000..49a0130
--- /dev/null
+++ b/v_windows/v/old/cmd/tools/vdoc/tests/vdoc_file_test.v
@@ -0,0 +1,72 @@
+import os
+import rand
+import term
+import v.util.vtest
+import v.util.diff
+
+const vexe = @VEXE
+
+const vroot = @VMODROOT
+
+const diff_cmd = find_diff_cmd()
+
+fn find_diff_cmd() string {
+ return diff.find_working_diff_command() or { '' }
+}
+
+fn test_vet() {
+ os.setenv('VCOLORS', 'never', true)
+ os.chdir(vroot)
+ test_dir := 'cmd/tools/vdoc/tests/testdata'
+ main_files := get_main_files_in_dir(test_dir)
+ fails := check_path(vexe, test_dir, main_files)
+ assert fails == 0
+}
+
+fn get_main_files_in_dir(dir string) []string {
+ mut mfiles := os.walk_ext(dir, '.v')
+ mfiles.sort()
+ return mfiles
+}
+
+fn check_path(vexe string, dir string, tests []string) int {
+ mut nb_fail := 0
+ paths := vtest.filter_vtest_only(tests, basepath: vroot)
+ for path in paths {
+ program := path
+ print(path + ' ')
+ res := os.execute('$vexe doc $program')
+ if res.exit_code < 0 {
+ panic(res.output)
+ }
+ mut expected := os.read_file(program.replace('main.v', 'main.out')) or { panic(err) }
+ expected = clean_line_endings(expected)
+ found := clean_line_endings(res.output)
+ if expected != found {
+ println(term.red('FAIL'))
+ println('============')
+ println('expected:')
+ println(expected)
+ println('============')
+ println('found:')
+ println(found)
+ println('============\n')
+ println('diff:')
+ println(diff.color_compare_strings(diff_cmd, rand.ulid(), found, expected))
+ println('============\n')
+ nb_fail++
+ } else {
+ println(term.green('OK'))
+ }
+ }
+ return nb_fail
+}
+
+fn clean_line_endings(s string) string {
+ mut res := s.trim_space()
+ res = res.replace(' \n', '\n')
+ res = res.replace(' \r\n', '\n')
+ res = res.replace('\r\n', '\n')
+ res = res.trim('\n')
+ return res
+}