Skip to content

Commit

Permalink
basic support for python tests
Browse files Browse the repository at this point in the history
At the moment only running tests of changes file works - which is
usefull for my scenario with Coding katas containing unit tests
emvbedded within.
  • Loading branch information
michal-franc committed Jun 27, 2021
1 parent 58a3d3f commit a925c31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Support for more types of files and test runners so that if I change python a py

### Current limitations
- very basic and not optimized
- only `GO` supported at the moment
- only `GO`, `Python` supported at the moment
- watches all the files - even `.git` file changes

### Usage
Expand All @@ -24,6 +24,7 @@ Commands
rgt start
--go-test-runner string Specifies which go test runner to use. (default "go", supports gotestsum)
--sub-folder-only If set true will run only tests from the folder the file that is changed in.
--type string Specifiec which type of test to start : [golang, python]
```

### Installation
Expand Down
31 changes: 19 additions & 12 deletions internal/app/rgt/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import (
var watcher *fsnotify.Watcher
var goTestRunner string
var runTestsIntheSubFolder bool
var testType string
var supportedTypes = [...]string{"golang", "python"}

func init() {
startCmd.Flags().StringVar(&goTestRunner, "go-test-runner", "go", "Specifies which go test runner to use.")
startCmd.Flags().StringVar(&testType, "test-type", "golang", fmt.Sprintf("Specifies which test runner to run supported. %s", supportedTypes))
startCmd.Flags().BoolVar(&runTestsIntheSubFolder, "sub-folder-only", false, "If set true will run only tests from the folder the file that is changed is.")
rootCmd.AddCommand(startCmd)
}
Expand Down Expand Up @@ -83,19 +86,23 @@ var startCmd = &cobra.Command{

var cmd *exec.Cmd

//TODO: support for any test runner from config like gotestsum - hacky mess at the moment
if goTestRunner == "go" {
if runTestsIntheSubFolder {
cmd = exec.Command("go", "test")
cmd.Dir = extractDir(lastFileWritten)
} else {
cmd = exec.Command("go", "test", "./...")
}
} else if goTestRunner == "gotestsum" {
cmd = exec.Command(goTestRunner)
if runTestsIntheSubFolder {
cmd.Dir = extractDir(lastFileWritten)
if testType == "golang" {
//TODO: support for any test runner from config like gotestsum - hacky mess at the moment
if goTestRunner == "go" {
if runTestsIntheSubFolder {
cmd = exec.Command("go", "test")
cmd.Dir = extractDir(lastFileWritten)
} else {
cmd = exec.Command("go", "test", "./...")
}
} else if goTestRunner == "gotestsum" {
cmd = exec.Command(goTestRunner)
if runTestsIntheSubFolder {
cmd.Dir = extractDir(lastFileWritten)
}
}
} else {
cmd = exec.Command("pytest", fmt.Sprintf("./%s", *fPath))
}

if cmd == nil {
Expand Down

0 comments on commit a925c31

Please sign in to comment.