mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ensure that v fmt
can be run over most .v files on each PR
This commit is contained in:
parent
ccb041c831
commit
1d86f4b5d1
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
@ -2,6 +2,23 @@ name: CI
|
|||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
|
v-fmt:
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: getting all branch metainfo from github
|
||||||
|
run: |
|
||||||
|
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
|
||||||
|
echo "Changed files compared to origin/master are:" && git diff --name-status origin/master HEAD -- '*.v'
|
||||||
|
- name: Build v (there is no need for dependencies for fmt)
|
||||||
|
run: make -j4
|
||||||
|
- name: Build a production tools/vfmt
|
||||||
|
run: ./v -prod -d vfmt tools/vfmt.v
|
||||||
|
- name: fmt only the changed files (from master)
|
||||||
|
run: git diff --name-status origin/master HEAD -- '*.v' |grep -v '^D'|cut -f2- | xargs ./v fmt -diff
|
||||||
|
- name: Run v test-fmt
|
||||||
|
run: ./v test-fmt
|
||||||
|
|
||||||
ubuntu-tcc:
|
ubuntu-tcc:
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-18.04
|
||||||
env:
|
env:
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,6 +12,7 @@ fns.txt
|
|||||||
/tools/vrepl
|
/tools/vrepl
|
||||||
/tools/vtest
|
/tools/vtest
|
||||||
/tools/vtest-compiler
|
/tools/vtest-compiler
|
||||||
|
/tools/vtest-fmt
|
||||||
/tools/vfmt
|
/tools/vfmt
|
||||||
/tools/vup
|
/tools/vup
|
||||||
/tools/vpm
|
/tools/vpm
|
||||||
@ -26,6 +27,7 @@ fns.txt
|
|||||||
/v_prod_g
|
/v_prod_g
|
||||||
*.exe
|
*.exe
|
||||||
*.o
|
*.o
|
||||||
|
*.so
|
||||||
.*.c
|
.*.c
|
||||||
*.tmp.c
|
*.tmp.c
|
||||||
vjs
|
vjs
|
||||||
|
@ -17,21 +17,13 @@ fn main() {
|
|||||||
v_test_compiler(args_string.all_before('test-compiler'))
|
v_test_compiler(args_string.all_before('test-compiler'))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn v_test_compiler(vargs string){
|
fn v_test_compiler(vargs string) {
|
||||||
v_test_compiler2(vargs)
|
|
||||||
//make_sure_vfmt_was_run()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn v_test_compiler2(vargs string){
|
|
||||||
|
|
||||||
vexe := testing.vexe_path()
|
vexe := testing.vexe_path()
|
||||||
parent_dir := filepath.dir(vexe)
|
parent_dir := filepath.dir(vexe)
|
||||||
testing.vlib_should_be_present( parent_dir )
|
testing.vlib_should_be_present(parent_dir)
|
||||||
|
|
||||||
// Changing the current directory is needed for some of the compiler tests,
|
// Changing the current directory is needed for some of the compiler tests,
|
||||||
// compiler/tests/local_test.v and compiler/tests/repl/repl_test.v
|
// compiler/tests/local_test.v and compiler/tests/repl/repl_test.v
|
||||||
os.chdir( parent_dir )
|
os.chdir(parent_dir)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if !os.exists(parent_dir + '/v.v') {
|
if !os.exists(parent_dir + '/v.v') {
|
||||||
eprintln('v.v is missing, it must be next to the V executable')
|
eprintln('v.v is missing, it must be next to the V executable')
|
||||||
@ -50,22 +42,16 @@ fn v_test_compiler2(vargs string){
|
|||||||
eprintln('v.c can be compiled without warnings. This is good :)')
|
eprintln('v.c can be compiled without warnings. This is good :)')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
building_tools_failed := testing.v_build_failing(vargs, 'tools')
|
building_tools_failed := testing.v_build_failing(vargs, 'tools')
|
||||||
|
|
||||||
eprintln('\nTesting all _test.v files...')
|
eprintln('\nTesting all _test.v files...')
|
||||||
mut compiler_test_session := testing.new_test_session( vargs )
|
mut compiler_test_session := testing.new_test_session(vargs)
|
||||||
compiler_test_session.files << os.walk_ext(parent_dir, '_test.v')
|
compiler_test_session.files << os.walk_ext(parent_dir, '_test.v')
|
||||||
compiler_test_session.test()
|
compiler_test_session.test()
|
||||||
eprintln( compiler_test_session.benchmark.total_message('running V tests') )
|
eprintln(compiler_test_session.benchmark.total_message('running V tests'))
|
||||||
|
|
||||||
eprintln('')
|
eprintln('')
|
||||||
building_examples_failed := testing.v_build_failing(vargs, 'examples')
|
building_examples_failed := testing.v_build_failing(vargs, 'examples')
|
||||||
|
|
||||||
eprintln('')
|
eprintln('')
|
||||||
building_live_failed := testing.v_build_failing(vargs + '-live',
|
building_live_failed := testing.v_build_failing(vargs + '-live', filepath.join('examples','hot_reload'))
|
||||||
filepath.join( 'examples', 'hot_reload'))
|
|
||||||
|
|
||||||
eprintln('')
|
eprintln('')
|
||||||
v_module_install_cmd := '$vexe install nedpals.args'
|
v_module_install_cmd := '$vexe install nedpals.args'
|
||||||
eprintln('\nInstalling a v module with: $v_module_install_cmd ')
|
eprintln('\nInstalling a v module with: $v_module_install_cmd ')
|
||||||
@ -78,25 +64,8 @@ fn v_test_compiler2(vargs string){
|
|||||||
eprintln('v failed to install a test module')
|
eprintln('v failed to install a test module')
|
||||||
}
|
}
|
||||||
vmark.stop()
|
vmark.stop()
|
||||||
eprintln( 'Installing a v module took: ' + vmark.total_duration().str() + 'ms')
|
eprintln('Installing a v module took: ' + vmark.total_duration().str() + 'ms')
|
||||||
|
if building_tools_failed || compiler_test_session.failed || building_examples_failed || building_live_failed {
|
||||||
make_sure_vfmt_was_run()
|
|
||||||
|
|
||||||
if building_tools_failed ||
|
|
||||||
compiler_test_session.failed ||
|
|
||||||
building_examples_failed ||
|
|
||||||
building_live_failed {
|
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_sure_vfmt_was_run() {
|
|
||||||
files := os.walk_ext('.', '_test.v')
|
|
||||||
for file in files {
|
|
||||||
println(file)
|
|
||||||
os.exec('./vfmt $file') or {
|
|
||||||
println('$file failed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
66
tools/vtest-fmt.v
Normal file
66
tools/vtest-fmt.v
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import (
|
||||||
|
os
|
||||||
|
testing
|
||||||
|
benchmark
|
||||||
|
)
|
||||||
|
|
||||||
|
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) {
|
||||||
|
// NB: vfmt have to be build with '-d vfmt' . V itself knows about this,
|
||||||
|
// and v will rebuild tools/vfmt, if it is missing.
|
||||||
|
// Removing the binaries below is needed, since the building tools step
|
||||||
|
// rebuilds all the tools without the special option needed by vfmt
|
||||||
|
// by simply compiling each of them with `v tools/{toolname}.v`
|
||||||
|
// os.rm('tools/vfmt')
|
||||||
|
// os.rm('tools/vfmt.exe')
|
||||||
|
mut files_able_to_be_formatted := []string
|
||||||
|
all_test_files := os.walk_ext('.', '.v')
|
||||||
|
known_failing_exceptions := ['./examples/vweb/vweb_example.v',
|
||||||
|
'./tools/gen_vc.v',
|
||||||
|
'./tutorials/code/blog/article.v',
|
||||||
|
'./tutorials/code/blog/blog.v',
|
||||||
|
'./vlib/arrays/arrays.v',
|
||||||
|
'./vlib/arrays/arrays_test.v',
|
||||||
|
'./vlib/builtin/js/hashmap.v',
|
||||||
|
'./vlib/compiler/tests/fn_variadic_test.v',
|
||||||
|
'./vlib/compiler/tests/generic_test.v',
|
||||||
|
'./vlib/compiler/preludes/live_main.v',
|
||||||
|
'./vlib/compiler/preludes/live_shared.v',
|
||||||
|
'./vlib/compiler/preludes/tests_assertions.v',
|
||||||
|
'./vlib/compiler/preludes/tests_with_stats.v',
|
||||||
|
'./vlib/crypto/aes/aes.v',
|
||||||
|
'./vlib/crypto/aes/aes_cbc.v',
|
||||||
|
'./vlib/crypto/aes/block_generic.v',
|
||||||
|
'./vlib/crypto/aes/const.v',
|
||||||
|
'./vlib/crypto/aes/cypher_generic.v',
|
||||||
|
'./vlib/crypto/rc4/rc4.v',
|
||||||
|
'./vlib/eventbus/eventbus_test.v',
|
||||||
|
'./vlib/flag/flag.v',
|
||||||
|
'./vlib/os/bare/bare_example_linux.v',
|
||||||
|
'./vlib/szip/szip.v',
|
||||||
|
'./vlib/ui/examples/users_gui/users.v',
|
||||||
|
'./vlib/vweb/assets/assets.v',
|
||||||
|
'./vlib/vweb/vweb.v',
|
||||||
|
]
|
||||||
|
for tfile in all_test_files {
|
||||||
|
if tfile in known_failing_exceptions {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
files_able_to_be_formatted << tfile
|
||||||
|
}
|
||||||
|
eprintln('Run "v fmt" over all .v files')
|
||||||
|
mut vfmt_test_session := testing.new_test_session('$vargs fmt')
|
||||||
|
vfmt_test_session.files << files_able_to_be_formatted
|
||||||
|
vfmt_test_session.test()
|
||||||
|
eprintln(vfmt_test_session.benchmark.total_message('running vfmt over V test files'))
|
||||||
|
if vfmt_test_session.benchmark.nfail > 0 {
|
||||||
|
panic('\nWARNING: v fmt failed ${vfmt_test_session.benchmark.nfail} times.\n')
|
||||||
|
}
|
||||||
|
}
|
2
v.v
2
v.v
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
known_commands = ['run', 'build', 'version', 'doc']
|
known_commands = ['run', 'build', 'version', 'doc']
|
||||||
simple_tools = ['fmt', 'up', 'create', 'test', 'test-compiler', 'build-tools', 'build-examples', 'build-vbinaries']
|
simple_tools = ['fmt', 'up', 'create', 'test', 'test-fmt', 'test-compiler', 'build-tools', 'build-examples', 'build-vbinaries']
|
||||||
)
|
)
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -36,7 +36,7 @@ const (
|
|||||||
|
|
||||||
const(
|
const(
|
||||||
fnv64_prime = 1099511628211
|
fnv64_prime = 1099511628211
|
||||||
fnv64_offset_basis = u64(14695981039346656037)
|
fnv64_offset_basis = 14695981039346656037
|
||||||
)
|
)
|
||||||
|
|
||||||
const(
|
const(
|
||||||
|
2
vlib/os2/keep_vfmt_happy.v
Normal file
2
vlib/os2/keep_vfmt_happy.v
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
//this keeps vfmt happy
|
||||||
|
module os2
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
module main
|
module main
|
||||||
|
|
||||||
|
import filepath
|
||||||
import rand
|
import rand
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
module ttf
|
module ttf
|
||||||
|
|
||||||
|
import sdl
|
||||||
|
|
||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
|
|
||||||
[typedef]
|
[typedef]
|
||||||
@ -132,4 +134,5 @@ fn C.TTF_CloseFont(font &TTF_Font)
|
|||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
version = '0.0.1'
|
version = '0.0.1'
|
||||||
|
sdl_version = sdl.version // TODO: remove this hack to mark sdl as used; avoids warning
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user