-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from matsuyoshi30/add-tests
Add tests
- Loading branch information
Showing
11 changed files
with
111 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: test | ||
on: | ||
push: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- 'README.md' | ||
- '.github/' | ||
pull_request: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- 'README.md' | ||
- '.github/' | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go-version: [1.16.x] | ||
os: [ubuntu-latest, macos-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Build | ||
run: go build | ||
- name: Test | ||
run: make test |
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,67 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"image" | ||
"image/png" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var genGoldenFiles = flag.Bool("gen_golden_files", false, "whether to generate the golden files fot test") | ||
|
||
func TestRun(t *testing.T) { | ||
filepath.Walk("./testdata", func(path string, info os.FileInfo, err error) error { | ||
if strings.HasSuffix(path, ".sh") { | ||
cmd := exec.Command("bash", filepath.Base(path)) | ||
cmd.Dir = filepath.Dir(path) | ||
if err := cmd.Run(); err != nil { | ||
t.Errorf("FAIL: %v\n", err) | ||
} else { | ||
filename := strings.TrimSuffix(path, filepath.Ext(path)) | ||
if *genGoldenFiles { | ||
if err := os.Rename(filename+"-gen.png", filename+".png"); err != nil { | ||
t.Errorf("FAIL: %v\n", err) | ||
} | ||
t.Logf("Generate file: %s\n", filename+"-want.png") | ||
return nil | ||
} | ||
|
||
wantFile := filename + ".png" | ||
want, err := os.Open(wantFile) | ||
if err != nil { | ||
t.Errorf("FAIL: Reading want file: %s", wantFile) | ||
} | ||
wantImg, err := png.Decode(want) | ||
if err != nil { | ||
t.Errorf("FAIL: Decoding want file: %s", wantFile) | ||
} | ||
|
||
gotFile := filename + "-gen.png" | ||
got, err := os.Open(gotFile) | ||
if err != nil { | ||
t.Errorf("FAIL: Reading got file: %s", gotFile) | ||
} | ||
gotImg, err := png.Decode(got) | ||
if err != nil { | ||
t.Errorf("FAIL: Decoding got file: %s", gotFile) | ||
} | ||
|
||
if reflect.DeepEqual(wantImg.(*image.RGBA), gotImg.(*image.RGBA)) { | ||
t.Logf("PASS: %s\n", path) | ||
} else { | ||
t.Errorf("FAIL: output differs: %s\n", path) | ||
} | ||
|
||
if err := os.Remove(gotFile); err != nil { | ||
t.Errorf("FAIL: cleanup got file: %s\n", path) | ||
} | ||
} | ||
} | ||
return nil | ||
}) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,2 @@ | ||
#!/bin/bash | ||
../germanium main.go -o default-gen.png |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,2 @@ | ||
#!/bin/bash | ||
../germanium --no-line-number main.go -o no-line-num-gen.png |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,2 @@ | ||
#!/bin/bash | ||
../germanium --no-window-access-bar main.go -o no-window-access-bar-gen.png |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,2 @@ | ||
#!/bin/bash | ||
../germanium --no-line-number --no-window-access-bar main.go -o only-editor-gen.png |