|
4 | 4 | "errors" |
5 | 5 | "fmt" |
6 | 6 | "regexp" |
| 7 | + "slices" |
7 | 8 | "strings" |
8 | 9 |
|
9 | 10 | "blitznote.com/src/semver/v3" |
@@ -84,35 +85,68 @@ func findMinimumSupported(target Target, tests []TestDescription) (*semver.Range |
84 | 85 | continue |
85 | 86 | } |
86 | 87 |
|
87 | | - // We need to find the minimum version of the target module by looking |
88 | | - // through the dependencies list and the inspecting the semver range |
89 | | - // strings associated with it. |
90 | | - for key, val := range test.Dependencies { |
91 | | - if key != target.Name { |
| 88 | + if test.Dependencies != nil { |
| 89 | + // We need to find the minimum version of the target module by looking |
| 90 | + // through the dependencies list and the inspecting the semver range |
| 91 | + // strings associated with it. |
| 92 | + for key, val := range test.Dependencies { |
| 93 | + if key != target.Name { |
| 94 | + continue |
| 95 | + } |
| 96 | + |
| 97 | + var currentVersion semver.Range |
| 98 | + |
| 99 | + // The semver library does not parse strings like `>1.0.0 <2.0.0 || >3.0.0`. |
| 100 | + // So we need to split it up and normalize the pieces into range strings |
| 101 | + // it can understand. |
| 102 | + rangeStrings := strings.Split(val.Versions, "||") |
| 103 | + for k, v := range rangeStrings { |
| 104 | + // Oh, Go, why no slices.Map? |
| 105 | + rangeStrings[k] = normalizeRangeString(v) |
| 106 | + } |
| 107 | + |
| 108 | + currentVersion, err := processRangeStrings(rangeStrings) |
| 109 | + if err != nil { |
| 110 | + return nil, fmt.Errorf("`%s` => `%s`: %w", target, val.Versions, err) |
| 111 | + } |
| 112 | + |
| 113 | + if lastVersion == nil { |
| 114 | + lastVersion = ¤tVersion |
| 115 | + continue |
| 116 | + } |
| 117 | + |
| 118 | + if isRangeLower(currentVersion, *lastVersion) == true { |
| 119 | + lastVersion = ¤tVersion |
| 120 | + } |
| 121 | + } |
| 122 | + } else if test.GroupedDependencies != nil { |
| 123 | + // As above, but for a `groupedDependencies` block instead. We should |
| 124 | + // always have one or the other. |
| 125 | + if slices.Contains(test.GroupedDependencies.Packages, target.Name) == false { |
| 126 | + // We are trying to find the minimum version across all defined "test" |
| 127 | + // blocks for the given `target`. So we cannot return an error here |
| 128 | + // if the `target` is not found in the grouped packages list. |
92 | 129 | continue |
93 | 130 | } |
94 | 131 |
|
95 | 132 | var currentVersion semver.Range |
96 | | - |
97 | | - // The semver library does not parse strings like `>1.0.0 <2.0.0 || >3.0.0`. |
98 | | - // So we need to split it up and normalize the pieces into range strings |
99 | | - // it can understand. |
100 | | - rangeStrings := strings.Split(val.Versions, "||") |
| 133 | + rangeStrings := strings.Split(test.GroupedDependencies.Version, "||") |
101 | 134 | for k, v := range rangeStrings { |
102 | | - // Oh, Go, why no slices.Map? |
103 | 135 | rangeStrings[k] = normalizeRangeString(v) |
104 | 136 | } |
105 | | - |
106 | 137 | currentVersion, err := processRangeStrings(rangeStrings) |
107 | 138 | if err != nil { |
108 | | - return nil, fmt.Errorf("`%s` => `%s`: %w", target, val.Versions, err) |
| 139 | + return nil, fmt.Errorf( |
| 140 | + "`%s` => `%s`: %w", |
| 141 | + target, |
| 142 | + test.GroupedDependencies.Version, |
| 143 | + err, |
| 144 | + ) |
109 | 145 | } |
110 | | - |
111 | 146 | if lastVersion == nil { |
112 | 147 | lastVersion = ¤tVersion |
113 | 148 | continue |
114 | 149 | } |
115 | | - |
116 | 150 | if isRangeLower(currentVersion, *lastVersion) == true { |
117 | 151 | lastVersion = ¤tVersion |
118 | 152 | } |
|
0 commit comments