-
Notifications
You must be signed in to change notification settings - Fork 64
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 #64 from Funfun/tests_for_generate_pkg
Add basic tests for generate.ImportPry
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.go.go | ||
*.zip | ||
fuzz/ | ||
*.coverprofile |
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,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) | ||
} |