@@ -21,6 +21,7 @@ const (
2121 hide_warnings = '-hide-warnings' in os.args || '-w' in os.args
2222 show_progress = os.getenv ('GITHUB_JOB' ) == '' && '-silent' ! in os.args
2323 non_option_args = cmdline.only_non_options (os.args[2 ..])
24+ is_verbose = os.getenv ('VERBOSE' ) != ''
2425)
2526
2627struct CheckResult {
@@ -75,7 +76,7 @@ fn main() {
7576 res + = mdfile.check ()
7677 }
7778 if res.errors == 0 && show_progress {
78- term. clear_previous_line ()
79+ clear_previous_line ()
7980 }
8081 if res.warnings > 0 || res.errors > 0 || res.oks > 0 {
8182 println ('\n Warnings: $res.warnings | Errors: $res.errors | OKs: $res.oks ' )
@@ -131,9 +132,7 @@ fn eline(file_path string, lnumber int, column int, message string) string {
131132 return btext ('$file_path :${lnumber + 1} :${column + 1} :' ) + btext (rtext (' error: $message ' ))
132133}
133134
134- const (
135- default_command = 'compile'
136- )
135+ const default_command = 'compile'
137136
138137struct VCodeExample {
139138mut :
160159
161160fn (mut f MDFile) progress (message string ) {
162161 if show_progress {
163- term. clear_previous_line ()
162+ clear_previous_line ()
164163 println ('File: ${f.path:-30s} , Lines: ${f.lines.len:5} , $message ' )
165164 }
166165}
@@ -394,6 +393,7 @@ fn (mut f MDFile) debug() {
394393}
395394
396395fn cmdexecute (cmd string ) int {
396+ verbose_println (cmd)
397397 res := os.execute (cmd)
398398 if res.exit_code < 0 {
399399 return 1
@@ -405,6 +405,7 @@ fn cmdexecute(cmd string) int {
405405}
406406
407407fn silent_cmdexecute (cmd string ) int {
408+ verbose_println (cmd)
408409 res := os.execute (cmd)
409410 return res.exit_code
410411}
@@ -426,6 +427,7 @@ fn (mut f MDFile) check_examples() CheckResult {
426427 }
427428 fname := os.base (f.path).replace ('.md' , '_md' )
428429 uid := rand.ulid ()
430+ cfile := os.join_path (os.temp_dir (), '${uid} .c' )
429431 vfile := os.join_path (os.temp_dir (), 'check_${fname} _example_${e.sline} __${e.eline} __${uid} .v' )
430432 mut should_cleanup_vfile := true
431433 // eprintln('>>> checking example $vfile ...')
@@ -438,8 +440,7 @@ fn (mut f MDFile) check_examples() CheckResult {
438440 fmt_res := if nofmt { 0 } else { get_fmt_exit_code (vfile, vexe) }
439441 match command {
440442 'compile' {
441- res := cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors -o x.c ${os.quoted_path(vfile)} ' )
442- os.rm ('x.c' ) or {}
443+ res := cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors ${os.quoted_path(vfile)} ' )
443444 if res != 0 || fmt_res != 0 {
444445 if res != 0 {
445446 eprintln (eline (f.path, e.sline, 0 , 'example failed to compile' ))
@@ -454,9 +455,26 @@ fn (mut f MDFile) check_examples() CheckResult {
454455 }
455456 oks++
456457 }
458+ 'cgen' {
459+ res := cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)} ' )
460+ os.rm (cfile) or {}
461+ if res != 0 || fmt_res != 0 {
462+ if res != 0 {
463+ eprintln (eline (f.path, e.sline, 0 , 'example failed to generate C code' ))
464+ }
465+ if fmt_res != 0 {
466+ eprintln (eline (f.path, e.sline, 0 , 'example is not formatted' ))
467+ }
468+ eprintln (vcontent)
469+ should_cleanup_vfile = false
470+ errors++
471+ continue
472+ }
473+ oks++
474+ }
457475 'globals' {
458- res := cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors -enable-globals -o x.c ${os.quoted_path(vfile)} ' )
459- os.rm ('x.c' ) or {}
476+ res := cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors -enable-globals -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)} ' )
477+ os.rm (cfile ) or {}
460478 if res != 0 || fmt_res != 0 {
461479 if res != 0 {
462480 eprintln (eline (f.path, e.sline, 0 , '`example failed to compile with -enable-globals' ))
@@ -472,7 +490,8 @@ fn (mut f MDFile) check_examples() CheckResult {
472490 oks++
473491 }
474492 'live' {
475- res := cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors -live -o x.c ${os.quoted_path(vfile)} ' )
493+ res := cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors -live -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)} ' )
494+ os.rm (cfile) or {}
476495 if res != 0 || fmt_res != 0 {
477496 if res != 0 {
478497 eprintln (eline (f.path, e.sline, 0 , 'example failed to compile with -live' ))
@@ -488,8 +507,8 @@ fn (mut f MDFile) check_examples() CheckResult {
488507 oks++
489508 }
490509 'failcompile' {
491- res := silent_cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors -o x.c ${os.quoted_path(vfile)} ' )
492- os.rm ('x.c' ) or {}
510+ res := silent_cmdexecute ('${os.quoted_path(vexe)} -w -Wfatal-errors -o ${os.quoted_path(cfile)} ${os.quoted_path(vfile)} ' )
511+ os.rm (cfile ) or {}
493512 if res == 0 || fmt_res != 0 {
494513 if res == 0 {
495514 eprintln (eline (f.path, e.sline, 0 , '`failcompile` example compiled' ))
@@ -533,7 +552,7 @@ fn (mut f MDFile) check_examples() CheckResult {
533552 }
534553 'nofmt' {}
535554 else {
536- eprintln (eline (f.path, e.sline, 0 , 'unrecognized command: "$command ", use one of: wip/ignore/compile/failcompile/oksyntax/badsyntax' ))
555+ eprintln (eline (f.path, e.sline, 0 , 'unrecognized command: "$command ", use one of: wip/ignore/compile/cgen/ failcompile/oksyntax/badsyntax/nofmt ' ))
537556 should_cleanup_vfile = false
538557 errors++
539558 }
@@ -548,3 +567,16 @@ fn (mut f MDFile) check_examples() CheckResult {
548567 oks: oks
549568 }
550569}
570+
571+ fn verbose_println (message string ) {
572+ if is_verbose {
573+ println (message)
574+ }
575+ }
576+
577+ fn clear_previous_line () {
578+ if is_verbose {
579+ return
580+ }
581+ term.clear_previous_line ()
582+ }
0 commit comments