2022-08-09 21:27:12 +10:00
package tests
import (
2022-08-14 20:32:17 +10:00
"fmt"
"os"
"path/filepath"
"strings"
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/generics/slices"
2022-10-15 13:47:55 -03:00
"github.com/jesseduffield/lazycore/pkg/utils"
2022-08-12 09:19:39 +10:00
"github.com/jesseduffield/lazygit/pkg/integration/components"
2022-08-22 19:34:02 +10:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/bisect"
2022-08-09 21:27:12 +10:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/branch"
2022-09-16 22:15:02 -07:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/cherry_pick"
2022-08-09 21:27:12 +10:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/commit"
2022-11-24 12:56:03 +01:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/config"
2022-08-14 19:15:21 +10:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands"
2022-12-21 22:52:23 +11:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/diff"
2022-11-11 12:16:38 +11:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/file"
2022-12-28 18:17:28 +11:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/filter_by_path"
2022-08-09 21:27:12 +10:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
2022-12-20 23:08:39 +11:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/misc"
2023-01-18 21:05:40 +05:30
"github.com/jesseduffield/lazygit/pkg/integration/tests/patch_building"
2022-09-15 23:11:27 -02:30
"github.com/jesseduffield/lazygit/pkg/integration/tests/stash"
2022-12-28 17:39:45 +11:00
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
2022-08-09 21:27:12 +10: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 20:32:17 +10:00
var tests = [ ] * components . IntegrationTest {
2022-12-20 23:08:39 +11:00
misc . ConfirmOnQuit ,
2022-11-12 18:09:10 -03:30
bisect . Basic ,
bisect . FromOtherBranch ,
2022-10-16 21:31:42 +09:00
branch . CheckoutByName ,
2022-08-22 20:02:40 +10:00
branch . Delete ,
2022-08-22 20:43:19 +10:00
branch . Rebase ,
branch . RebaseAndDrop ,
2022-11-12 18:09:10 -03:30
branch . Suggestions ,
2022-12-19 22:38:32 +11:00
branch . Reset ,
2023-01-27 20:14:03 +09:00
branch . DetachedHead ,
2022-09-16 22:15:02 -07:00
cherry_pick . CherryPick ,
cherry_pick . CherryPickConflicts ,
2022-11-12 18:09:10 -03:30
commit . Commit ,
2022-12-20 22:18:26 +11:00
commit . CommitMultiline ,
2022-12-20 22:31:59 +11:00
commit . Revert ,
2022-11-12 18:09:10 -03:30
commit . NewBranch ,
2022-11-27 17:33:37 +01:00
commit . Staged ,
commit . Unstaged ,
2022-11-28 19:40:29 +01:00
commit . StagedWithoutHooks ,
2022-12-28 13:01:32 +11:00
commit . DiscardOldFileChange ,
2022-11-12 18:09:10 -03:30
custom_commands . Basic ,
2022-08-09 19:52:19 +03:00
custom_commands . FormPrompts ,
2022-11-12 18:09:10 -03:30
custom_commands . MenuFromCommand ,
2022-11-25 22:09:02 +01:00
custom_commands . MenuFromCommandsOutput ,
2022-11-12 18:09:10 -03:30
custom_commands . MultiplePrompts ,
2022-11-11 12:16:38 +11:00
file . DirWithUntrackedFile ,
2022-12-24 16:46:01 +11:00
file . DiscardChanges ,
2022-12-28 13:24:23 +11:00
file . DiscardStagedChanges ,
2022-12-28 17:15:59 +11:00
file . GitIgnore ,
2022-11-12 18:09:10 -03:30
interactive_rebase . AmendMerge ,
interactive_rebase . One ,
stash . Rename ,
stash . Stash ,
stash . StashIncludingUntrackedFiles ,
2022-11-24 12:56:03 +01:00
config . RemoteNamedStar ,
2022-12-21 22:52:23 +11:00
diff . Diff ,
diff . DiffAndApplyPatch ,
diff . DiffCommits ,
2023-02-07 13:33:10 +01:00
diff . IgnoreWhitespace ,
2022-12-28 17:39:45 +11:00
sync . FetchPrune ,
2022-12-28 17:52:04 +11:00
sync . RenameBranchAndPull ,
2022-12-28 18:17:28 +11:00
filter_by_path . CliArg ,
filter_by_path . SelectFile ,
filter_by_path . TypeFile ,
2023-01-18 21:05:40 +05:30
patch_building . BuildPatchAndCopyToClipboard ,
2022-08-09 21:27:12 +10:00
}
2022-08-14 20:32:17 +10: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 13:47:55 -03:00
if err := filepath . Walk ( filepath . Join ( utils . GetLazyRootDirectory ( ) , "pkg/integration/tests" ) , func ( path string , info os . FileInfo , err error ) error {
2022-08-14 20:32:17 +10:00
if ! info . IsDir ( ) && strings . HasSuffix ( path , ".go" ) {
// ignoring this current file
if filepath . Base ( path ) == "tests.go" {
return nil
}
2022-09-16 22:15:02 -07: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 20:32:17 +10: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
}