Skip to content

Commit

Permalink
Merge pull request #64 from Funfun/tests_for_generate_pkg
Browse files Browse the repository at this point in the history
Add basic tests for generate.ImportPry
  • Loading branch information
d4l3k committed Sep 29, 2018
2 parents d9fb2c4 + 222843a commit 0793567
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.go.go
*.zip
fuzz/
*.coverprofile
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ before_install:

script:
- go test -v -race -coverprofile=pry.coverprofile ./pry
- go test -v -race -coverprofile=generate.coverprofile ./generate
- go test -v -race -coverprofile=main.coverprofile
- $HOME/gopath/bin/gover
- $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=gover.coverprofile
47 changes: 47 additions & 0 deletions generate/generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package generate

import (
"os"
"path/filepath"
"testing"
)

func TestImportPry(t *testing.T) {
g := NewGenerator(false)
file := "../example/file/file.go"
res, err := g.InjectPry(file)

if err != nil {
t.Errorf("Failed to inject pry %v", err)
}

if !fileExists(res) {
t.Error("Source file not found")
}

pryFile := filepath.Join(filepath.Dir(res), ".file.gopry")
if !fileExists(pryFile) {
t.Error("Pry file not found")
}

// clean up
g.RevertPry([]string{res})

if !fileExists(file) {
t.Error("Source file not found")
}

res, err = g.InjectPry("nonexisting.go")
if res != "" {
t.Error("Non empty result received")
}

if fileExists(".nonexisting.gopry") {
t.Error("Pry file should not exists")
}
}

func fileExists(filePath string) bool {
_, err := os.Stat(filePath)
return !os.IsNotExist(err)
}

0 comments on commit 0793567

Please sign in to comment.