compiler: restore support for --enable-globals flag, and add tests.
parent
1cb4aa7642
commit
d830620651
|
@ -143,6 +143,9 @@ fn parse_args(args []string) (&pref.Preferences, string) {
|
|||
'-shared' {
|
||||
res.is_shared = true
|
||||
}
|
||||
'--enable-globals' {
|
||||
res.enable_globals = true
|
||||
}
|
||||
'-autofree' {
|
||||
res.autofree = true
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import os
|
||||
import term
|
||||
|
||||
fn clean_line_endings(s string) string {
|
||||
return s.trim_space().replace(' \n', '\n').replace(' \r\n', '\n').replace('\r\n', '\n').trim('\n')
|
||||
}
|
||||
|
||||
fn test_all() {
|
||||
mut total_errors := 0
|
||||
vexe := os.getenv('VEXE')
|
||||
|
@ -21,17 +17,24 @@ fn test_all() {
|
|||
}
|
||||
tests.sort()
|
||||
for test in tests {
|
||||
// -prod so that warns are errors
|
||||
total_errors += check_path(vexe, dir, test, '-prod', '.out')
|
||||
}
|
||||
total_errors += check_path(vexe, dir, 'globals_error.vv', '--enable-globals run', '.run.out')
|
||||
assert total_errors == 0
|
||||
}
|
||||
|
||||
fn check_path(vexe, dir, test, voptions, result_extension string) int {
|
||||
path := os.join_path(dir, test).replace('\\', '/')
|
||||
program := path.replace('.vv', '.v')
|
||||
print(program + ' ')
|
||||
os.cp(path, program) or {
|
||||
panic(err)
|
||||
}
|
||||
// -prod so that warn are errors
|
||||
res := os.exec('$vexe -prod $program') or {
|
||||
res := os.exec('$vexe $voptions $program') or {
|
||||
panic(err)
|
||||
}
|
||||
mut expected := os.read_file(program.replace('.v', '') + '.out') or {
|
||||
mut expected := os.read_file(program.replace('.v', '') + result_extension) or {
|
||||
panic(err)
|
||||
}
|
||||
expected = clean_line_endings(expected)
|
||||
|
@ -45,11 +48,14 @@ fn test_all() {
|
|||
println('found:')
|
||||
println(found)
|
||||
println('============\n')
|
||||
total_errors++
|
||||
return 1
|
||||
} else {
|
||||
println(term.green('OK'))
|
||||
os.rm( program )
|
||||
os.rm(program)
|
||||
}
|
||||
}
|
||||
assert total_errors == 0
|
||||
return 0
|
||||
}
|
||||
|
||||
fn clean_line_endings(s string) string {
|
||||
return s.trim_space().replace(' \n', '\n').replace(' \r\n', '\n').replace('\r\n', '\n').trim('\n')
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
vlib/v/checker/tests/globals_error.v:2:1: error: use `v --enable-globals ...` to enable globals
|
||||
1 |
|
||||
2 | __global rfcnt int
|
||||
| ~~~~~~~~
|
||||
3 |
|
||||
4 | fn abc(){
|
|
@ -0,0 +1 @@
|
|||
rfcnt: 2
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
__global rfcnt int
|
||||
|
||||
fn abc(){
|
||||
rfcnt = 2
|
||||
}
|
||||
|
||||
fn main(){
|
||||
rfcnt = 1
|
||||
abc()
|
||||
println('rfcnt: $rfcnt')
|
||||
}
|
|
@ -70,7 +70,6 @@ pub fn (mut p Preferences) fill_with_defaults() {
|
|||
}
|
||||
}
|
||||
}
|
||||
p.enable_globals = false
|
||||
}
|
||||
|
||||
fn default_c_compiler() string {
|
||||
|
|
Loading…
Reference in New Issue