compiler: restore support for --enable-globals flag, and add tests.

pull/4893/head
Delyan Angelov 2020-05-14 08:20:38 +03:00
parent 1cb4aa7642
commit d830620651
6 changed files with 61 additions and 34 deletions

View File

@ -143,6 +143,9 @@ fn parse_args(args []string) (&pref.Preferences, string) {
'-shared' { '-shared' {
res.is_shared = true res.is_shared = true
} }
'--enable-globals' {
res.enable_globals = true
}
'-autofree' { '-autofree' {
res.autofree = true res.autofree = true
} }

View File

@ -1,10 +1,6 @@
import os import os
import term 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() { fn test_all() {
mut total_errors := 0 mut total_errors := 0
vexe := os.getenv('VEXE') vexe := os.getenv('VEXE')
@ -21,17 +17,24 @@ fn test_all() {
} }
tests.sort() tests.sort()
for test in tests { 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('\\', '/') path := os.join_path(dir, test).replace('\\', '/')
program := path.replace('.vv', '.v') program := path.replace('.vv', '.v')
print(program + ' ') print(program + ' ')
os.cp(path, program) or { os.cp(path, program) or {
panic(err) panic(err)
} }
// -prod so that warn are errors res := os.exec('$vexe $voptions $program') or {
res := os.exec('$vexe -prod $program') or {
panic(err) 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) panic(err)
} }
expected = clean_line_endings(expected) expected = clean_line_endings(expected)
@ -45,11 +48,14 @@ fn test_all() {
println('found:') println('found:')
println(found) println(found)
println('============\n') println('============\n')
total_errors++ return 1
} else { } else {
println(term.green('OK')) println(term.green('OK'))
os.rm( program ) os.rm(program)
} }
} return 0
assert total_errors == 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')
} }

View File

@ -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(){

View File

@ -0,0 +1 @@
rfcnt: 2

View File

@ -0,0 +1,12 @@
__global rfcnt int
fn abc(){
rfcnt = 2
}
fn main(){
rfcnt = 1
abc()
println('rfcnt: $rfcnt')
}

View File

@ -70,7 +70,6 @@ pub fn (mut p Preferences) fill_with_defaults() {
} }
} }
} }
p.enable_globals = false
} }
fn default_c_compiler() string { fn default_c_compiler() string {