Skip to content

Commit

Permalink
move unvetted tests to untested, remove passing_list (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
JalonSolov authored Aug 4, 2024
1 parent bf04be1 commit 715d717
Show file tree
Hide file tree
Showing 264 changed files with 39 additions and 66 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ v run .

```

To run a single test:
To attempt a new test, specify the path to the directory as well as
the name of the test:

```bash
v .
./go2v array_byte
./go2v untested/block
```

When a test passes, move it from `untested` to `tests`.
2 changes: 1 addition & 1 deletion expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn (mut app App) expr(expr Expr) {
app.selector_expr(expr)
}
TypeOrIdent {
app.type_or_ident(expr)
type_or_ident(expr)
}
CompositeLit {
app.composite_lit(expr)
Expand Down
10 changes: 5 additions & 5 deletions fn_decl.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ fn (mut app App) func_decl(decl Decl) {
// println('FUNC DECL ${method_name}')
mut recv := ''
if decl.recv.list.len > 0 {
recv_type := app.type_or_ident(decl.recv.list[0].typ)
recv_type := type_or_ident(decl.recv.list[0].typ)
recv_name := decl.recv.list[0].names[0].name
recv = '(${recv_name} ${recv_type})'
}
// params := decl.typ.params.list.map(it.names.map(it.name).join(', ') + ' ' +
// app.type_or_ident(it.typ)).join(', ')
// type_or_ident(it.typ)).join(', ')
results := if decl.typ.results.list.len > 0 {
' ${decl.typ.results.list.map(app.type_or_ident(it.typ)).join(', ')}'
' ${decl.typ.results.list.map(type_or_ident(it.typ)).join(', ')}'
} else {
''
}
Expand All @@ -28,15 +28,15 @@ fn (mut app App) func_decl(decl Decl) {
}

fn (mut app App) func_params(params FieldList) {
p := params.list.map(it.names.map(it.name).join(', ') + ' ' + app.type_or_ident(it.typ)).join(', ')
p := params.list.map(it.names.map(it.name).join(', ') + ' ' + type_or_ident(it.typ)).join(', ')
app.gen('(')
app.gen(p)
app.gen(')')
/*
for i, param in params.list {
app.gen(param.names[0].name)
app.gen(' ')
app.gen(app.type_or_ident(param.typ))
app.gen(type_or_ident(param.typ))
if i < params.list.len - 1 {
app.gen(',')
}
Expand Down
81 changes: 25 additions & 56 deletions main.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,6 @@ import os
import term
import strings

const passing_tests = [
'struct_simple',
'method',
'operators',
'fn_call',
'fn_case',
'append',
'for_c_style_inc',
'for_in',
'operation',
'match',
'arrays',
'math_expr',
'if',
'if_complex_condition',
'if_else_if',
'array',
'array_byte',
'array_fixed_size',
'defer',
'defer_multiple',
'map',
'if_nested',
'import_strings',
]

struct App {
mut:
sb strings.Builder
Expand Down Expand Up @@ -70,13 +44,13 @@ fn (mut app App) generate_v_code(go_file GoFile) string {
return app.sb.str()
}

fn (app &App) type_or_ident(typ TypeOrIdent) string {
fn type_or_ident(typ TypeOrIdent) string {
return if typ.elt.name != '' { '[]${typ.elt.name}' } else { typ.name }
}

fn (mut app App) run_test(test_name string) ! {
go_file_path := 'tests/${test_name}/${test_name}.go.json'
expected_v_code_path := 'tests/${test_name}/${test_name}.vv'
fn (mut app App) run_test(subdir string, test_name string) ! {
go_file_path := '${subdir}/${test_name}/${test_name}.go.json'
expected_v_code_path := '${subdir}/${test_name}/${test_name}.vv'

go_file := parse_go_ast(go_file_path) or {
eprintln('Failed to parse Go AST: ${err}')
Expand All @@ -87,7 +61,7 @@ fn (mut app App) run_test(test_name string) ! {

generated_v_code := app.generate_v_code(go_file)

v_path := tmpdir + '/${test_name}.v'
v_path := '${tmpdir}/${test_name}.v'
os.write_file(v_path, generated_v_code) or { panic(err) }
res := os.execute('v fmt -w ${v_path}')
if res.exit_code != 0 {
Expand Down Expand Up @@ -144,48 +118,43 @@ fn print_diff_line(formatted_v_code string, expected_v_code string) {
}
}

fn trim_space(s string) string {
return s.replace('\n\n', '\n')
}

fn main() {
mut subdir := 'tests'

go_file_name := if os.args.len > 1 { os.args[1] } else { '' }

mut app := &App{
sb: strings.new_builder(1000)
}

if go_file_name != '' {
app.run_test(go_file_name)!
subdir = os.dir(go_file_name)
test_name := os.base(go_file_name)

if !os.exists('${subdir}/${test_name}/${test_name}.go.json') {
println('generating ast for ${test_name}')
os.system('asty go2json -indent 2 -input ${subdir}/${test_name}/${test_name}.go -output ${subdir}/${test_name}/${test_name}.go.json')
}

app.run_test(subdir, test_name)!
return
}
test_names := os.ls('tests') or { return }

mut test_names := os.ls('tests') or { return }
test_names.sort()
//.filter(it.ends_with('.go'))
//.map(it.replace('.go', ''))

// test_names.sort(it.split('.')[0]

for test_name in test_names {
if test_name !in passing_tests {
continue
}
// println(test_name)
if !os.exists('tests/${test_name}/${test_name}.go.json') {
if !os.exists('${subdir}/${test_name}/${test_name}.go.json') {
println('generating ast for ${test_name}')
os.system('asty go2json -indent 2 -input tests/${test_name}/${test_name}.go -output tests/${test_name}/${test_name}.go.json')

continue
os.system('asty go2json -indent 2 -input ${subdir}/${test_name}/${test_name}.go -output ${subdir}/${test_name}/${test_name}.go.json')
}
// Extract the number before the first dot
// test_number_str := test_name.before('.')
// test_number := test_number_str.int()

// Continue if the number is greater than what we need
// if test_number > nr_tests {
// continue
//}
// for test_name in test_names {

println('===========================================')

app.run_test(test_name) or {
app.run_test(subdir, test_name) or {
eprintln('Error running test ${test_name}: ${err}')
break
}
Expand Down
2 changes: 1 addition & 1 deletion struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn (mut app App) struct_decl(spec Spec) {
app.genln('pub mut:')
}
for field in spec.typ.fields.list {
type_name := app.type_or_ident(field.typ)
type_name := type_or_ident(field.typ)
for n in field.names {
app.genln('\t${go2v_ident(n.name)} ${go2v_type(type_name)}')
}
Expand Down
3 changes: 2 additions & 1 deletion tests/fn/fn.vv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module main

fn abc(a int, b []string, c rune) string {}
fn abc(a int, b []string, c rune) string {
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 715d717

Please sign in to comment.