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,35 +17,45 @@ fn test_all() {
} }
tests.sort() tests.sort()
for test in tests { for test in tests {
path := os.join_path(dir, test).replace('\\', '/') // -prod so that warns are errors
program := path.replace('.vv', '.v') total_errors += check_path(vexe, dir, test, '-prod', '.out')
print(program + ' ')
os.cp(path, program) or {
panic(err)
}
// -prod so that warn are errors
res := os.exec('$vexe -prod $program') or {
panic(err)
}
mut expected := os.read_file(program.replace('.v', '') + '.out') or {
panic(err)
}
expected = clean_line_endings(expected)
found := clean_line_endings(res.output)
if expected != found {
println(term.red('FAIL'))
println('============')
println('expected:')
println(expected)
println('============')
println('found:')
println(found)
println('============\n')
total_errors++
} else {
println(term.green('OK'))
os.rm( program )
}
} }
total_errors += check_path(vexe, dir, 'globals_error.vv', '--enable-globals run', '.run.out')
assert total_errors == 0 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)
}
res := os.exec('$vexe $voptions $program') or {
panic(err)
}
mut expected := os.read_file(program.replace('.v', '') + result_extension) or {
panic(err)
}
expected = clean_line_endings(expected)
found := clean_line_endings(res.output)
if expected != found {
println(term.red('FAIL'))
println('============')
println('expected:')
println(expected)
println('============')
println('found:')
println(found)
println('============\n')
return 1
} else {
println(term.green('OK'))
os.rm(program)
}
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')
}

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 {