-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser: fix infinite loop in Parser.sql stmt in `-silent -print-watch…
…ed-files` mode (used by `v watch`) (#20873)
- Loading branch information
Showing
5 changed files
with
147 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
vlib/v/parser/testdata/silent/orm_infinite_loop_in_parser_sql_stmt.vv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module main | ||
|
||
import db.sqlite | ||
|
||
@[table: 'modules'] | ||
struct Module { | ||
id int @[primary; sql: serial] | ||
name string | ||
nr_downloads int @[sql: u64] | ||
creator User | ||
} | ||
|
||
struct User { | ||
id int @[primary; sql: serial] | ||
age u32 @[unique: 'user'] | ||
name string @[sql: 'username'; sql_type: 'VARCHAR(200)'; unique] | ||
is_customer bool @[sql: 'abc'; unique: 'user'] | ||
skipped_string string @[skip] | ||
} | ||
|
||
struct Parent { | ||
id int @[primary; sql: serial] | ||
name string | ||
children []Child @[fkey: 'parent_id'] | ||
} | ||
|
||
struct Child { | ||
id int @[primary; sql: serial] | ||
parent_id int | ||
name string | ||
} | ||
|
||
fn main() { | ||
eprintln('------------ ${@METHOD} -----------------') | ||
mut db := sqlite.connect(':memory:')! | ||
defer { | ||
sql db { | ||
drop table Parent | ||
drop table Child | ||
} or {} | ||
db.close() or {} | ||
} | ||
|
||
sql db { | ||
create table Parent | ||
}! | ||
sql db { | ||
create table Child | ||
}! | ||
par := Parent{ | ||
name: 'test' | ||
children: [ | ||
Child{ | ||
name: 'abc' | ||
}, | ||
Child{ | ||
name: 'def' | ||
}, | ||
] | ||
} | ||
sql db { | ||
insert par into Parent | ||
}! | ||
sql db { | ||
select from Parent where id == 1 & name == "whatever" | ||
}! | ||
eprintln(parent) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
|
||
const vexe = @VEXE | ||
const vroot = os.dir(vexe) | ||
|
||
fn test_print_v_files_in_stdout_mode() { | ||
check_parsing_files_in_folder('vlib/v/parser/testdata/stdout', '-print-v-files') | ||
} | ||
|
||
// | ||
|
||
fn test_print_v_files_in_silent_mode() { | ||
check_parsing_files_in_folder('vlib/v/parser/testdata/silent', '-silent -print-v-files') | ||
} | ||
|
||
fn test_print_watched_files_in_silent_mode__used_by_vwatch() { | ||
check_parsing_files_in_folder('vlib/v/parser/testdata/silent', '-silent -print-watched-files') | ||
} | ||
|
||
fn check_parsing_files_in_folder(folder string, options string) { | ||
println('> checking .vv files in folder: `${folder}`, with `${options}` ...') | ||
files := os.walk_ext(os.join_path(vroot, folder), '.vv') | ||
for f in files { | ||
cmd := '${os.quoted_path(vexe)} ${options} ${os.quoted_path(f)}' | ||
// eprintln('> cmd: $cmd') | ||
res := os.execute(cmd) | ||
assert res.exit_code == 0, 'failed cmd: ${cmd}, output:\n${res.output}' | ||
assert res.output.split_into_lines().len > 10, 'there should be several files printed by cmd: ${cmd}' | ||
} | ||
} |