2019-12-25 13:54:48 +01:00
|
|
|
module main
|
|
|
|
|
2020-04-26 08:32:05 +02:00
|
|
|
import os
|
2020-10-21 14:20:07 +02:00
|
|
|
import time
|
2020-04-26 08:32:05 +02:00
|
|
|
import testing
|
2020-10-21 11:54:03 +02:00
|
|
|
import v.util
|
2019-12-25 13:54:48 +01:00
|
|
|
|
2020-10-21 08:11:09 +02:00
|
|
|
// os.v - // embeded comments, mib := [1/* CTL_KERN */, 14/* KERN_PROC */, 12/* KERN_PROC_PATHNAME */, -1] => comment the rest of the line
|
2019-12-27 17:59:04 +01:00
|
|
|
const (
|
2020-10-14 22:49:12 +02:00
|
|
|
known_failing_exceptions = [
|
2020-10-14 23:39:09 +02:00
|
|
|
'vlib/v/tests/generics_test.v', // struct Repo<T, U> { => struct Repo {
|
2020-10-15 15:17:52 +02:00
|
|
|
'vlib/crypto/aes/aes.v', // pub fn (c &AesCipher) encrypt(mut dst, mut src []byte) {
|
2020-10-14 23:39:09 +02:00
|
|
|
'vlib/crypto/aes/block_generic.v', // fn expand_key_generic(key []byte, mut enc, mut dec []u32) {
|
|
|
|
'vlib/crypto/aes/const.v', // multiple narrow columns of []string turned to 1 long single column, otherwise works
|
|
|
|
'vlib/crypto/rc4/rc4.v', // pub fn (mut c Cipher) xor_key_stream(mut dst, mut src []byte) {
|
|
|
|
'vlib/vweb/vweb.v', // $for method in T.methods { => $for method in T(methods) { , `return // xx` => parse expr error
|
|
|
|
'vlib/v/gen/js/tests/life.v', // error: unexpected `,`, expecting ), on JS.setInterval(fn () { show(game) game = step(game) }, 500)
|
|
|
|
'vlib/builtin/js/builtin.v', // JS.console.error(s) => JS.error(s), JS.process.exit(c) => JS.exit(c)
|
2020-10-15 15:17:52 +02:00
|
|
|
'vlib/builtin/js/jsfns_node.js.v',
|
|
|
|
'vlib/builtin/js/jsfns.js.v',
|
|
|
|
'vlib/builtin/js/jsfns_browser.js.v',
|
2020-10-14 23:39:09 +02:00
|
|
|
'vlib/builtin/bare/linuxsys_bare.v', // error: expr(): bad token `asm`, on `asm {}`
|
2020-10-21 11:23:03 +02:00
|
|
|
'vlib/picoev/picoev.v', // the fn args are removed, then `cb fn (picohttpparser.Request, mut picohttpparser.Response)` can not be reparsed
|
2020-10-21 08:11:09 +02:00
|
|
|
'vlib/os/os.v',
|
2019-12-25 13:54:48 +01:00
|
|
|
]
|
2019-12-27 17:59:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
args := os.args
|
|
|
|
args_string := args[1..].join(' ')
|
|
|
|
v_test_formatting(args_string.all_before('test-fmt'))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn v_test_formatting(vargs string) {
|
|
|
|
all_v_files := v_files()
|
2020-10-21 11:54:03 +02:00
|
|
|
prepare_vfmt_when_needed()
|
2020-02-08 17:01:10 +01:00
|
|
|
testing.eheader('Run "v fmt" over all .v files')
|
2019-12-27 17:59:04 +01:00
|
|
|
mut vfmt_test_session := testing.new_test_session('$vargs fmt -worker')
|
|
|
|
vfmt_test_session.files << all_v_files
|
2020-10-14 22:58:31 +02:00
|
|
|
vfmt_test_session.skip_files << known_failing_exceptions
|
2019-12-25 13:54:48 +01:00
|
|
|
vfmt_test_session.test()
|
2019-12-27 17:59:04 +01:00
|
|
|
eprintln(vfmt_test_session.benchmark.total_message('running vfmt over V files'))
|
2019-12-25 13:54:48 +01:00
|
|
|
if vfmt_test_session.benchmark.nfail > 0 {
|
2020-10-14 22:49:12 +02:00
|
|
|
eprintln('\nWARNING: v fmt failed $vfmt_test_session.benchmark.nfail times.\n')
|
2020-10-14 22:42:30 +02:00
|
|
|
exit(1)
|
2019-12-25 13:54:48 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-27 17:59:04 +01:00
|
|
|
|
|
|
|
fn v_files() []string {
|
2020-04-26 13:49:31 +02:00
|
|
|
mut files_that_can_be_formatted := []string{}
|
2019-12-27 17:59:04 +01:00
|
|
|
all_test_files := os.walk_ext('.', '.v')
|
|
|
|
for tfile in all_test_files {
|
2019-12-28 13:55:53 +01:00
|
|
|
if tfile.starts_with('./vlib/v/cgen/tests') {
|
|
|
|
continue
|
|
|
|
}
|
2019-12-27 17:59:04 +01:00
|
|
|
files_that_can_be_formatted << tfile
|
|
|
|
}
|
|
|
|
return files_that_can_be_formatted
|
|
|
|
}
|
2020-10-21 10:06:15 +02:00
|
|
|
|
|
|
|
fn prepare_vfmt_when_needed() {
|
|
|
|
vexe := os.getenv('VEXE')
|
|
|
|
vroot := os.dir(vexe)
|
|
|
|
vfmtv := os.join_path(vroot, 'cmd', 'tools', 'vfmt.v')
|
2020-10-21 11:54:03 +02:00
|
|
|
if util.should_recompile_tool(vexe, vfmtv) {
|
2020-10-21 14:20:07 +02:00
|
|
|
time.sleep_ms(1001) // TODO: remove this when we can get mtime with a better resolution
|
2020-10-21 11:54:03 +02:00
|
|
|
recompile_file(vexe, vfmtv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn recompile_file(vexe string, file string) {
|
2020-10-21 14:07:57 +02:00
|
|
|
cmd := '$vexe $file'
|
|
|
|
println('recompilation command: $cmd')
|
|
|
|
recompile_result := os.system(cmd)
|
2020-10-21 11:54:03 +02:00
|
|
|
if recompile_result != 0 {
|
|
|
|
eprintln('could not recompile $file')
|
|
|
|
exit(2)
|
2020-10-21 10:06:15 +02:00
|
|
|
}
|
|
|
|
}
|