Skip to content

Commit df36362

Browse files
committed
support solutions that read from stdin, and 2 part solutions, where the first ends with part1.v, and the second with part2.v
1 parent 68aadb5 commit df36362

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

verify.v

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ fn vrun(v_file string) !(string, time.Duration, time.Duration) {
1515
local_file_name := os.file_name(v_file)
1616
vdir := os.dir(v_file)
1717
executable_name := local_file_name.replace('.v', '.exe')
18+
mut input_files := []string{}
19+
input_files << os.walk_ext('.', '.input')
20+
if input_files.len == 0 {
21+
input_files << os.walk_ext('..', '.input')
22+
}
23+
if input_files.len == 0 {
24+
eprintln('there should be *at least* 1 .input file in the folder ${vdir}, or in its parent folder.')
25+
return error('missing .input file')
26+
}
1827

1928
compilation_cmd := '${vexe} -o ${executable_name} ${local_file_name}'
2029
sw_compilation := time.new_stopwatch()
@@ -28,7 +37,11 @@ fn vrun(v_file string) !(string, time.Duration, time.Duration) {
2837
v_lines := os.read_lines(local_file_name)!
2938
skip_run := v_lines.any(it.starts_with('// verify: norun'))
3039
if !skip_run {
31-
run_cmd := './${executable_name}'
40+
input_file := find_proper_input_file(input_files, v_file)
41+
run_cmd := './${executable_name} < ${input_file}'
42+
$if trace_input_selection ? {
43+
println('\n>> v_file: ${v_file} | input_files: ${input_files} | input_file: ${input_file}')
44+
}
3245
sw_running := time.new_stopwatch()
3346
res := os.execute(run_cmd)
3447
run_time_took = sw_running.elapsed()
@@ -40,6 +53,17 @@ fn vrun(v_file string) !(string, time.Duration, time.Duration) {
4053
return output, compile_time_took, run_time_took
4154
}
4255

56+
fn find_proper_input_file(input_files []string, v_file string) string {
57+
mut input_file := input_files.first()
58+
if v_file.ends_with('part1.v') {
59+
input_file = input_files.filter(it.ends_with('part1.input'))[0] or { input_file }
60+
}
61+
if v_file.ends_with('part2.v') {
62+
input_file = input_files.filter(it.ends_with('part2.input'))[0] or { input_file }
63+
}
64+
return input_file
65+
}
66+
4367
fn v_file2out_file(v_file string) string {
4468
return os.real_path(os.join_path(wd, 'known', v_file.replace('.v', '.out')))
4569
}

0 commit comments

Comments
 (0)