more precise support for internal module tests
parent
2ac074655f
commit
5b990078f9
|
@ -35,7 +35,7 @@ enum Pass {
|
||||||
|
|
||||||
pub struct V {
|
pub struct V {
|
||||||
pub mut:
|
pub mut:
|
||||||
mod_file_cacher &ModFileCacher // used during lookup for v.mod to support @VROOT
|
mod_file_cacher &builder.ModFileCacher // used during lookup for v.mod to support @VROOT
|
||||||
out_name_c string // name of the temporary C file
|
out_name_c string // name of the temporary C file
|
||||||
files []string // all V files that need to be parsed and compiled
|
files []string // all V files that need to be parsed and compiled
|
||||||
compiled_dir string // contains os.real_path() of the dir of the final file beeing compiled, or the dir itself when doing `v .`
|
compiled_dir string // contains os.real_path() of the dir of the final file beeing compiled, or the dir itself when doing `v .`
|
||||||
|
@ -68,7 +68,7 @@ pub fn new_v(pref &pref.Preferences) &V {
|
||||||
compiled_dir:=if os.is_dir(rdir) { rdir } else { os.dir(rdir) }
|
compiled_dir:=if os.is_dir(rdir) { rdir } else { os.dir(rdir) }
|
||||||
|
|
||||||
return &V{
|
return &V{
|
||||||
mod_file_cacher: new_mod_file_cacher()
|
mod_file_cacher: builder.new_mod_file_cacher()
|
||||||
compiled_dir:compiled_dir// if os.is_dir(rdir) { rdir } else { os.dir(rdir) }
|
compiled_dir:compiled_dir// if os.is_dir(rdir) { rdir } else { os.dir(rdir) }
|
||||||
table: new_table(pref.obfuscate)
|
table: new_table(pref.obfuscate)
|
||||||
out_name_c: out_name_c
|
out_name_c: out_name_c
|
||||||
|
@ -746,8 +746,18 @@ pub fn (v &V) get_user_files() []string {
|
||||||
tcontent := os.read_file(dir)or{
|
tcontent := os.read_file(dir)or{
|
||||||
panic('$dir does not exist')
|
panic('$dir does not exist')
|
||||||
}
|
}
|
||||||
if tcontent.contains('module ') && !tcontent.contains('module main') {
|
slines := tcontent.trim_space().split_into_lines()
|
||||||
is_internal_module_test = true
|
for sline in slines {
|
||||||
|
line := sline.trim_space()
|
||||||
|
if line.len > 2 {
|
||||||
|
if line[0] == `/` && line[1] == `/` {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if line.starts_with('module ') && !line.starts_with('module main') {
|
||||||
|
is_internal_module_test = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if is_internal_module_test {
|
if is_internal_module_test {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
pub:
|
pub:
|
||||||
|
mod_file_cacher &ModFileCacher // used during lookup for v.mod to support @VROOT
|
||||||
pref &pref.Preferences
|
pref &pref.Preferences
|
||||||
table &table.Table
|
table &table.Table
|
||||||
checker checker.Checker
|
checker checker.Checker
|
||||||
|
@ -28,6 +29,7 @@ mut:
|
||||||
pub fn new_builder(pref &pref.Preferences) Builder {
|
pub fn new_builder(pref &pref.Preferences) Builder {
|
||||||
table := table.new_table()
|
table := table.new_table()
|
||||||
return Builder{
|
return Builder{
|
||||||
|
mod_file_cacher: new_mod_file_cacher()
|
||||||
pref: pref
|
pref: pref
|
||||||
table: table
|
table: table
|
||||||
checker: checker.new_checker(table)
|
checker: checker.new_checker(table)
|
||||||
|
@ -160,16 +162,24 @@ pub fn (b &Builder) v_files_from_dir(dir string) []string {
|
||||||
if file.ends_with('_nix.v') && b.os == .windows {
|
if file.ends_with('_nix.v') && b.os == .windows {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if file.ends_with('_android.v') && b.pref.os != .android {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if file.ends_with('_freebsd.v') && b.pref.os != .freebsd {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if file.ends_with('_solaris.v') && b.pref.os != .solaris {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if file.ends_with('_js.v') && b.os != .js {
|
if file.ends_with('_js.v') && b.os != .js {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if file.ends_with('_c.v') && b.os == .js {
|
if file.ends_with('_c.v') && b.os == .js {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
/*
|
if b.pref.compile_defines_all.len > 0 && file.contains('_d_') {
|
||||||
if v.compile_defines_all.len > 0 && file.contains('_d_') {
|
|
||||||
mut allowed := false
|
mut allowed := false
|
||||||
for cdefine in v.compile_defines {
|
for cdefine in b.pref.compile_defines {
|
||||||
file_postfix := '_d_${cdefine}.v'
|
file_postfix := '_d_${cdefine}.v'
|
||||||
if file.ends_with(file_postfix) {
|
if file.ends_with(file_postfix) {
|
||||||
allowed = true
|
allowed = true
|
||||||
|
@ -180,8 +190,6 @@ pub fn (b &Builder) v_files_from_dir(dir string) []string {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
res << os.join_path(dir,file)
|
res << os.join_path(dir,file)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module compiler
|
module builder
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -9,20 +9,21 @@ import os
|
||||||
// ModFileCacher.get(folder) works in such a way, that given this tree:
|
// ModFileCacher.get(folder) works in such a way, that given this tree:
|
||||||
// examples/hanoi.v
|
// examples/hanoi.v
|
||||||
// vlib/v.mod
|
// vlib/v.mod
|
||||||
// vlib/compiler/tests/project_with_c_code/mod1/v.mod
|
// vlib/v/tests/project_with_c_code/mod1/v.mod
|
||||||
// vlib/compiler/tests/project_with_c_code/mod1/wrapper.v
|
// vlib/v/tests/project_with_c_code/mod1/wrapper.v
|
||||||
// -----------------
|
// -----------------
|
||||||
// ModFileCacher.get('examples')
|
// ModFileCacher.get('examples')
|
||||||
// => ModFileAndFolder{'', 'examples'}
|
// => ModFileAndFolder{'', 'examples'}
|
||||||
// ModFileCacher.get('vlib/compiler/tests')
|
// ModFileCacher.get('vlib/v/tests')
|
||||||
// => ModFileAndFolder{'vlib/v.mod', 'vlib'}
|
// => ModFileAndFolder{'vlib/v.mod', 'vlib'}
|
||||||
// ModFileCacher.get('vlib/compiler')
|
// ModFileCacher.get('vlib/v')
|
||||||
// => ModFileAndFolder{'vlib/v.mod', 'vlib'}
|
// => ModFileAndFolder{'vlib/v.mod', 'vlib'}
|
||||||
// ModFileCacher.get('vlib/project_with_c_code/mod1')
|
// ModFileCacher.get('vlib/v/test/project_with_c_code/mod1')
|
||||||
// => ModFileAndFolder{'vlib/project_with_c_code/mod1/v.mod', 'vlib/project_with_c_code/mod1'}
|
// => ModFileAndFolder{'vlib/v/test/project_with_c_code/mod1/v.mod', 'vlib/v/test/project_with_c_code/mod1'}
|
||||||
|
|
||||||
|
|
||||||
struct ModFileAndFolder {
|
pub struct ModFileAndFolder {
|
||||||
|
pub:
|
||||||
// vmod_file contains the full path of the found 'v.mod' file, or ''
|
// vmod_file contains the full path of the found 'v.mod' file, or ''
|
||||||
// if no 'v.mod' file was found in file_path_dir, or in its parent folders.
|
// if no 'v.mod' file was found in file_path_dir, or in its parent folders.
|
||||||
vmod_file string
|
vmod_file string
|
||||||
|
@ -33,18 +34,18 @@ struct ModFileAndFolder {
|
||||||
vmod_folder string
|
vmod_folder string
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ModFileCacher {
|
pub struct ModFileCacher {
|
||||||
mut:
|
mut:
|
||||||
cache map[string]ModFileAndFolder
|
cache map[string]ModFileAndFolder
|
||||||
// folder_files caches os.ls(key)
|
// folder_files caches os.ls(key)
|
||||||
folder_files map[string][]string
|
folder_files map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_mod_file_cacher() &ModFileCacher {
|
pub fn new_mod_file_cacher() &ModFileCacher {
|
||||||
return &ModFileCacher{}
|
return &ModFileCacher{}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mcache &ModFileCacher) dump() {
|
pub fn (mcache &ModFileCacher) dump() {
|
||||||
$if debug {
|
$if debug {
|
||||||
eprintln('ModFileCacher DUMP:')
|
eprintln('ModFileCacher DUMP:')
|
||||||
eprintln(' ModFileCacher.cache:')
|
eprintln(' ModFileCacher.cache:')
|
||||||
|
@ -58,7 +59,7 @@ fn (mcache &ModFileCacher) dump() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mcache mut ModFileCacher) get(mfolder string) ModFileAndFolder {
|
pub fn (mcache mut ModFileCacher) get(mfolder string) ModFileAndFolder {
|
||||||
if mfolder in mcache.cache {
|
if mfolder in mcache.cache {
|
||||||
return mcache.cache[ mfolder ]
|
return mcache.cache[ mfolder ]
|
||||||
}
|
}
|
|
@ -2641,14 +2641,30 @@ fn (g &Gen) get_all_test_function_names() []string {
|
||||||
for _, f in g.table.fns {
|
for _, f in g.table.fns {
|
||||||
if f.name == 'testsuite_begin' {
|
if f.name == 'testsuite_begin' {
|
||||||
tsuite_begin = f.name
|
tsuite_begin = f.name
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if f.name == 'testsuite_end' {
|
if f.name == 'testsuite_end' {
|
||||||
tsuite_end = f.name
|
tsuite_end = f.name
|
||||||
}
|
|
||||||
if !f.name.starts_with('test_') {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tfuncs << f.name
|
if f.name.starts_with('test_') {
|
||||||
|
tfuncs << f.name
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// What follows is for internal module tests
|
||||||
|
// (they are part of a V module, NOT in main)
|
||||||
|
if f.name.contains('.test_') {
|
||||||
|
tfuncs << f.name
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if f.name.ends_with('.testsuite_begin') {
|
||||||
|
tsuite_begin = f.name
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if f.name.ends_with('.testsuite_end') {
|
||||||
|
tsuite_end = f.name
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mut all_tfuncs := []string
|
mut all_tfuncs := []string
|
||||||
if tsuite_begin.len > 0 {
|
if tsuite_begin.len > 0 {
|
||||||
|
@ -2658,7 +2674,11 @@ fn (g &Gen) get_all_test_function_names() []string {
|
||||||
if tsuite_end.len > 0 {
|
if tsuite_end.len > 0 {
|
||||||
all_tfuncs << tsuite_end
|
all_tfuncs << tsuite_end
|
||||||
}
|
}
|
||||||
return all_tfuncs
|
mut all_tfuncs_c := []string
|
||||||
|
for f in all_tfuncs {
|
||||||
|
all_tfuncs_c << f.replace('.', '__')
|
||||||
|
}
|
||||||
|
return all_tfuncs_c
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (g &Gen) is_importing_os() bool {
|
fn (g &Gen) is_importing_os() bool {
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
module scanner
|
module scanner
|
||||||
|
|
||||||
import (
|
import v.token
|
||||||
v.token
|
|
||||||
)
|
|
||||||
|
|
||||||
fn test_scan() {
|
fn test_scan() {
|
||||||
text := 'println(2 + 3)'
|
text := 'println(2 + 3)'
|
||||||
|
@ -33,11 +31,11 @@ fn test_scan() {
|
||||||
c = 1000000
|
c = 1000000
|
||||||
assert c == 1000000
|
assert c == 1000000
|
||||||
// test float conversion and reading
|
// test float conversion and reading
|
||||||
d := f64(23000000e-3)
|
d := 23000000e-3
|
||||||
assert int(d) == 23000
|
assert int(d) == 23000
|
||||||
mut e := f64(1.2E3) * f64(-1e-1)
|
mut e := 1.2E3 * -1e-1
|
||||||
assert e == -120.0
|
assert e == -120.0
|
||||||
e = f64(1.2E3) * f64(1e-1)
|
e = 1.2E3 * 1e-1
|
||||||
assert e == 120.0
|
assert e == 120.0
|
||||||
assert 1.23e+10 == 1.23e10
|
assert 1.23e+10 == 1.23e10
|
||||||
assert 1.23e+10 == 1.23e0010
|
assert 1.23e+10 == 1.23e0010
|
||||||
|
|
Loading…
Reference in New Issue