From ef454680dc447a22e6dd2905a32e48f4183d344a Mon Sep 17 00:00:00 2001 From: jguer Date: Mon, 7 Aug 2017 10:53:20 +0100 Subject: [PATCH] Fixed tests for unified structure --- pacman_test.go | 62 -------------------------------------------------- print_test.go | 36 +++++++++++++++++++++++++++++ query_test.go | 27 ++++++++++++++++++++++ vcs_test.go | 6 ++--- 4 files changed, 66 insertions(+), 65 deletions(-) delete mode 100644 pacman_test.go create mode 100644 print_test.go create mode 100644 query_test.go diff --git a/pacman_test.go b/pacman_test.go deleted file mode 100644 index a8852a4c..00000000 --- a/pacman_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package main - -import ( - "os" - "testing" - - "github.com/jguer/yay/config" -) - -func benchmarkPrintSearch(search string, b *testing.B) { - old := os.Stdout - _, w, _ := os.Pipe() - os.Stdout = w - - for n := 0; n < b.N; n++ { - res, _, _ := Search(append([]string{}, search)) - res.PrintSearch() - } - os.Stdout = old -} - -func BenchmarkPrintSearchSimpleTopDown(b *testing.B) { - config.YayConf.SortMode = config.TopDown - benchmarkPrintSearch("chromium", b) -} -func BenchmarkPrintSearchComplexTopDown(b *testing.B) { - config.YayConf.SortMode = config.TopDown - benchmarkPrintSearch("linux", b) -} - -func BenchmarkPrintSearchSimpleBottomUp(b *testing.B) { - config.YayConf.SortMode = config.BottomUp - benchmarkPrintSearch("chromium", b) -} -func BenchmarkPrintSearchComplexBottomUp(b *testing.B) { - config.YayConf.SortMode = config.BottomUp - benchmarkPrintSearch("linux", b) -} - -func benchmarkSearch(search string, b *testing.B) { - for n := 0; n < b.N; n++ { - Search(append([]string{}, search)) - } -} -func BenchmarkSearchSimpleTopDown(b *testing.B) { - config.YayConf.SortMode = config.TopDown - benchmarkSearch("chromium", b) -} - -func BenchmarkSearchSimpleBottomUp(b *testing.B) { - config.YayConf.SortMode = config.BottomUp - benchmarkSearch("chromium", b) -} - -func BenchmarkSearchComplexTopDown(b *testing.B) { - config.YayConf.SortMode = config.TopDown - benchmarkSearch("linux", b) -} -func BenchmarkSearchComplexBottomUp(b *testing.B) { - config.YayConf.SortMode = config.BottomUp - benchmarkSearch("linux", b) -} diff --git a/print_test.go b/print_test.go new file mode 100644 index 00000000..fec362d8 --- /dev/null +++ b/print_test.go @@ -0,0 +1,36 @@ +package main + +import ( + "os" + "testing" +) + +func benchmarkPrintSearch(search string, b *testing.B) { + old := os.Stdout + _, w, _ := os.Pipe() + os.Stdout = w + + for n := 0; n < b.N; n++ { + res, _, _ := queryRepo(append([]string{}, search)) + res.printSearch() + } + os.Stdout = old +} + +func BenchmarkPrintSearchSimpleTopDown(b *testing.B) { + config.SortMode = TopDown + benchmarkPrintSearch("chromium", b) +} +func BenchmarkPrintSearchComplexTopDown(b *testing.B) { + config.SortMode = TopDown + benchmarkPrintSearch("linux", b) +} + +func BenchmarkPrintSearchSimpleBottomUp(b *testing.B) { + config.SortMode = BottomUp + benchmarkPrintSearch("chromium", b) +} +func BenchmarkPrintSearchComplexBottomUp(b *testing.B) { + config.SortMode = BottomUp + benchmarkPrintSearch("linux", b) +} diff --git a/query_test.go b/query_test.go new file mode 100644 index 00000000..5e26624b --- /dev/null +++ b/query_test.go @@ -0,0 +1,27 @@ +package main + +import "testing" + +func benchmarkSearch(search string, b *testing.B) { + for n := 0; n < b.N; n++ { + queryRepo(append([]string{}, search)) + } +} +func BenchmarkSearchSimpleTopDown(b *testing.B) { + config.SortMode = TopDown + benchmarkSearch("chromium", b) +} + +func BenchmarkSearchSimpleBottomUp(b *testing.B) { + config.SortMode = BottomUp + benchmarkSearch("chromium", b) +} + +func BenchmarkSearchComplexTopDown(b *testing.B) { + config.SortMode = TopDown + benchmarkSearch("linux", b) +} +func BenchmarkSearchComplexBottomUp(b *testing.B) { + config.SortMode = BottomUp + benchmarkSearch("linux", b) +} diff --git a/vcs_test.go b/vcs_test.go index d72044df..f6e96dd9 100644 --- a/vcs_test.go +++ b/vcs_test.go @@ -12,20 +12,20 @@ func TestParsing(t *testing.T) { } neovim := source{sourceurl: "git+https://github.com/neovim/neovim.git"} - neovim.owner, neovim.repo = ParseSource(neovim.sourceurl) + neovim.owner, neovim.repo = parseSource(neovim.sourceurl) if neovim.owner != "neovim" || neovim.repo != "neovim" { t.Fatalf("Expected to find neovim/neovim, found %+v/%+v", neovim.owner, neovim.repo) } yay := source{sourceurl: "git://github.com/jguer/yay.git#branch=master"} - yay.owner, yay.repo = ParseSource(yay.sourceurl) + yay.owner, yay.repo = parseSource(yay.sourceurl) if yay.owner != "jguer" || yay.repo != "yay" { t.Fatalf("Expected to find jguer/yay, found %+v/%+v", yay.owner, yay.repo) } ack := source{sourceurl: "git://github.com/davidgiven/ack"} - ack.owner, ack.repo = ParseSource(ack.sourceurl) + ack.owner, ack.repo = parseSource(ack.sourceurl) if ack.owner != "davidgiven" || ack.repo != "ack" { t.Fatalf("Expected to find davidgiven/ack, found %+v/%+v", ack.owner, ack.repo) }