1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tests: add a vlib/v/tests/known_errors/known_errors_test.v test runner

This commit is contained in:
Delyan Angelov 2022-04-03 12:44:22 +03:00
parent 0497b885dc
commit a1e9cae5d2
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 68 additions and 0 deletions

View File

@ -83,6 +83,20 @@ This *test runner*, checks whether whole project folders, can be compiled, and r
NB: Each project in these folders, should finish with an exit code of 0, NB: Each project in these folders, should finish with an exit code of 0,
and it should output `OK` as its last stdout line. and it should output `OK` as its last stdout line.
## `v vlib/v/tests/known_errors/known_errors_test.v`
This *test runner*, checks whether a known program, that was expected to compile,
but did NOT, due to a buggy checker, parser or cgen, continues to fail.
The negative programs are collected in the `vlib/v/tests/known_errors/testdata/` folder.
Each of them should FAIL to compile, due to a known/confirmed compiler bug/limitation.
The intended use of this, is for providing samples, that currently do NOT compile,
but that a future compiler improvement WILL be able to compile, and to
track, whether they were not fixed incidentally, due to an unrelated
change/improvement. For example, code that triggers generating invalid C code can go here,
and later when a bug is fixed, can be moved to a proper _test.v or .vv/.out pair, outside of
the `vlib/v/tests/known_errors/testdata/` folder.
## Test building of actual V programs (examples, tools, V itself) ## Test building of actual V programs (examples, tools, V itself)
* `v build-tools` * `v build-tools`

View File

@ -0,0 +1,36 @@
import os
const vexe = @VEXE
const vroot = os.dir(vexe)
const testdata_folder = 'vlib/v/tests/known_errors/testdata'
fn test_known_errors_testdata_folder_exists() ? {
os.chdir(vroot) ?
assert os.is_dir(testdata_folder)
}
fn test_known_failures_are_still_failures() ? {
mut oks := []string{}
mut files := os.walk_ext(testdata_folder, '.v')
files << os.walk_ext(testdata_folder, '.vv')
for f in files {
cmd := '${os.quoted_path(vexe)} ${os.quoted_path(f)}'
println('known compilation failure: $cmd')
res := os.execute(cmd)
if res.exit_code == 0 {
oks << cmd
println(' unexpectedly COMPILED: $cmd')
} else {
assert true
}
}
println('Summary: $files.len files, $oks.len unexpectedly succeeded.')
if oks.len != 0 {
for cmd in oks {
println(' expected to fail, but SUCCEEDED command: $cmd')
}
assert false
}
}

View File

@ -0,0 +1,18 @@
module main
import rand
import rand.wyrand
import rand.splitmix64
fn main() {
mut wyrand_rng := &rand.PRNG(&wyrand.WyRandRNG{})
mut splitmix_rng := &rand.PRNG(&splitmix64.SplitMix64RNG{})
mut generators := [wyrand_rng, splitmix_rng]
for mut rng in generators {
seed_len := rng.block_size() / 32
// NB: `seed_len := (*rng).block_size() / 32` does compile
dump(seed_len)
println(rng.string(15))
}
}