|
1 | 1 | module Main where |
2 | 2 |
|
3 | | -import Control.Monad ( unless ) |
| 3 | +import Control.Monad ( unless ) |
4 | 4 | import qualified Data.List as L |
5 | | -import Test.Tasty |
6 | | -import Test.Tasty.HUnit |
7 | | -import Text.Show.Pretty |
| 5 | +import Test.Tasty |
| 6 | +import Test.Tasty.HUnit |
| 7 | +import Text.Show.Pretty |
8 | 8 |
|
9 | | -import Test.Tasty.Sugar.Types |
10 | | -import Test.Tasty.Sugar.ExpectCheck |
| 9 | +import Test.Tasty.Sugar.Candidates |
| 10 | +import Test.Tasty.Sugar.ExpectCheck |
| 11 | +import Test.Tasty.Sugar.ParamCheck |
| 12 | +import Test.Tasty.Sugar.Types |
11 | 13 |
|
12 | 14 |
|
13 | 15 | main = defaultMain $ |
@@ -180,6 +182,129 @@ main = defaultMain $ |
180 | 182 | in mapM test (L.permutations $ adding <> sample) |
181 | 183 | >> return () |
182 | 184 |
|
| 185 | + , testCase "multi-val-param matching" $ |
| 186 | + let cand = CandidateFile { candidateDir = "testdir" |
| 187 | + , candidateSubdirs = [] |
| 188 | + , candidateFile = "file.clang12+.clang14+.z3.exp" |
| 189 | + , candidatePMatch = |
| 190 | + [ ("clangtgt", Explicit "clang12+") |
| 191 | + , ("clangtgt", Explicit "clang14+") |
| 192 | + , ("solver", Explicit "z3") |
| 193 | + ] |
| 194 | + , candidateMatchIdx = 99 |
| 195 | + } |
| 196 | + pvals1 = [ ("clangtgt", Just "clang12+"), ("solver", Just "z3") ] |
| 197 | + pvals2 = [ ("clangtgt", Just "clang14+"), ("solver", Just "z3") ] |
| 198 | + pvals3 = [ ("clangtgt", Just "clang12"), ("solver", Just "z3") ] |
| 199 | + in do isCompatible pvals1 cand @? "first multival" |
| 200 | + isCompatible pvals2 cand @? "second multival" |
| 201 | + not (isCompatible pvals3 cand) @? "no multival" |
| 202 | + |
| 203 | + , testCase "collation of expectations" $ |
| 204 | + let exp1 = Expectation |
| 205 | + { expectedFile = "test/data/llvm1/T972-fail.z3.good" |
| 206 | + , expParamsMatch = [("clang-range",Assumed "clang11+") |
| 207 | + ,("solver",Explicit "z3")] |
| 208 | + , associated = [] |
| 209 | + } |
| 210 | + exp2 = Expectation |
| 211 | + { expectedFile = "test/data/llvm1/T972-fail.clang12+.clang14+.z3.good" |
| 212 | + , expParamsMatch = [("clang-range",Explicit "clang12+") |
| 213 | + ,("solver",Explicit "z3")] |
| 214 | + , associated = [] |
| 215 | + } |
| 216 | + exp3 = Expectation |
| 217 | + { expectedFile = "test/data/llvm1/T972-fail.z3.good" |
| 218 | + , expParamsMatch = [("clang-range",Assumed "clang12+") |
| 219 | + ,("solver",Explicit "z3")] |
| 220 | + , associated = [] |
| 221 | + } |
| 222 | + exp4 = Expectation |
| 223 | + { expectedFile = "test/data/llvm1/T972-fail.z3.good" |
| 224 | + , expParamsMatch = [("clang-range",Assumed "clang13+") |
| 225 | + ,("solver",Explicit "z3")] |
| 226 | + , associated = [] |
| 227 | + } |
| 228 | + exp5 = Expectation |
| 229 | + { expectedFile = "test/data/llvm1/T972-fail.clang12+.clang14+.z3.good" |
| 230 | + , expParamsMatch = [("clang-range",Explicit "clang14+") |
| 231 | + ,("solver",Explicit "z3")] |
| 232 | + , associated = [] |
| 233 | + } |
| 234 | + exp6 = Expectation |
| 235 | + { expectedFile = "test/data/llvm1/T972-fail.z3.good" |
| 236 | + , expParamsMatch = [("clang-range",Assumed "clang14+") |
| 237 | + ,("solver",Explicit "z3")] |
| 238 | + , associated = [] |
| 239 | + } |
| 240 | + exp7 = Expectation |
| 241 | + { expectedFile = "test/data/llvm1/T972-fail.z3.good" |
| 242 | + , expParamsMatch = [("clang-range",Assumed "older-clang") |
| 243 | + ,("solver",Explicit "z3")] |
| 244 | + , associated = [] |
| 245 | + } |
| 246 | + allExps = [exp1, exp2, exp3, exp4, exp5, exp6, exp7] |
| 247 | + in collateExpectations allExps @?= [exp7, exp5, exp4, exp2, exp1] |
| 248 | + -- ^ order of collateExpectations results doesn't really matter, so |
| 249 | + -- feel free to re-order this as needed. |
| 250 | + |
| 251 | + , testCase "matchStrength" $ |
| 252 | + let cand1 = CandidateFile { candidateDir = "testdir" |
| 253 | + , candidateSubdirs = [] |
| 254 | + , candidateFile = "file.clang12+.clang14+.z3.exp" |
| 255 | + , candidatePMatch = |
| 256 | + [ ("clangtgt", Explicit "clang12+") |
| 257 | + , ("clangtgt", Explicit "clang14+") |
| 258 | + , ("solver", Explicit "z3") |
| 259 | + ] |
| 260 | + , candidateMatchIdx = 99 |
| 261 | + } |
| 262 | + cand2 = CandidateFile { candidateDir = "testdir" |
| 263 | + , candidateSubdirs = [] |
| 264 | + , candidateFile = "file.z3.exp" |
| 265 | + , candidatePMatch = |
| 266 | + [ ("solver", Explicit "z3") |
| 267 | + ] |
| 268 | + , candidateMatchIdx = 99 |
| 269 | + } |
| 270 | + strength1 = matchStrength (snd <$> (candidatePMatch cand1)) |
| 271 | + strength2 = matchStrength (snd <$> (candidatePMatch cand2)) |
| 272 | + in strength1 > strength2 @? |
| 273 | + ("candidate 1 strength of " <> show strength1 |
| 274 | + <> " is not greater than candidate 2 strength of " |
| 275 | + <> show strength2) |
| 276 | + |
| 277 | + , testCase "candidateMatchPrefix" $ |
| 278 | + let seps = "." |
| 279 | + rootPrefix = CandidateFile { candidateDir = "testdir" |
| 280 | + , candidateSubdirs = [] |
| 281 | + , candidateFile = "file" |
| 282 | + , candidatePMatch = [] |
| 283 | + , candidateMatchIdx = 5 |
| 284 | + } |
| 285 | + expSuffix = "exp" |
| 286 | + cand1 = CandidateFile { candidateDir = "testdir" |
| 287 | + , candidateSubdirs = [] |
| 288 | + , candidateFile = "file.clang12+.clang14+.z3.exp" |
| 289 | + , candidatePMatch = |
| 290 | + [ ("clangtgt", Explicit "clang12+") |
| 291 | + , ("clangtgt", Explicit "clang14+") |
| 292 | + , ("solver", Explicit "z3") |
| 293 | + ] |
| 294 | + , candidateMatchIdx = 5 |
| 295 | + } |
| 296 | + cand2 = CandidateFile { candidateDir = "testdir" |
| 297 | + , candidateSubdirs = [] |
| 298 | + , candidateFile = "file.z3.exp" |
| 299 | + , candidatePMatch = |
| 300 | + [ ("solver", Explicit "z3") |
| 301 | + ] |
| 302 | + , candidateMatchIdx = 5 |
| 303 | + } |
| 304 | + in do candidateMatchPrefix seps rootPrefix cand1 @? "cand1 pfx match" |
| 305 | + candidateMatchPrefix seps rootPrefix cand2 @? "cand2 pfx match" |
| 306 | + candidateMatchSuffix seps "exp" rootPrefix cand1 @? "cand1 sfx match" |
| 307 | + candidateMatchSuffix seps "exp" rootPrefix cand2 @? "cand2 sfx match" |
183 | 308 | ] |
184 | 309 |
|
185 | 310 |
|
|
0 commit comments