2022-08-09 13:27:12 +02:00
package tests
import (
2022-08-14 12:32:17 +02:00
"fmt"
"os"
"path/filepath"
"strings"
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/generics/slices"
2022-10-15 18:47:55 +02:00
"github.com/jesseduffield/lazycore/pkg/utils"
2022-08-12 01:19:39 +02:00
"github.com/jesseduffield/lazygit/pkg/integration/components"
2022-08-22 11:34:02 +02:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/bisect"
2022-08-09 13:27:12 +02:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/branch"
2022-09-17 07:15:02 +02:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/cherry_pick"
2022-08-09 13:27:12 +02:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/commit"
2022-08-14 11:15:21 +02:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands"
2022-08-09 13:27:12 +02:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
2022-09-16 03:41:27 +02:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/stash"
2022-08-14 12:32:17 +02:00
"github.com/jesseduffield/lazygit/pkg/utils"
2022-08-09 13:27:12 +02:00
)
// Here is where we lists the actual tests that will run. When you create a new test,
// be sure to add it to this list.
2022-08-14 12:32:17 +02:00
var tests = [ ] * components . IntegrationTest {
2022-08-09 13:27:12 +02:00
commit . Commit ,
commit . NewBranch ,
branch . Suggestions ,
2022-08-22 12:02:40 +02:00
branch . Delete ,
2022-08-22 12:43:19 +02:00
branch . Rebase ,
branch . RebaseAndDrop ,
2022-08-09 13:27:12 +02:00
interactive_rebase . One ,
2022-09-10 17:00:40 +02:00
interactive_rebase . AmendMerge ,
2022-08-14 11:15:21 +02:00
custom_commands . Basic ,
2022-08-14 12:13:39 +02:00
custom_commands . MultiplePrompts ,
2022-08-14 13:18:12 +02:00
custom_commands . MenuFromCommand ,
2022-08-22 11:34:02 +02:00
bisect . Basic ,
2022-08-22 11:52:05 +02:00
bisect . FromOtherBranch ,
2022-09-17 07:15:02 +02:00
cherry_pick . CherryPick ,
cherry_pick . CherryPickConflicts ,
2022-08-09 18:52:19 +02:00
custom_commands . FormPrompts ,
2022-10-07 03:29:06 +02:00
stash . Stash ,
2022-10-07 03:23:13 +02:00
stash . StashIncludingUntrackedFiles ,
2022-10-15 04:57:19 +02:00
stash . Rename ,
2022-08-09 13:27:12 +02:00
}
2022-08-14 12:32:17 +02:00
func GetTests ( ) [ ] * components . IntegrationTest {
// first we ensure that each test in this directory has actually been added to the above list.
testCount := 0
testNamesSet := set . NewFromSlice ( slices . Map (
tests ,
func ( test * components . IntegrationTest ) string {
return test . Name ( )
} ,
) )
missingTestNames := [ ] string { }
2022-10-15 18:47:55 +02:00
if err := filepath . Walk ( filepath . Join ( utils . GetLazyRootDirectory ( ) , "pkg/integration/tests" ) , func ( path string , info os . FileInfo , err error ) error {
2022-08-14 12:32:17 +02:00
if ! info . IsDir ( ) && strings . HasSuffix ( path , ".go" ) {
// ignoring this current file
if filepath . Base ( path ) == "tests.go" {
return nil
}
2022-09-17 07:15:02 +02:00
// the shared directory won't itself contain tests: only shared helper functions
if filepath . Base ( filepath . Dir ( path ) ) == "shared" {
return nil
}
2022-08-14 12:32:17 +02:00
nameFromPath := components . TestNameFromFilePath ( path )
if ! testNamesSet . Includes ( nameFromPath ) {
missingTestNames = append ( missingTestNames , nameFromPath )
}
testCount ++
}
return nil
} ) ; err != nil {
panic ( fmt . Sprintf ( "failed to walk tests: %v" , err ) )
}
if len ( missingTestNames ) > 0 {
panic ( fmt . Sprintf ( "The following tests are missing from the list of tests: %s. You need to add them to `pkg/integration/tests/tests.go`." , strings . Join ( missingTestNames , ", " ) ) )
}
if testCount > len ( tests ) {
panic ( "you have not added all of the tests to the tests list in `pkg/integration/tests/tests.go`" )
} else if testCount < len ( tests ) {
panic ( "There are more tests in `pkg/integration/tests/tests.go` than there are test files in the tests directory. Ensure that you only have one test per file and you haven't included the same test twice in the tests list." )
}
return tests
}