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

move compiler tests from compiler/ to v/

This commit is contained in:
Alexander Medvednikov
2020-03-27 18:01:46 +01:00
parent 95e67c9502
commit eed7c91e87
132 changed files with 18 additions and 18 deletions

View File

@ -1,5 +0,0 @@
fn test_array_to_string_conversion() {
expected := '["1", "2", "3", "4"] '
arr := ['1', '2', '3', '4']
assert '$arr' == expected
}

View File

@ -1,26 +0,0 @@
fn test_inline_asm() {
a := 10
b := 0
unsafe {
asm {
"movl %1, %%eax;"
"movl %%eax, %0;"
:"=r"(b)
:"r"(a)
:"%eax"
}
}
assert a == 10
assert b == 10
//
e := 0
unsafe {
asm {
//".intel_syntax noprefix;"
//"mov %0, 5"
"movl $5, %0"
:"=a"(e)
}
}
assert e == 5
}

View File

@ -1,33 +0,0 @@
[testing]
struct StructAttrTest {
foo string
bar int
}
[testing]
pub struct PubStructAttrTest {
foo string
bar int
}
[testing]
enum EnumAttrTest {
one
two
}
[testing]
pub enum PubEnumAttrTest {
one
two
}
[testing]
fn test_fn_attribute() {
assert true
}
[testing]
pub fn test_pub_fn_attribute() {
assert true
}

View File

@ -1,11 +0,0 @@
/*
Test for backtrace capability
*/
fn a_method() {
print_backtrace()
}
fn test_backtrace() {
a_method()
//panic('hi')
}

View File

@ -1,21 +0,0 @@
#include <stdio.h>
int increment_val(int n) {
return n + 2;
}
// ~26% faster
void increment_ptr(int* n) {
*n += 2;
}
int main() {
int n = 0;
for (int i = 0; i < 1000000000; i++) {
n = increment_val(n);
//increment_ptr(&n);
}
printf("%d\n", n);
return 0;
}

View File

@ -1,26 +0,0 @@
fn test_bitness(){
mut x := 0
$if x32 {
println('system is 32 bit')
x = 1
}
$if x64 {
println('system is 64 bit')
x = 2
}
assert x > 0
}
fn test_endianness(){
mut x := 0
$if little_endian {
println('system is little endian')
x = 1
}
$if big_endian {
println('system is big endian')
x = 2
}
assert x > 0
}

View File

@ -1,14 +0,0 @@
pub const (
// c = a // TODO
a = b
b = 1
)
struct Foo {
}
fn test_const() {
assert a == 1
// assert c == 1 // TODO: This will not build yet
}

View File

@ -1,8 +0,0 @@
fn test_cstring(){
w := c'world'
hlen := C.strlen(c'hello')
wlen := C.strlen(w)
assert hlen == 5
assert wlen == 5
}

View File

@ -1,65 +0,0 @@
fn foo() string {
println('foo()')
return 'foo'
}
fn foo2() string {
println('start')
defer {
println('defer')
}
defer {
println('defer2')
}
println('end')
return foo()
}
fn test_defer() {
assert foo2() == 'foo'
}
fn set_num(i int, n mut Num) {
defer {
println('exiting')
n.val++
}
println('Hi')
if i < 5 {
return
}
else {
n.val++
}
}
fn set_num_opt(n mut Num) ?int {
defer {
n.val = 1
}
return 99
}
struct Num {
mut:
val int
}
fn test_defer_early_exit() {
mut sum := Num{
0}
for i in 0 .. 10 {
set_num(i, mut sum)
}
println('sum: $sum.val')
assert sum.val == 15
}
fn test_defer_option() {
mut ok := Num{
0}
set_num_opt(mut ok) or {
assert false
}
assert ok.val == 1
}

View File

@ -1,34 +0,0 @@
[flag]
enum BfPermission {
read
write
execute
other
}
struct BfFile {
mut:
perm BfPermission
}
fn test_enum_bitfield() {
mut a := BfFile{}
a.perm.set(.read)
a.perm.set(.write)
a.perm.toggle(.execute)
a.perm.clear(.write)
//a.perm.set(.other)
assert a.perm.has(.read)
assert a.perm.has(.execute)
assert !a.perm.has(.write)
assert !a.perm.has(.other)
mut b := BfPermission.read // TODO: this does nothing currenty just sets the type
b.set(.write)
b.set(.other)
assert b.has(.write)
assert b.has(.other)
assert !b.has(.read)
assert !b.has(.execute)
}

View File

@ -1,33 +0,0 @@
enum w_hex {
a = 0x001
b = 0x010
c = 0x100
}
enum w_decimal {
a = 1
b = 16
c = 256
}
const (
ca = 1
cb = 16
cc = 256
)
fn test_enum_hex() {
assert ca == int(w_decimal.a)
assert cb == int(w_decimal.b)
assert cc == int(w_decimal.c)
assert int(w_hex.a) == ca
assert int(w_hex.b) == cb
assert int(w_hex.c) == cc
assert int(w_hex.a) == int(w_decimal.a)
assert int(w_hex.b) == int(w_decimal.b)
assert int(w_hex.c) == int(w_decimal.c)
}

View File

@ -1,116 +0,0 @@
enum Color {
red
blue
green
}
fn enum_optional_helper(b bool) ?Color {
if b {
return .red
}
return error('failed')
}
fn test_enum_optional() {
a := enum_optional_helper(true) or {
assert false
return
}
assert a == .red
}
fn test_enum() {
assert Color.red == .red
assert Color.blue == .blue
assert Color.green == .green
assert Color.red != .blue
assert Color.red != .green
assert Color.blue != .green
mut color := Color.red
assert color == .red
color = .green
assert color == .green
}
fn test_in() {
color := Color.red
num := 3 // used to be an expr bug before `in`
assert color in [.red, .green]
assert num == 3
println(color)
assert true
}
fn test_match() {
color := Color.green
num := 3
match color {
.red { assert false }
.green { assert true }
else { assert false }
}
println(color)
assert num == 3
}
enum Foo {
a = 1
b = 2
c = 3
d = -10
}
fn test_nums() {
foo := Foo.a
assert foo == 1
assert Foo.c == 3
d := Foo.d
assert d == -10
}
enum Expr {
BoolExpr(bool)
IntExpr(int)
//FloatExpr(int)
}
fn get_expr() Expr {
return Expr.IntExpr(10)
}
fn test_typed_enum() {
i := Expr.IntExpr(10)
expr := Expr.BoolExpr(true)
//println(i)
//if i == expr {
//}
println('done')
// expr = i
/*
match expr {
IntExpr(n) { println('INT $n') }
BoolExpr(b) { println('BOOL $b') }
}
*/
}
/*
fn test_typed_enum() {
Expr i = { .obj = 10, .typ = IntExpr_type };
Expr expr = { .obj = true, .typ = BoolExpr_type };
// val = expr;
if (expr.typ == IntExpr_type) {
int n = (int)expr.obj;
println('INT $n');
}
else if (expr.typ == BoolExpr_type) {
int b = (bool)expr.obj;
println('BOOL $b');
}
}
*/

View File

@ -1,32 +0,0 @@
fn test_fixed_array_can_be_assigned(){
x := 2.32
mut v := [8]f64
v = [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]!!
assert v[1] == x
}
fn test_fixed_array_can_be_used_in_declaration(){
x := 2.32
v := [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]!!
assert v[1] == x
}
struct Context {
pub mut:
vb [8]f64
}
fn test_fixed_array_can_be_assigned_to_a_struct_field(){
mut ctx := Context{}
x := 2.32
ctx.vb = [1.1, x, 3.3, 4.4, 5.0, 6.0, 7.0, 8.9]!!
assert ctx.vb[1] == x
assert ctx.vb[7] == 8.9
/*
println( ctx.vb[0] )
println( ctx.vb[1] )
println( ctx.vb[2] )
println( ctx.vb[3] )
*/
}

View File

@ -1,23 +0,0 @@
struct Foo {
}
pub fn (f Foo) str() string { return 'Foo{}' }
fn process_foo(foo &Foo) {
println('>process_foo, called for ${foo} === ${*foo}')
}
fn get_foo() Foo {
println('>get_foo')
return Foo{}
}
/*
// TODO: Fix this. It 'works' only with tcc, but is not stable.
fn test_ref_fn_arg() {
process_foo(get_foo())
println(3434)
assert true
}
*/
fn test_dummy(){}

View File

@ -1,18 +0,0 @@
import time.misc as tmisc
// using a manual temporary intermediate variable should always work:
fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_manual() {
t1 := tmisc.random()
t2 := t1.unix_time()
println('res: $t2')
assert true
}
/*
// TODO: Fix this.
// v should produce temporary intermediate variables in chained calls:
fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_chained(){
res := (tmisc.random().unix_time())
println('res: $res')
assert true
}
*/

View File

@ -1,19 +0,0 @@
struct UserData {
test string
}
fn test_fn_multiple_returns() {
name, age, groups, data := fn_mr_get_user()
assert name == 'joe'
assert age == 34
assert groups[0] == 'admins'
assert groups[1] == 'users'
assert data.test == 'Test Data'
println('name: $name | age: $age | groups: ' + groups.join(',') + ' | data: $data.test')
}
fn fn_mr_get_user() (string, int, []string, UserData) {
groups := ['admins', 'users']
data := UserData{test: 'Test Data'}
return 'joe',34,groups,data
}

View File

@ -1,166 +0,0 @@
// 1 line comment
/* 1 line comment */
/*
multi line comment (1)
multi line comment (2)
multi line comment (3)
*/
/*
multi line comment (1)
/*
nested comment
*/
/*nested comment*/
/*nested comment
*/
/* nested comment */
/* /* nested comment */ */
multi line comment (2)
*/
type myfn fn (int) string
type myfn2 fn (a int, b int) int
type myfn3 fn (int, int)
fn myfn4(string)
fn foobar()
fn slopediv(num u32, den u32) int
type f1 fn ()
type f2 fn (voidptr)
type f3 fn (voidptr, voidptr)
type f4 fn (voidptr) int
type f5 fn (int, int) int
type f6 fn (int, int)
fn C.atoi(byteptr) int
fn foo() {
}
type actionf_v fn ()
type actionf_p1 fn (voidptr)
type actionf_p2 fn (voidptr, voidptr)
// TODO
fn modify_array(a mut []int) {
a[0] = 10
for i in 0..a.len {
a[i] = a[i] * 2
}
//a << 888
}
fn test_mut_array() {
mut nums := [1, 2, 3]
modify_array(mut nums)
//assert nums.len == 4
// println(nums)
assert nums[0] == 20
assert nums[1] == 4
assert nums[2] == 6
//assert nums[3] == 888
// workaround for // [91, 32, -33686272] windows bug
println(nums.clone())
}
fn mod_struct(user mut User) {
user.age++
}
struct User {
mut:
age int
}
fn test_mut_struct() {
mut user := User{18}
mod_struct(mut user)
assert user.age == 19
}
fn mod_ptr(buf mut byteptr) {
buf[0] = 77
}
fn test_mut_ptr() {
buf := malloc(10)
mod_ptr(mut buf)
assert buf[0] == 77
}
fn high_fn(f fn(int) int) {
}
fn high_fn_array(f fn(a []int) []int) {
}
fn high_fn_multi_return(a int, b fn (c []int, d []string) ([]int, []string)) {
}
fn sqr(x int) int {
return x * x
}
fn test_fns() {
// no asserts for now, just test function declarations above
high_fn(sqr)
}
fn test_anon_fn() {
/*
high_fn(fn (x int) int {
println('hello')
return x + 1
})
*/
}
fn assert_in_bool_fn(v int) bool {
assert v < 3
return true
}
fn test_assert_in_bool_fn() {
assert_in_bool_fn(2)
}
type MyFn fn (int) int
fn test(n int) int {
return n + 1000
}
struct MySt {
f MyFn
}
fn test_fn_type_call() {
mut arr := []MyFn
arr << MyFn(test)
assert arr[0](10) == 1010
st := MySt{f:test}
assert st.f(10) == 1010
st1 := &MySt{f:test}
assert st1.f(10) == 1010
}

View File

@ -1,76 +0,0 @@
struct VaTestGroup {
name string
}
// basic
fn variadic_test(name string, groups ...VaTestGroup) {
assert groups.len == 2
assert groups[0].name == 'users'
assert groups[1].name == 'admins'
}
fn test_fn_variadic() {
group1 := VaTestGroup{name: 'users'}
group2 := VaTestGroup{name: 'admins'}
variadic_test('joe', group1, group2)
}
// generic
fn variadic_test_generic<T>(a int, b ...T) T {
b1 := b[0]
b2 := b[1]
return '$a $b1 $b2'
}
fn test_fn_variadic_generic() {
assert variadic_test_generic(111, 'hello', 'v') == '111 hello v'
}
// forwarding
fn variadic_forward_a(a ...string) string {
return variadic_forward_b(a)
}
fn variadic_forward_b(a ...string) string {
a0 := a[0]
a1 := a[1]
a2 := a[2]
return '$a0$a1$a2'
}
fn test_fn_variadic_forward() {
assert variadic_forward_a('a', 'b', 'c') == 'abc'
}
fn variadic_test_no_args(name string, groups ...VaTestGroup) {
assert groups.len == 0
}
fn test_fn_variadic_no_args() {
variadic_test_no_args('marko')
}
struct VaTestStruct {
}
fn (a VaTestStruct) variadic_method(name string, groups ...VaTestGroup) {
assert groups.len == 2
assert groups[0].name == 'users'
assert groups[1].name == 'admins'
}
fn (a VaTestStruct) variadic_method_no_args(name string, groups ...VaTestGroup) {
assert groups.len == 0
}
fn test_fn_variadic_method() {
a := VaTestStruct{}
group1 := VaTestGroup{name: 'users'}
group2 := VaTestGroup{name: 'admins'}
a.variadic_method('marko', group1, group2)
}
fn test_fn_variadic_method_no_args() {
a := VaTestStruct{}
a.variadic_method_no_args('marko')
}

View File

@ -1,131 +0,0 @@
fn simple<T>(p T) T {
return p
}
fn sum<T>(l []T) T {
mut r := T(0)
for e in l {
r += e
}
return r
}
fn map_f<T,U>(l []T, f fn(T)U) []U {
mut r := []U
for e in l {
r << f(e)
}
return r
}
fn foldl<T>(l []T, nil T, f fn(T,T)T) T {
mut r := nil
for e in l {
r = f(r, e)
}
return r
}
fn plus<T>(a T, b T) T {
return a+b
}
fn square(x int) int {
return x*x
}
fn mul_int(x int, y int) int {
return x*y
}
fn assert_eq<T>(a, b T) {
r := a == b
println('$a == $b: ${r.str()}')
assert r
}
fn print_nice<T>(x T, indent int) {
mut space := ''
for _ in 0..indent {
space = space + ' '
}
println('$space$x')
}
fn test_generic_fn() {
assert_eq(simple(0+1), 1)
assert_eq(simple('g') + 'h', 'gh')
assert_eq(sum([5.1,6.2,7.0]), 18.3)
assert_eq(plus(i64(4), i64(6)), i64(10))
a := [1,2,3,4]
b := map_f(a, square)
assert_eq(sum(b), 30) // 1+4+9+16 = 30
assert_eq(foldl(b, 1, mul_int), 576) // 1*4*9*16 = 576
print_nice('str', 8)
}
struct Point {
mut:
x f64
y f64
}
fn (p mut Point) translate<T>(x, y T) {
p.x += x
p.y += y
}
fn test_generic_method() {
mut p := Point{}
p.translate(2, 1.0)
assert p.x == 2.0 && p.y == 1.0
}
fn get_values<T>(i T) []T {
return [i]
}
fn test_generic_fn_in_for_in_expression() {
for value in get_values(1) {
assert value == 1
}
for i, val in get_values(0) {
assert i == val
}
for value in get_values('a') {
assert value == 'a'
}
}
// test generic struct
struct DB {
driver string
}
struct User {
db DB
mut:
name string
}
struct Repo<T> {
db DB
mut:
model T
}
fn new_repo<U>(db DB) Repo<U> {
return Repo<U>{db: db}
}
fn test_generic_struct() {
mut a := new_repo<User>(DB{})
a.model.name = 'joe'
mut b := Repo<User>{db: DB{}}
b.model.name = 'joe'
assert a.model.name == 'joe'
assert b.model.name == 'joe'
}

View File

@ -1,14 +0,0 @@
fn test_if_expression_precedence_false_condition(){
b := 10
c := 20
res := 1 + if b > c { b } else { c } + 1
assert res == c + 2
}
fn test_if_expression_precedence_true_condition(){
b := 20
c := 10
res := 1 + if b > c { b } else { c } + 1
assert res == b + 2
}

View File

@ -1,174 +0,0 @@
enum Colors {
red green blue yellow
}
fn test_in_expression(){
mut a := false
arr1 := [1, 2]
arr2 := [0, 2]
arr3 := [1, 0]
a = true && 2 in arr1
assert a == true
a = false && 2 in arr1
assert a == false
a = true && 0 in arr2
assert a == true
a = false && 0 in arr3
assert a == false
a = true && 0 in arr1
assert a == false
a = true && 3 in arr1
assert a == false
a = true && !2 in arr2
assert a == false
a = true && !3 in arr2
assert a == true
a = 1 in arr1 && true
assert a == true
a = 1 in arr1 && false
assert a == false
}
/* not implemented
fn test_in_expression_with_enum(){
mut a := false
arr1 := [Colors.green, .blue]
arr2 := [Colors.red, .blue]
arr3 := [Colors.green, .red]
a = true && Colors.blue in arr1
assert a == true
a = false && Colors.blue in arr1
assert a == false
a = true && Colors.red in arr2
assert a == true
a = false && Colors.red in arr3
assert a == false
a = true && Colors.red in arr1
assert a == false
a = true && Colors.yellow in arr1
assert a == false
a = true && !Colors.blue in arr2
assert a == false
a = true && !Colors.yellow in arr2
assert a == true
a = Colors.green in arr1 && true
assert a == true
a = Colors.green in arr1 && false
assert a == false
}
*/
fn test_in_expression_with_string(){
mut a := false
arr1 := ['ab', 'bc']
arr2 := ['', 'bc']
arr3 := ['ab', '']
a = true && 'bc' in arr1
assert a == true
a = false && 'bc' in arr1
assert a == false
a = true && '' in arr2
assert a == true
a = false && '' in arr3
assert a == false
a = true && '' in arr1
assert a == false
a = true && 'abc' in arr1
assert a == false
a = true && !'bc' in arr2
assert a == false
a = true && !'abc' in arr2
assert a == true
a = 'ab' in arr1 && true
assert a == true
a = 'ab' in arr1 && false
assert a == false
}
fn test_optimized_in_expression(){
mut a := false
a = true && 2 in [1, 2]
assert a == true
a = false && 2 in [1, 2]
assert a == false
a = true && 0 in [0, 2]
assert a == true
a = false && 0 in [1, 0]
assert a == false
a = true && 0 in [1, 2]
assert a == false
a = true && 3 in [1, 2]
assert a == false
a = true && !2 in [0, 2]
assert a == false
a = true && !3 in [0, 2]
assert a == true
a = 1 in [1, 2] && true
assert a == true
a = 1 in [1, 2] && false
assert a == false
}
fn test_optimized_in_expression_with_enum(){
mut a := false
a = true && Colors.blue in [.green, .blue]
assert a == true
a = false && Colors.blue in [.green, .blue]
assert a == false
a = true && Colors.red in [.red, .blue]
assert a == true
a = false && Colors.red in [.green, .red]
assert a == false
a = true && Colors.red in [.green, .blue]
assert a == false
a = true && Colors.yellow in [.green, .blue]
assert a == false
a = true && !Colors.blue in [.red, .blue]
assert a == false
a = true && !Colors.yellow in [.red, .blue]
assert a == true
a = Colors.green in [.green, .blue] && true
assert a == true
a = Colors.green in [.green, .blue] && false
assert a == false
}
fn test_optimized_in_expression_with_string(){
mut a := false
a = true && 'bc' in ['ab', 'bc']
assert a == true
a = false && 'bc' in ['ab', 'bc']
assert a == false
a = true && '' in ['', 'bc']
assert a == true
a = false && '' in ['ab', '']
assert a == false
a = true && '' in ['ab', 'bc']
assert a == false
a = true && 'abc' in ['ab', 'bc']
assert a == false
a = true && !'bc' in ['', 'bc']
assert a == false
a = true && !'abc' in ['', 'bc']
assert a == true
a = 'ab' in ['ab', 'bc'] && true
assert a == true
a = 'ab' in ['ab', 'bc'] && false
assert a == false
}

View File

@ -1,73 +0,0 @@
struct Dog {
breed string
}
struct Cat {
breed string
}
fn (d Cat) name() string { return 'Cat' }
fn (d Cat) speak() { println('meow') }
fn (d Dog) speak() { println('woof') }
fn (d Dog) name() string { return 'Dog'}
interface Speaker {
name() string
speak()
}
interface Speak2er {
name() string
speak()
}
struct Foo {
speaker Speaker
speakers []Speaker
}
fn perform_speak(s Speaker) {
s.speak()
assert true
name := s.name()
assert name == 'Dog' || name == 'Cat'
println(s.name())
}
fn perform_speakers(speakers []Speaker) {
}
fn test_perform_speak() {
dog := Dog{}
perform_speak(dog)
cat := Cat{}
perform_speak(cat)
//perform_speakers([dog, cat])
/*
f := Foo {
speaker: dog
}
*/
}
interface Register {
register()
}
struct RegTest {a int}
fn (f RegTest) register() {
}
fn handle_reg(r Register) {
}
fn test_register() {
f := RegTest{}
f.register()
handle_reg(f)
}

View File

@ -1,49 +0,0 @@
module main
interface Speaker {
say() string
}
struct ChatRoom {
mut:
talkers map[string]Speaker
}
fn new_room() &ChatRoom {
return &ChatRoom{
talkers: map[string]Speaker
}
}
fn (r mut ChatRoom) add(name string, s Speaker) {
r.talkers[name] = s
}
fn test_using_a_map_of_speaker_interfaces(){
mut room := new_room()
room.add('my cat', Cat{name: 'Tigga'} )
room.add('my dog', Dog{name: 'Pirin'} )
room.add('stray dog', Dog{name: 'Anoni'} )
room.add('me', Human{name: 'Bilbo'} )
room.add('she', Human{name: 'Maria'} )
mut text := ''
for name, subject in room.talkers {
line := '${name:12s}: ${subject.say()}'
println(line)
text += line
}
assert text.contains(' meows ')
assert text.contains(' barks ')
assert text.contains(' says ')
}
//
struct Cat { name string }
fn (c &Cat) say() string { return '${c.name} meows "MEOW!"' }
struct Dog { name string }
fn (d &Dog) say() string { return '${d.name} barks "Bau Bau!"' }
struct Human { name string }
fn (h &Human) say() string { return '${h.name} says "Hello"' }

View File

@ -1,97 +0,0 @@
import os
import time
const (
vexe = os.getenv('VEXE')
source_file = os.join_path(os.temp_dir(), 'generated_live_program.v')
output_file = os.join_path(os.temp_dir(), 'generated_live_program.output.txt')
live_program_source = "
module main
import time
[live]
fn pmessage() {
println('ORIGINAL')
}
fn main() {
println('START')
for i := 0; i<6*100; i++ {
pmessage()
time.sleep_ms(10)
}
println('END')
}
"
)
//
fn testsuite_begin(){
if os.user_os() != 'linux' && os.getenv('FORCE_LIVE_TEST').len == 0 {
eprintln('Testing the runtime behaviour of -live mode,')
eprintln('is reliable only on Linux for now.')
eprintln('You can still do it by setting FORCE_LIVE_TEST=1 .')
exit(0)
}
os.write_file(source_file, live_program_source)
}
fn testsuite_end(){
os.rm( source_file )
eprintln('source: $source_file')
eprintln('output: $output_file')
$if !windows {
os.system('cat $output_file')
}
println('---------------------------------------------------------------------------')
output_lines := os.read_lines( output_file ) or {
return
}
mut histogram := map[string]int
for line in output_lines {
histogram[line] = histogram[line] + 1
}
for k,v in histogram {
println('> found ${k} $v times.')
}
println('---------------------------------------------------------------------------')
assert histogram['START'] > 0
assert histogram['END'] > 0
assert histogram['CHANGED'] + histogram['ANOTHER'] > 0
assert histogram['ORIGINAL'] > 0
}
fn change_source(new string){
time.sleep_ms(250)
eprintln('> change ORIGINAL to: $new')
os.write_file(source_file,live_program_source.replace('ORIGINAL', new))
time.sleep_ms(1000)
eprintln('> done.')
}
//
fn test_live_program_can_be_compiled(){
cmd := '$vexe -live run $source_file > $output_file &'
eprintln('Compiling and running with: $cmd')
res := os.system(cmd)
eprintln('... running in the background')
time.sleep_ms(3000)
assert res == 0
}
fn test_live_program_can_be_changed_1(){
change_source('CHANGED')
assert true
}
fn test_live_program_can_be_changed_2(){
change_source('ANOTHER')
assert true
}
fn test_live_program_has_ended(){
time.sleep_ms(10*1000)
assert true
}

View File

@ -1,7 +0,0 @@
module local
pub fn local_fn() bool {
return true
}

View File

@ -1,7 +0,0 @@
import compiler.tests.local
fn test_local_module_is_callable() {
assert local.local_fn()
}

View File

@ -1,93 +0,0 @@
enum Color{
red, green, blue
}
fn test_match_integers() {
mut a := 3
mut b := 0
match a {
2 { println('two') }
3 {
println('three')
b = 3
}
4 { println('four') }
else { println('???') }
}
assert b == 3
assert match 2 {
1 { 2 }
2 { 3 }
else { 5 }
} == 3
assert match 0 {
1 { 2 }
2 { 3 }
else 5
} == 5
assert match 1 {
else { 5 }
} == 5
a = 0
match 2 {
0 { a = 1 }
1 { a = 2 }
else {
a = 3
println('a is $a')
}
}
assert a == 3
a = 0
match 1 {
0 { a = 1 }
1 {
a = 2
a = a + 2
a = a + 2
}
else {}
}
assert a == 6
a = 0
match 1 {
else {
a = -2
}
}
assert a == -2
}
fn test_match_enums(){
mut b := Color.red
match b{
.red {
b = .green
}
.green {
b = .blue
}
else {
println('b is ${b.str()}')
b = .red
}
}
assert b == .green
match b{
.red {
b = .green
}
else {
println('b is ${b.str()}')
b = .blue
}
}
assert b == .blue
}

View File

@ -1,25 +0,0 @@
import os
import time as t
import crypto.sha256 as s2
import (
math
log as l
crypto.sha512 as s5
)
struct TestAliasInStruct {
time t.Time
}
fn test_import() {
assert os.O_RDONLY == os.O_RDONLY && t.month_days[0] == t.month_days[0] && s2.size == s2.size && math.pi == math.pi && l.INFO == l.INFO && s5.size == s5.size
}
fn test_alias_in_struct_field() {
a := TestAliasInStruct{
time: t.Time{
year: 2020
}
}
assert a.time.year == 2020
}

View File

@ -1,5 +0,0 @@
/*
module acommentedmodule
*/

View File

@ -1,16 +0,0 @@
module amodule
// This tests whether _test.v files can be *internal* to a
// module, and thus have access to its guts.
// NB: the function test_private_isub() is defined both here
// and inside internal_module_test.v . That is done on purpose,
// with the goal of ensuring that _test.v files are compiled
// *independently* from each other.
//
// _test.v files should *only* import all the other normal .v
// files from the same folder, NOT other _test.v files from it.
fn test_private_isub(){
assert private_isub(7,5) == 2
}

View File

@ -1,16 +0,0 @@
module amodule
// this tests whether _test.v files can be *internal*
// to a module, and thus have access to its guts.
fn test_iadd(){
assert iadd(10, 20) == 30
}
fn test_imul(){
assert imul(5,8) == 40
}
fn test_private_isub(){
assert private_isub(10,6) == 4
}

View File

@ -1,15 +0,0 @@
module amodule
pub fn iadd(x int, y int) int {
return x + y
}
pub fn imul(x int, y int) int {
return x * y
}
///////////////////////////////////////
fn private_isub(x int, y int) int {
return x - y
}

View File

@ -1,11 +0,0 @@
import simplemodule
// this tests whether the tests can import the same module without any special
// custom paths setup on the CLI
fn test_iadd(){
assert simplemodule.iadd(10, 20) == 30
}
fn test_imul(){
assert simplemodule.imul(5,8) == 40
}

View File

@ -1,9 +0,0 @@
module simplemodule
pub fn iadd(x int, y int) int {
return x + y
}
pub fn imul(x int, y int) int {
return x * y
}

View File

@ -1,51 +0,0 @@
fn test_flag_parsing() {
mut rest := '-lGlfw -f gl2,-ltest_nice_meme,-l cc,-Ldl test.o a.o ' //, whatever.o'
result := ['-l', 'Glfw',
'-f', 'gl2',
'-l', 'test_nice_meme',
'-l', 'cc',
'-L', 'dl',
'', 'test.o',
'', 'a.o']
mut flags := []string
for {
mut base := rest
fl := if rest.starts_with('-') {
base = rest[2..].trim_space()
rest[..2]
} else {
''
}
// Which ever one of these is lowest we use
// TODO: we really shouldnt support all of these cmon
mut lowest := base.index('-') or { -1 }
a := base.index(' ') or { -1 }
b := base.index(',') or { -1 }
for x in [a, b] {
if (x < lowest && x != -1) || lowest == -1 {
lowest = x
}
}
arg := if lowest != -1 {
rest = base[lowest..].trim_space().trim(',')
base[..lowest].trim_space().trim(',')
} else {
rest = ''
base.trim_space()
}
flags << fl
flags << arg
if rest.len == 0 {
break
}
}
for i, f in flags {
assert f == result[i]
}
}

View File

@ -1,18 +0,0 @@
fn multi_voidptr_ret() (voidptr, bool) {
return voidptr(0), true
}
fn multi_byteptr_ret() (byteptr, bool) {
return byteptr(0), true
}
fn test_multi_ptrtype_ret() {
a, b := multi_voidptr_ret()
assert a == voidptr(0)
assert b == true
c, d := multi_byteptr_ret()
assert c == byteptr(0)
assert d == true
}

View File

@ -1,53 +0,0 @@
struct A {
pub mut:
v []int
}
struct B {
pub mut:
a []A
}
fn foo(b int, a mut []int) {
a[0] = 7
//a << 4
}
fn test_mut() {
mut numbers := [1,2,3]
foo(7, mut numbers)
assert numbers.len == 3
// TODO bring back once << works with mutable args
//assert numbers.len == 4
//assert numbers[0] == 7
//assert numbers[3] == 4
println(numbers)
n := 1
mut b := &n
*b = 10
//mut b := mut a
//b = 10
}
fn test_mut_2() {
zero := 0
mut b := B{}
b.a << A{}
b.a[0].v = [9, 8, 7]
b.a[0].v << 6
b.a[zero].v << 5
b.a[0].v[zero] = 3
b.a[0].v[b.a[zero].v[zero]]+= 2 -1 // TODO
b.a[0].v[b.a[0].v[zero]]+= 2 - 1 // TODO
assert b.a[0].v.len == 5
assert b.a[0].v[0] == 3
assert b.a[0].v[1] == 8
assert b.a[0].v[2] == 7
assert b.a[0].v[3] == 8
assert b.a[0].v[4] == 5
}

View File

@ -1,16 +0,0 @@
fn simple<T>(p T) string {
tname := nameof(T)
println("Hello generic, I'm an [$tname]")
return tname
}
struct FunkyStruct{ }
fn test_nameof_on_various_types_in_generic() {
assert simple(42) == "int"
assert simple(3.14) == "f64"
assert simple("FuBar") == "string"
assert simple(FunkyStruct{}) == "FunkyStruct"
assert simple(test_nameof_on_various_types_in_generic) == "fn ()"
}

View File

@ -1,164 +0,0 @@
fn opt_err_with_code() ?string {return error_with_code('hi',137)}
fn test_err_with_code(){
v := opt_err_with_code() or {
assert err == 'hi'
assert errcode == 137
return
}
assert false
println(v) // suppress not used error
}
fn opt_err() ?string {return error('hi')}
fn test_err(){
v := opt_err() or {
assert err == 'hi'
return
}
assert false
println(v) // suppress not used error
}
fn err_call(ok bool) ?int {
if !ok {
return error('Not ok!')
}
return 42
}
fn ret_none() ?int {
//return error('wtf') //none
return none
}
fn test_option_for_base_type_without_variable() {
val := err_call(true) or {
panic(err)
}
assert val == 42
println('hm')
val2 := ret_none() or {
println('yep')
return
}
println('$val2 should have been `none`')
assert false
// This is invalid:
// x := 5 or {
// return
// }
}
fn test_if_opt() {
if val := err_call(false) {
assert val == 42
}
assert 1 == 1
println('nice')
}
fn for_opt_default() ?string {
return error('awww')
}
fn test_opt_default() {
a := for_opt_default() or {
// panic(err)
'default'
}
assert a == 'default'
}
fn foo_ok() ?int {
return 777
}
fn foo_str() ?string {
return 'something'
}
fn test_q() {
//assert foo_ok()? == true
}
struct Person {
mut:
name string
age int
title ?string
}
fn test_field_or() {
name := foo_str() or {
'nada'
}
assert name == 'something'
mut p := Person {}
p.name = foo_str() or {
'nothing'
}
assert p.name == 'something'
p.age = foo_ok() or {
panic('no age')
}
assert p.age == 777
mytitle := p.title or {
'default'
}
assert mytitle == 'default'
}
struct Thing {
mut:
opt ?int
}
fn test_opt_field() {
mut t := Thing{}
t.opt = 5
val := t.opt or { return }
assert val == 5
}
fn opt_ptr(a &int) ?&int {
if isnil(a) {
return none
}
return a
}
fn test_opt_ptr() {
a := 3
r1 := opt_ptr(&a) or {
&int(0)
}
assert r1 == &a
r2 := opt_ptr(&int(0)) or {
return
}
println('`$r2` should be none')
assert false
}
fn multi_return_opt(err bool) ?(string, string) {
if err {
return error('oops')
}
return 'hello', 'v'
}
fn test_multi_return_opt() {
a, b := multi_return_opt(false) or {
panic(err)
}
assert a == 'hello' && b == 'v'
_, _ := multi_return_opt(true) or {
assert err == 'oops'
return
}
}

View File

@ -1,27 +0,0 @@
fn test_pointer_arithmetic() {
arr := [1,2,3,4]
unsafe {
mut parr := *int(arr.data)
parr++
assert 2 == *parr
parr++
assert 3 == *parr
assert *(parr + 1) == 4
}
}
fn test_multi_level_pointer_dereferencing() {
n := 100
pn := &n
ppn := &pn
unsafe {
mut pppn := &ppn
***pppn = 300
pppa := ***int(pppn)
assert 300 == ***pppa
}
assert n == 300 // updated by the unsafe pointer manipulation
}

View File

@ -1,3 +0,0 @@
fn test_print() {
println(2.0)
}

View File

@ -1,2 +0,0 @@
/*.prod
/*.result.txt

View File

@ -1,14 +0,0 @@
struct MyStruct {
s string
}
fn new_st() MyStruct {
return MyStruct{}
}
fn get_st() MyStruct {
r := new_st()
return {r|s:'6'}
}
fn main() {
s := get_st()
println(s)
}

View File

@ -1,3 +0,0 @@
MyStruct {
s: 6
}

View File

@ -1,28 +0,0 @@
// Build and run files in ./prod/ folder, comparing their output to *.expected.txt files.
// (Similar to REPL tests, but in -prod mode.)
// import os
import compiler.tests.repl.runner
import benchmark
fn test_all_v_prod_files() {
// TODO: Fix running this test on Windows:
$if !windows {
options := runner.new_prod_options()
mut bmark := benchmark.new_benchmark()
for file in options.files {
// println('file:$file')
bmark.step()
fres := runner.run_prod_file(options.wd, options.vexec, file) or {
bmark.fail()
eprintln(bmark.step_message_fail(err))
assert false
continue
}
bmark.ok()
println(bmark.step_message_ok(fres))
assert true
}
bmark.stop()
println(bmark.total_message('total time spent running PROD files'))
}
}

View File

@ -1,3 +0,0 @@
main
mod1/c/implementation.o
main_test

View File

@ -1,4 +0,0 @@
Do not delete this file.
It is used by V to stop the lookup for v.mod,
so that the top level vlib/v.mod is not found,
if you delete mod1/v.mod .

View File

@ -1,8 +0,0 @@
module main
import mod1
fn main(){
res := mod1.vadd(1,2)
println( res )
}

View File

@ -1,5 +0,0 @@
import mod1
fn test_using_c_code_in_the_same_module_works(){
assert 1003 == mod1.vadd(1,2)
}

View File

@ -1,6 +0,0 @@
#ifndef ADD_H
#define ADD_H
int cadd(int a, int b);
#endif

View File

@ -1,5 +0,0 @@
#include "header.h"
int cadd(int a, int b) {
return a + b;
}

View File

@ -1,7 +0,0 @@
#V Module#
Module {
name: 'mod1',
description: 'A simple module, containing C code.',
dependencies: []
}

View File

@ -1,12 +0,0 @@
module mod1
#flag -I @VROOT/c
#flag @VROOT/c/implementation.o
#include "header.h"
fn C.cadd(int,int) int
pub fn vadd(a int, b int) int {
return 1000 + C.cadd(a,b)
}

View File

@ -1,2 +0,0 @@
/bin/main
/tests/submodule_test

View File

@ -1,16 +0,0 @@
This projects demonstrates how v.mod lookup can be used so that
a project/module can be as selfcontained as possible.
The programs under bin/ can find the modules mod1,
because the project has a 'v.mod' file, so v module lookup for
the programs under bin/ can still find the parent sibling folder
mod1/ through relation to the parent 'v.mod' file.
Note also that mod1/ also has its own 'v.mod' file.
This allows mod1 submodules to find and import themselves
in relation to it too.
Finally, there is a test/ folder, so you can put all your tests
in there, without cluttering your top level folder, or your module
folders if you so desire.

View File

@ -1,12 +0,0 @@
import mod1.submodule as m
fn test_mod1_can_still_be_found_through_parent_project_vmod(){
assert 1051 == m.f()
}
/*
NB: this main program is under bin/ , but it still
can find mod1, because the parent project has v.mod,
so v module lookup for this program will find mod1 through
relation to the parent v.mod file
*/

View File

@ -1,14 +0,0 @@
#!/usr/local/bin/v run
import mod1.submodule as m
println('This script is located inside: ' + resource_abs_path(''))
println('The result of calling m.f is: ' + m.f().str() )
/*
NB: this main program v script is under bin/ ,
but it *still* can find mod1, because the parent project has v.mod,
so v module lookup for this bin/main.vsh file will find mod1 through
relation to the parent ../v.mod file
*/

View File

@ -1,5 +0,0 @@
module mod1
pub fn f() int {
return 1
}

View File

@ -1,5 +0,0 @@
module mod11
pub fn f() int {
return 11
}

View File

@ -1,5 +0,0 @@
module mod12
pub fn f() int {
return 12
}

View File

@ -1,5 +0,0 @@
module mod13
pub fn f() int {
return 13
}

View File

@ -1,7 +0,0 @@
module mod14
import math
pub fn f() int {
return 14 + int(math.cos(0))
}

View File

@ -1,16 +0,0 @@
module submodule
/*
This submodule just imports its sibling submodules.
Note that they are NOT under 'submodule' itself,
but are in its parent mod1 , and mod1 has a 'v.mod' file.
*/
import mod11
import mod12
import mod13
import mod14
pub fn f() int {
return 1000 + mod11.f() + mod12.f() + mod13.f() + mod14.f()
}

View File

@ -1,7 +0,0 @@
#V Module#
Module {
name: 'mod1',
description: 'A module with several submodules.',
dependencies: []
}

View File

@ -1,11 +0,0 @@
import mod1
import mod1.submodule
fn test_mod1(){
assert 1 == mod1.f()
}
fn test_mod1_submodule_can_find_and_use_all_its_sibling_submodules(){
assert 1051 == submodule.f()
}

View File

@ -1,7 +0,0 @@
#V Project#
Module {
name: 'project_with_modules_having_submodules',
description: 'This project was created with `v create` to prevent regressions with the way V module import lookup works.',
dependencies: []
}

View File

@ -1,15 +0,0 @@
// verify fix for #2913
fn some_multiret_fn(a int, b int) (int, int) {
return a+1, b+1
}
fn test_repeated_multiple_multiret() {
a, b := some_multiret_fn(1,2)
assert a == 2
assert b == 3
c, d := some_multiret_fn(3,4)
assert c == 4
assert d == 5
}

View File

@ -1,2 +0,0 @@
*.repl text=auto eol=lf

View File

@ -1,3 +0,0 @@
run
*.repl.result.txt
*.repl.expected.txt

View File

@ -1,25 +0,0 @@
# V REPL Tests Script
### How to write a new test
- Create a new file named `*.repl`
- Write the input to be given to REPL
- Add `===output===`
- Write the output expected
### Notes
Keep in mind, that the way V repl works for now, every non empty line
would cause a new recompilation of the entire repl content that was
collected so far.
*Longer REPL files would cause measurably*
*longer recompilation/testing times.*
Also, longer repl files would be slower to debug when they fail,
*It is better to have several smaller files vs one huge REPL file.*
### Example :
```
a := 1
println(a)
===output===
1

View File

@ -1,4 +0,0 @@
a := [1,2,3]
println('hi' in a)
===output===
.vrepl.v:2:18: bad element type: `string` in `[]int`

View File

@ -1,17 +0,0 @@
struct A { mut: v int } struct B { a A } struct C { mut: b B } struct D { mut: c C }
mut b := B{} b = B{A{2}}
b.a.v = 1 // Error (field a immutable)
b.a = A{} // Error (field a immutable)
===output===
cannot modify immutable field `a` (type `B`)
declare the field with `mut:`
struct B {
mut:
a A
}
cannot modify immutable field `a` (type `B`)
declare the field with `mut:`
struct B {
mut:
a A
}

View File

@ -1,17 +0,0 @@
struct A { mut: v int } struct B { a A } struct C { mut: b B } struct D { mut: c C }
mut c := C{} c.b = B{}
c.b.a = A{} // Error (field a immutable)
c.b.a.v = 1 // Error (field a immutable)
===output===
cannot modify immutable field `a` (type `B`)
declare the field with `mut:`
struct B {
mut:
a A
}
cannot modify immutable field `a` (type `B`)
declare the field with `mut:`
struct B {
mut:
a A
}

View File

@ -1,5 +0,0 @@
struct A { mut: v int } struct B { a A } struct C { mut: b B } struct D { mut: c C }
c2 := C{}
c2.b = B{} // Error (c2 immutable)
===output===
`c2` is immutable

View File

@ -1,5 +0,0 @@
struct A { mut: v int } struct B { a A } struct C { mut: b B } struct D { mut: c C }
mut d := D{} d.c.b = B{}
'OK'
===output===
OK

View File

@ -1,19 +0,0 @@
struct E { mut: v []int } struct F { e []E } mut f := F{}
f.e << E{} // Error (field e immutable)
f.e[0].v << 1 // Error (field e immutable)
e := E{}
e.v << 1 // Error (e immutable)
===output===
cannot modify immutable field `e` (type `F`)
declare the field with `mut:`
struct F {
mut:
e []E
}
cannot modify immutable field `e` (type `F`)
declare the field with `mut:`
struct F {
mut:
e []E
}
`e` is immutable (can't <<)

View File

@ -1,8 +0,0 @@
for i := 0; i < 4; i++ {
println(i)
}
===output===
0
1
2
3

View File

@ -1,5 +0,0 @@
if true {
println('foo')
}
===output===
foo

View File

@ -1,7 +0,0 @@
if false {
println('foo')
} else {
println('bar')
}
===output===
bar

View File

@ -1,6 +0,0 @@
num := 1 string := 'Hello'
num
string
===output===
1
Hello

View File

@ -1,4 +0,0 @@
struct Empty{} ee := Empty{}
println('OK')
===output===
OK

View File

@ -1,3 +0,0 @@
import compiler.tests.modules.acommentedmodule
===output===
vlib/compiler/tests/modules/acommentedmodule/commentedfile.v:7:1: bad module definition: vlib/compiler/tests/modules/acommentedmodule/commentedfile.v imports module "compiler.tests.modules.acommentedmodule" but vlib/compiler/tests/modules/acommentedmodule/commentedfile.v is defined as module `main`

View File

@ -1,3 +0,0 @@
println(a)
===output===
.vrepl.v:2:9: undefined: `a`

View File

@ -1,5 +0,0 @@
a
33
===output===
undefined: `a`
33

View File

@ -1,4 +0,0 @@
fn test() { println('foo') } test() fn test2(a int) { println(a) } test2(42)
===output===
foo
42

View File

@ -1,11 +0,0 @@
mut s := 'hello world'
s.len = 0 // Error (field len immutable)
'BYE'
===output===
cannot modify immutable field `len` (type `string`)
declare the field with `mut:`
struct string {
mut:
len int
}
BYE

View File

@ -1,11 +0,0 @@
mut a := []string
a.len = 0 // Error (field len immutable)
'BYE'
===output===
cannot modify immutable field `len` (type `array`)
declare the field with `mut:`
struct array {
mut:
len int
}
BYE

View File

@ -1,11 +0,0 @@
mut ints := []int
ints.len = 0 // Error (field len immutable)
println('BYE')
===output===
cannot modify immutable field `len` (type `array`)
declare the field with `mut:`
struct array {
mut:
len int
}
BYE

View File

@ -1,8 +0,0 @@
name := 'Bob' age := 20 large_number := i64(9999999999)
println(name)
println(age)
println(large_number)
===output===
Bob
20
9999999999

View File

@ -1,7 +0,0 @@
println('Hello World')
println('Foo Bar')
println('dlroW olleH')
===output===
Hello World
Foo Bar
dlroW olleH

View File

@ -1,5 +0,0 @@
'abc'
'abc'+'xyz'
===output===
abc
abcxyz

View File

@ -1,3 +0,0 @@
===output===

View File

@ -1,4 +0,0 @@
a := 1
println(a)
===output===
1

View File

@ -1 +0,0 @@
===output===

View File

@ -1,5 +0,0 @@
'{'
'}'
===output===
{
}

View File

@ -1,7 +0,0 @@
fn foo() ?bool {return true}
fn main() {
foo()? // only works in main()
println('done')
}
===output===
done

View File

@ -1,4 +0,0 @@
mut a := 10 a++ a++ a++ a--
a
===output===
12

View File

@ -1,7 +0,0 @@
println('Hello, world!')
println('Привет, мир!')
println('你好世界')
===output===
Hello, world!
Привет, мир!
你好世界

View File

@ -1,90 +0,0 @@
module main
import os
import compiler.tests.repl.runner
import benchmark
import sync
fn test_the_v_compiler_can_be_invoked() {
vexec := runner.full_path_to_v(5)
println('vexecutable: $vexec')
assert vexec != ''
vcmd := '"$vexec" -version'
r := os.exec(vcmd) or {
panic(err)
}
// println('"$vcmd" exit_code: $r.exit_code | output: $r.output')
assert r.exit_code == 0
vcmd_error := '"$vexec" nonexisting.v'
r_error := os.exec(vcmd_error) or {
panic(err)
}
// println('"$vcmd_error" exit_code: $r_error.exit_code | output: $r_error.output')
assert r_error.exit_code == 1
assert r_error.output == "V error: nonexisting.v doesn't exist"
}
struct Session {
mut:
options runner.RunnerOptions
bmark benchmark.Benchmark
}
fn test_all_v_repl_files() {
mut session := &Session{
options: runner.new_options()
bmark: benchmark.new_benchmark()
}
// warmup, and ensure that the vrepl is compiled in single threaded mode if it does not exist
runner.run_repl_file(os.cache_dir(), session.options.vexec, 'vlib/compiler/tests/repl/nothing.repl') or {
panic(err)
}
session.bmark.set_total_expected_steps(session.options.files.len)
mut pool_repl := sync.new_pool_processor({
callback: worker_repl
})
pool_repl.set_shared_context(session)
$if windows {
// See: https://docs.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=vs-2019
pool_repl.set_max_jobs(1)
}
pool_repl.work_on_items(session.options.files)
session.bmark.stop()
println(session.bmark.total_message('total time spent running REPL files'))
}
fn worker_repl(p mut sync.PoolProcessor, idx int, thread_id int) voidptr {
cdir := os.cache_dir()
mut session := &Session(p.get_shared_context())
mut tls_bench := &benchmark.Benchmark(p.get_thread_context(idx))
if isnil(tls_bench) {
tls_bench = benchmark.new_benchmark_pointer()
tls_bench.set_total_expected_steps(session.bmark.nexpected_steps)
p.set_thread_context(idx, tls_bench)
}
tls_bench.cstep = idx
tfolder := os.join_path(cdir, 'vrepl_tests_$idx')
if os.is_dir(tfolder) {
os.rmdir_all(tfolder)
}
os.mkdir(tfolder) or {
panic(err)
}
file := p.get_string_item(idx)
session.bmark.step()
tls_bench.step()
fres := runner.run_repl_file(tfolder, session.options.vexec, file) or {
session.bmark.fail()
tls_bench.fail()
os.rmdir_all(tfolder)
eprintln(tls_bench.step_message_fail(err))
assert false
return sync.no_result
}
session.bmark.ok()
tls_bench.ok()
os.rmdir_all(tfolder)
println(tls_bench.step_message_ok(fres))
assert true
return sync.no_result
}

View File

@ -1,24 +0,0 @@
module main
import compiler.tests.repl.runner
import log
import benchmark
fn main() {
mut logger := log.Log{}
logger.set_level(log.DEBUG)
options := runner.new_options()
mut bmark := benchmark.new_benchmark()
for file in options.files {
bmark.step()
fres := runner.run_repl_file(options.wd, options.vexec, file) or {
bmark.fail()
logger.error(bmark.step_message_fail(err))
continue
}
bmark.ok()
logger.info(bmark.step_message_ok(fres))
}
bmark.stop()
logger.info(bmark.total_message('total time spent running REPL files'))
}

Some files were not shown because too many files have changed in this diff Show More