bench_test.odin (2122B)
1 package bench 2 3 import "core:os" 4 import "core:path/filepath" 5 import "core:strings" 6 import "core:testing" 7 import "jm:sh" 8 9 @(test) 10 bench_counts_what_fires :: proc(t: ^testing.T) { 11 context.allocator = context.temp_allocator 12 temp := os.temp_directory(context.temp_allocator) or_else "" 13 root, err := os.make_directory_temp(temp, "review-bench-*", context.temp_allocator) 14 testing.expect(t, err == nil) 15 defer os.remove_all(root) 16 git := proc(root: string, args: ..string) -> bool { 17 argv := make([dynamic]string, context.temp_allocator) 18 append( 19 &argv, 20 "git", 21 "-c", 22 "user.email=t@t", 23 "-c", 24 "user.name=t", 25 "-c", 26 "commit.gpgsign=false", 27 ) 28 append(&argv, ..args) 29 return sh.exec(argv[:], {dir = root}, context.temp_allocator).ok 30 } 31 write := proc(root, name, src: string) -> bool { 32 path := filepath.join({root, name}, context.temp_allocator) or_else name 33 return os.write_entire_file(path, transmute([]byte)src) == nil 34 } 35 testing.expect(t, git(root, "init", "-q")) 36 testing.expect(t, write(root, "x.go", "package x\n")) 37 testing.expect(t, git(root, "add", "x.go")) 38 testing.expect(t, git(root, "commit", "-q", "-m", "x: begin")) 39 testing.expect(t, write(root, "x.go", "package x\n\nvar a = 1\n")) 40 testing.expect(t, git(root, "add", "x.go")) 41 testing.expect(t, git(root, "commit", "-q", "-m", "whoops")) 42 testing.expect(t, write(root, "x.go", "package x\n\nvar a = 1\nvar b = 2\n")) 43 testing.expect(t, git(root, "add", "x.go")) 44 testing.expect(t, git(root, "commit", "-q", "-m", "x: add b")) 45 46 out, run_err := run(root, Options{n = 10}, nil) 47 testing.expect_value(t, run_err, "") 48 testing.expect(t, strings.contains(out, "2 commits measured"), out) 49 testing.expect(t, strings.contains(out, "message-frustration"), out) 50 listed, _ := run(root, Options{n = 10, rule = "message-frustration"}, nil) 51 testing.expect(t, strings.contains(listed, "whoops"), listed) 52 testing.expect( 53 t, 54 strings.contains(listed, "message-frustration fired on 1 of 2 commits"), 55 listed, 56 ) 57 _, none := run(root, Options{n = 10, author = "nobody-here"}, nil) 58 testing.expect_value(t, none, "no commits to measure") 59 }