Skip to content

Commit

Permalink
run tests with v test .
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Sep 22, 2024
1 parent 598478f commit 985293b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
run: v .

- name: Run tests
run: v -g run .
run: v -g test .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ it can find `go` in your path.

## Testing

To run the existing tests, do `v run .`
To run the existing tests, do `v test .`

To attempt a new test, specify the path to the directory as well as
the name of the test:
Expand Down
33 changes: 33 additions & 0 deletions go2v_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module main

import strings
import os

fn test_all() {
mut subdir := 'tests'
mut app := &App{
sb: strings.new_builder(1000)
}

// All tests
mut test_names := os.ls('tests') or { return }
test_names.sort()
mut tests_ok := true
for test_name in test_names {
println('===========================================')
create_json(subdir, test_name)
// A separate instance for each test
mut app2 := &App{
sb: strings.new_builder(1000)
}
app2.run_test(subdir, test_name) or {
eprintln('Error running test ${test_name}: ${err}')
break
}
tests_ok &&= app2.tests_ok
}
// if !app.tests_ok {
if !tests_ok {
exit(1)
}
}
36 changes: 12 additions & 24 deletions main.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2024 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module main

import os
import term
import strings
Expand Down Expand Up @@ -201,17 +203,23 @@ fn main() {
eprintln(err)
exit(1)
}

mut subdir := 'tests'
mut go_file_name := if os.args.len > 1 { os.args[1] } else { '' }
/*
if !go_file_name.ends_with('.go') {
eprintln("usage: go2v file.go")
return
}
*/
mut app := &App{
sb: strings.new_builder(1000)
}
// Not a test
if go_file_name.ends_with('.go') {
app.translate_file(go_file_name)
return
}

mut subdir := 'tests'

// A single test
if go_file_name != '' {
go_file_name = go_file_name.trim_right('/')
Expand All @@ -221,25 +229,5 @@ fn main() {
app.run_test(subdir, test_name)!
return
}
// All tests
mut test_names := os.ls('tests') or { return }
test_names.sort()
mut tests_ok := true
for test_name in test_names {
println('===========================================')
create_json(subdir, test_name)
// A separate instance for each test
mut app2 := &App{
sb: strings.new_builder(1000)
}
app2.run_test(subdir, test_name) or {
eprintln('Error running test ${test_name}: ${err}')
break
}
tests_ok &&= app2.tests_ok
}
// if !app.tests_ok {
if !tests_ok {
exit(1)
}
eprintln('usage: go2v file.go or go2v tests/test')
}

0 comments on commit 985293b

Please sign in to comment.