testing: do not allow fn main in tests and make sure there is at least one test fn
parent
104e4c9fc7
commit
6a788bb364
|
@ -429,8 +429,15 @@ string _STR_TMP(const char *fmt, ...) {
|
|||
exit(1)
|
||||
}
|
||||
}
|
||||
// Generate `main` which calls every single test function
|
||||
else if v.pref.is_test {
|
||||
if v.table.main_exists() {
|
||||
cerror('test files cannot have function `main`')
|
||||
}
|
||||
// make sure there's at least on test function
|
||||
if !v.table.has_at_least_one_test_fn() {
|
||||
cerror('test files need to have at least one test function')
|
||||
}
|
||||
// Generate `main` which calls every single test function
|
||||
cgen.genln('int main() { init_consts();')
|
||||
for _, f in v.table.fns {
|
||||
if f.name.starts_with('test_') {
|
||||
|
|
|
@ -672,6 +672,15 @@ fn (t &Table) main_exists() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
fn (t &Table) has_at_least_one_test_fn() bool {
|
||||
for _, f in t.fns {
|
||||
if f.name.starts_with('test_') {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fn (t &Table) find_const(name string) ?Var {
|
||||
//println('find const l=$t.consts.len')
|
||||
for c in t.consts {
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
crypto.sha512 as s5
|
||||
)
|
||||
|
||||
pub fn main() {
|
||||
fn test_import() {
|
||||
assert os.SUCCESS == os.SUCCESS &&
|
||||
t.MonthDays[0] == t.MonthDays[0] &&
|
||||
s2.Size == s2.Size &&
|
||||
|
|
Loading…
Reference in New Issue