...
1 package internal
2
3 import (
4 "regexp"
5 "strings"
6
7 "github.com/onsi/ginkgo/v2/types"
8 )
9
10
28 func ApplyNestedFocusPolicyToTree(tree *TreeNode) {
29 var walkTree func(tree *TreeNode) bool
30 walkTree = func(tree *TreeNode) bool {
31 if tree.Node.MarkedPending {
32 return false
33 }
34 hasFocusedDescendant := false
35 for _, child := range tree.Children {
36 childHasFocus := walkTree(child)
37 hasFocusedDescendant = hasFocusedDescendant || childHasFocus
38 }
39 tree.Node.MarkedFocus = tree.Node.MarkedFocus && !hasFocusedDescendant
40 return tree.Node.MarkedFocus || hasFocusedDescendant
41 }
42
43 walkTree(tree)
44 }
45
46
59 func ApplyFocusToSpecs(specs Specs, description string, suiteLabels Labels, suiteConfig types.SuiteConfig) (Specs, bool) {
60 focusString := strings.Join(suiteConfig.FocusStrings, "|")
61 skipString := strings.Join(suiteConfig.SkipStrings, "|")
62
63 type SkipCheck func(spec Spec) bool
64
65
66 skipChecks := []SkipCheck{func(spec Spec) bool { return spec.Nodes.HasNodeMarkedPending() }}
67 hasProgrammaticFocus := false
68
69 for _, spec := range specs {
70 if spec.Nodes.HasNodeMarkedFocus() && !spec.Nodes.HasNodeMarkedPending() {
71 hasProgrammaticFocus = true
72 break
73 }
74 }
75
76 if hasProgrammaticFocus {
77 skipChecks = append(skipChecks, func(spec Spec) bool { return !spec.Nodes.HasNodeMarkedFocus() })
78 }
79
80 if suiteConfig.LabelFilter != "" {
81 labelFilter, _ := types.ParseLabelFilter(suiteConfig.LabelFilter)
82 skipChecks = append(skipChecks, func(spec Spec) bool {
83 return !labelFilter(UnionOfLabels(suiteLabels, spec.Nodes.UnionOfLabels()))
84 })
85 }
86
87 if len(suiteConfig.FocusFiles) > 0 {
88 focusFilters, _ := types.ParseFileFilters(suiteConfig.FocusFiles)
89 skipChecks = append(skipChecks, func(spec Spec) bool { return !focusFilters.Matches(spec.Nodes.CodeLocations()) })
90 }
91
92 if len(suiteConfig.SkipFiles) > 0 {
93 skipFilters, _ := types.ParseFileFilters(suiteConfig.SkipFiles)
94 skipChecks = append(skipChecks, func(spec Spec) bool { return skipFilters.Matches(spec.Nodes.CodeLocations()) })
95 }
96
97 if focusString != "" {
98
99 re := regexp.MustCompile(focusString)
100 skipChecks = append(skipChecks, func(spec Spec) bool { return !re.MatchString(description + " " + spec.Text()) })
101 }
102
103 if skipString != "" {
104
105 re := regexp.MustCompile(skipString)
106 skipChecks = append(skipChecks, func(spec Spec) bool { return re.MatchString(description + " " + spec.Text()) })
107 }
108
109
110 processedSpecs := Specs{}
111 for _, spec := range specs {
112 for _, skipCheck := range skipChecks {
113 if skipCheck(spec) {
114 spec.Skip = true
115 break
116 }
117 }
118 processedSpecs = append(processedSpecs, spec)
119 }
120
121 return processedSpecs, hasProgrammaticFocus
122 }
123
View as plain text