From be323e2fb6a0e053b329d966aa83f312f1bf4932 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 6 Dec 2019 02:11:39 +0300 Subject: [PATCH] ci: set up pg database to test ORM --- .github/workflows/ci.yml | 6 +++++- tools/modules/testing/common.v | 23 +++++++++++++---------- tools/vtest-compiler.v | 26 +++++++++++++------------- tools/vtest.v | 6 +++--- vlib/builtin/array_test.v | 24 ++++++++++++++---------- 5 files changed, 48 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 496527b192..5edfead89f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: node-version: 12.x - name: Install dependencies run: | - brew install freetype glfw openssl + brew install freetype glfw openssl postgres export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/" - name: Build V run: make && ./v -o v v.v @@ -37,6 +37,10 @@ jobs: run: ./v -o v2 v.v && ./v2 -o v3 v.v - name: Test symlink run: sudo ./v symlink + - name: Set up pg database + run: | + psql -U postgres -c 'create database customerdb;' + psql -d customerdb -f examples/database/pg/mydb.sql - name: Test v->c run: ./v test-compiler - name: Test v binaries diff --git a/tools/modules/testing/common.v b/tools/modules/testing/common.v index 2fe008c66d..519e41f5c2 100644 --- a/tools/modules/testing/common.v +++ b/tools/modules/testing/common.v @@ -19,7 +19,7 @@ pub mut: fail string } -pub fn new_test_sesion(vargs string) TestSession { +pub fn new_test_session(vargs string) TestSession { return TestSession{ vexe: vexe_path() vargs: vargs @@ -50,6 +50,9 @@ pub fn (ts mut TestSession) test() { $if windows { if file.contains('sqlite') { continue } } + $if !macos { + if file.contains('customer') { continue } + } $if msvc { if file.contains('asm') { continue } } @@ -108,11 +111,11 @@ pub fn v_build_failing(zargs string, folder string) bool { parent_dir := os.dir(vexe) vlib_should_be_present( parent_dir ) vargs := zargs.replace(vexe, '') - + eprintln(main_label) eprintln(' v compiler args: "$vargs"') - - mut session := new_test_sesion( vargs ) + + mut session := new_test_session( vargs ) files := os.walk_ext(filepath.join(parent_dir, folder),'.v') mains := files.filter(!it.contains('modules')) mut rebuildable_mains := mains @@ -148,8 +151,8 @@ pub fn building_any_v_binaries_failed() bool { parent_dir := os.dir(vexe) testing.vlib_should_be_present( parent_dir ) os.chdir( parent_dir ) - - mut failed := false + + mut failed := false v_build_commands := [ // '$vexe -o v_g -g v.v', @@ -160,11 +163,11 @@ pub fn building_any_v_binaries_failed() bool { '$vexe -o v_prod -prod v.v', ] - + mut bmark := benchmark.new_benchmark() bok := term.ok_message('OK') bfail := term.fail_message('FAIL') - for cmd in v_build_commands { + for cmd in v_build_commands { bmark.step() if build_v_cmd_failed(cmd) { bmark.fail() @@ -174,10 +177,10 @@ pub fn building_any_v_binaries_failed() bool { continue } bmark.ok() - eprintln(bmark.step_message('$cmd => ${bok}')) + eprintln(bmark.step_message('$cmd => ${bok}')) } bmark.stop() eprintln( bmark.total_message( 'building v binaries' ) ) - + return failed } diff --git a/tools/vtest-compiler.v b/tools/vtest-compiler.v index a7c21fff78..728155e3f4 100644 --- a/tools/vtest-compiler.v +++ b/tools/vtest-compiler.v @@ -5,7 +5,7 @@ import ( testing benchmark filepath -) +) pub const ( v_modules_path = os.home_dir() + '.vmodules' @@ -21,18 +21,18 @@ fn v_test_compiler(vargs string){ vexe := testing.vexe_path() parent_dir := os.dir(vexe) testing.vlib_should_be_present( parent_dir ) - + // Changing the current directory is needed for some of the compiler tests, // compiler/tests/local_test.v and compiler/tests/repl/repl_test.v os.chdir( parent_dir ) - + /* if !os.exists(parent_dir + '/v.v') { eprintln('v.v is missing, it must be next to the V executable') exit(1) } */ - + // Make sure v.c can be compiled without warnings $if macos { if os.exists('/v.v') { @@ -44,11 +44,11 @@ fn v_test_compiler(vargs string){ eprintln('v.c can be compiled without warnings. This is good :)') } } - + building_tools_failed := testing.v_build_failing(vargs, 'tools') - + eprintln('\nTesting all _test.v files...') - mut compiler_test_session := testing.new_test_sesion( vargs ) + mut compiler_test_session := testing.new_test_session( vargs ) compiler_test_session.files << os.walk_ext(parent_dir, '_test.v') compiler_test_session.test() eprintln( compiler_test_session.benchmark.total_message('running V tests') ) @@ -57,7 +57,7 @@ fn v_test_compiler(vargs string){ building_examples_failed := testing.v_build_failing(vargs, 'examples') eprintln('') - building_live_failed := testing.v_build_failing(vargs + '-live', + building_live_failed := testing.v_build_failing(vargs + '-live', filepath.join( 'examples', 'hot_reload')) eprintln('') @@ -73,12 +73,12 @@ fn v_test_compiler(vargs string){ } vmark.stop() eprintln( 'Installing a v module took: ' + vmark.total_duration().str() + 'ms') - - if building_tools_failed || - compiler_test_session.failed || - building_examples_failed || + + if building_tools_failed || + compiler_test_session.failed || + building_examples_failed || building_live_failed { exit(1) } - + } diff --git a/tools/vtest.v b/tools/vtest.v index ba192501b8..cb061c2c7d 100644 --- a/tools/vtest.v +++ b/tools/vtest.v @@ -2,7 +2,7 @@ module main import ( os - testing + testing ) pub fn main() { @@ -29,8 +29,8 @@ pub fn main() { eprintln('Use `v test-compiler` instead.') exit(1) } - - mut ts := testing.new_test_sesion(args_before) + + mut ts := testing.new_test_session(args_before) for targ in args_after.split(' ') { if os.exists(targ) && targ.ends_with('_test.v') { ts.files << targ diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index 716034d5f8..73b0ba69f1 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -223,7 +223,7 @@ fn test_right_with_n_bigger_than_array_size() { // mut b := a[10..] mut b := a.right(10) assert b.len == 0 - + // also check that the result of a.right // is an array of the same type/element size as a: b << 5 @@ -285,6 +285,10 @@ const ( N = 5 ) +struct Foooj { + a [N]int +} + fn test_fixed() { mut nums := [4]int assert nums[0] == 0 @@ -368,7 +372,7 @@ fn test_single_element() { assert a[0] == 1 assert a[1] == 2 println(a) -} +} fn test_find_index() { // string @@ -452,7 +456,7 @@ fn test_filter() { d := c.filter(it.len > 1) assert d[0] == 'is' assert d[1] == 'awesome' -} +} fn test_map() { a := [1, 2, 3, 4, 5, 6] @@ -471,8 +475,8 @@ fn test_map() { assert bools[0] == true assert bools[1] == false assert bools[2] == false - -} + +} fn test_array_str() { numbers := [1, 2, 3] @@ -502,7 +506,7 @@ fn test_sort() { assert nums[2] == 42 assert nums[3] == 67 assert nums[4] == 108 -} +} @@ -514,10 +518,10 @@ fn test_for_last() { s += '$num' if !last { s += ', ' - - } - } + + } + } s += ']' assert s == '[1, 2, 3, 4]' -} +} */