github.com/go-maxhub/gremlins@v1.0.1-0.20231227222204-b03a6a1e3e09/core/engine/workdir/testdata/filetocopy_go (about) 1 /* 2 * Copyright 2022 The Gremlins Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package mutator_test 18 19 import ( 20 "context" 21 "go/token" 22 "io" 23 "os" 24 "testing" 25 "testing/fstest" 26 27 "github.com/go-gremlins/gremlins/configuration" 28 "github.com/go-gremlins/gremlins/internal/gomodule" 29 "github.com/go-gremlins/gremlins/pkg/coverage" 30 "github.com/go-gremlins/gremlins/pkg/mutant" 31 "github.com/go-gremlins/gremlins/pkg/mutator" 32 ) 33 34 const ( 35 defaultFixture = "testdata/fixtures/gtr_go" 36 expectedModule = "example.com" 37 ) 38 39 func coveredPosition(fixture string) coverage.Result { 40 fn := filenameFromFixture(fixture) 41 p := coverage.Profile{fn: {{StartLine: 6, EndLine: 7, StartCol: 8, EndCol: 9}}} 42 43 return coverage.Result{Profile: p, Elapsed: 10} 44 } 45 46 func notCoveredPosition(fixture string) coverage.Result { 47 fn := filenameFromFixture(fixture) 48 p := coverage.Profile{fn: {{StartLine: 9, EndLine: 9, StartCol: 8, EndCol: 9}}} 49 50 return coverage.Result{Profile: p, Elapsed: 10} 51 } 52 53 func TestMutations(t *testing.T) { 54 t.Parallel() 55 testCases := []struct { 56 name string 57 fixture string 58 covResult coverage.Result 59 mutantType mutant.Type 60 token token.Token 61 mutStatus mutant.Status 62 }{ 63 // CONDITIONAL BOUNDARIES 64 { 65 name: "it recognizes CONDITIONAL_BOUNDARY with GTR", 66 fixture: "testdata/fixtures/gtr_go", 67 mutantType: mutant.ConditionalsBoundary, 68 token: token.GTR, 69 covResult: coveredPosition("testdata/fixtures/gtr_go"), 70 mutStatus: mutant.Runnable, 71 }, 72 { 73 name: "it recognizes CONDITIONAL_BOUNDARY with LSS", 74 fixture: "testdata/fixtures/lss_go", 75 mutantType: mutant.ConditionalsBoundary, 76 token: token.LSS, 77 covResult: notCoveredPosition("testdata/fixtures/lss_go"), 78 mutStatus: mutant.NotCovered, 79 }, 80 { 81 name: "it recognizes CONDITIONAL_BOUNDARY with LEQ", 82 fixture: "testdata/fixtures/leq_go", 83 mutantType: mutant.ConditionalsBoundary, 84 token: token.LEQ, 85 covResult: notCoveredPosition("testdata/fixtures/leq_go"), 86 mutStatus: mutant.NotCovered, 87 }, 88 { 89 name: "it recognizes CONDITIONAL_BOUNDARY with GEQ", 90 fixture: "testdata/fixtures/geq_go", 91 mutantType: mutant.ConditionalsBoundary, 92 token: token.GEQ, 93 covResult: notCoveredPosition("testdata/fixtures/geq_go"), 94 mutStatus: mutant.NotCovered, 95 }, 96 // INCREMENT_DECREMENT 97 { 98 name: "it recognizes INCREMENT_DECREMENT with INC", 99 fixture: "testdata/fixtures/inc_go", 100 mutantType: mutant.IncrementDecrement, 101 token: token.INC, 102 covResult: notCoveredPosition("testdata/fixtures/inc_go"), 103 mutStatus: mutant.NotCovered, 104 }, 105 { 106 name: "it recognizes INCREMENT_DECREMENT with DEC", 107 fixture: "testdata/fixtures/dec_go", 108 mutantType: mutant.IncrementDecrement, 109 token: token.DEC, 110 covResult: notCoveredPosition("testdata/fixtures/dec_go"), 111 mutStatus: mutant.NotCovered, 112 }, 113 // CONDITIONAL_NEGATION 114 { 115 name: "it recognizes CONDITIONAL_NEGATION with EQL", 116 fixture: "testdata/fixtures/eql_go", 117 mutantType: mutant.ConditionalsNegation, 118 token: token.EQL, 119 covResult: notCoveredPosition("testdata/fixtures/eql_go"), 120 mutStatus: mutant.NotCovered, 121 }, 122 { 123 name: "it recognizes CONDITIONAL_NEGATION with NEQ", 124 fixture: "testdata/fixtures/neq_go", 125 mutantType: mutant.ConditionalsNegation, 126 token: token.NEQ, 127 covResult: notCoveredPosition("testdata/fixtures/neq_go"), 128 mutStatus: mutant.NotCovered, 129 }, 130 { 131 name: "it recognizes CONDITIONAL_NEGATION with LEQ", 132 fixture: "testdata/fixtures/leq_go", 133 mutantType: mutant.ConditionalsNegation, 134 token: token.LEQ, 135 covResult: notCoveredPosition("testdata/fixtures/leq_go"), 136 mutStatus: mutant.NotCovered, 137 }, 138 { 139 name: "it recognizes CONDITIONAL_NEGATION with GTR", 140 fixture: "testdata/fixtures/gtr_go", 141 mutantType: mutant.ConditionalsNegation, 142 token: token.GTR, 143 covResult: notCoveredPosition("testdata/fixtures/gtr_go"), 144 mutStatus: mutant.NotCovered, 145 }, 146 { 147 name: "it recognizes CONDITIONAL_NEGATION with GEQ", 148 fixture: "testdata/fixtures/geq_go", 149 mutantType: mutant.ConditionalsNegation, 150 token: token.GEQ, 151 covResult: notCoveredPosition("testdata/fixtures/geq_go"), 152 mutStatus: mutant.NotCovered, 153 }, 154 { 155 name: "it recognizes CONDITIONAL_NEGATION with LSS", 156 fixture: "testdata/fixtures/lss_go", 157 mutantType: mutant.ConditionalsNegation, 158 token: token.LSS, 159 covResult: notCoveredPosition("testdata/fixtures/lss_go"), 160 mutStatus: mutant.NotCovered, 161 }, 162 // INVERT_NEGATIVES 163 { 164 name: "it recognizes INVERT_NEGATIVE with SUB", 165 fixture: "testdata/fixtures/negative_sub_go", 166 mutantType: mutant.InvertNegatives, 167 token: token.SUB, 168 covResult: notCoveredPosition("testdata/fixtures/negative_sub_go"), 169 mutStatus: mutant.NotCovered, 170 }, 171 // ARITHMETIC_BASIC 172 { 173 name: "it recognizes ARITHMETIC_BASIC with ADD", 174 fixture: "testdata/fixtures/add_go", 175 mutantType: mutant.ArithmeticBase, 176 token: token.ADD, 177 covResult: notCoveredPosition("testdata/fixtures/add_go"), 178 mutStatus: mutant.NotCovered, 179 }, 180 { 181 name: "it recognizes ARITHMETIC_BASIC with SUB", 182 fixture: "testdata/fixtures/sub_go", 183 mutantType: mutant.ArithmeticBase, 184 token: token.SUB, 185 covResult: notCoveredPosition("testdata/fixtures/sub_go"), 186 mutStatus: mutant.NotCovered, 187 }, 188 { 189 name: "it recognizes ARITHMETIC_BASIC with MUL", 190 fixture: "testdata/fixtures/mul_go", 191 mutantType: mutant.ArithmeticBase, 192 token: token.MUL, 193 covResult: notCoveredPosition("testdata/fixtures/mul_go"), 194 mutStatus: mutant.NotCovered, 195 }, 196 { 197 name: "it recognizes ARITHMETIC_BASIC with QUO", 198 fixture: "testdata/fixtures/quo_go", 199 mutantType: mutant.ArithmeticBase, 200 token: token.QUO, 201 covResult: notCoveredPosition("testdata/fixtures/quo_go"), 202 mutStatus: mutant.NotCovered, 203 }, 204 { 205 name: "it recognizes ARITHMETIC_BASIC with REM", 206 fixture: "testdata/fixtures/rem_go", 207 mutantType: mutant.ArithmeticBase, 208 token: token.REM, 209 covResult: notCoveredPosition("testdata/fixtures/rem_go"), 210 mutStatus: mutant.NotCovered, 211 }, 212 // INVERT_LOGICAL 213 { 214 name: "it recognizes INVERT_LOGICAL with LAND", 215 fixture: "testdata/fixtures/land_go", 216 mutantType: mutant.InvertLogical, 217 token: token.LAND, 218 covResult: notCoveredPosition("testdata/fixtures/land_go"), 219 mutStatus: mutant.NotCovered, 220 }, 221 { 222 name: "it recognizes INVERT_LOGICAL with LOR", 223 fixture: "testdata/fixtures/lor_go", 224 mutantType: mutant.InvertLogical, 225 token: token.LOR, 226 covResult: notCoveredPosition("testdata/fixtures/lor_go"), 227 mutStatus: mutant.NotCovered, 228 }, 229 // Common behaviours 230 { 231 name: "it works with recursion", 232 fixture: "testdata/fixtures/geq_land_true_go", 233 mutantType: mutant.ConditionalsBoundary, 234 token: token.GEQ, 235 covResult: notCoveredPosition("testdata/fixtures/geq_go"), 236 mutStatus: mutant.NotCovered, 237 }, 238 { 239 name: "it skips illegal tokens", 240 fixture: "testdata/fixtures/illegal_go", 241 mutantType: mutant.ConditionalsBoundary, 242 token: token.ILLEGAL, 243 covResult: notCoveredPosition("testdata/fixtures/illegal_go"), 244 }, 245 } 246 for _, tc := range testCases { 247 tc := tc 248 t.Run(tc.name, func(t *testing.T) { 249 t.Parallel() 250 viperSet(map[string]any{configuration.UnleashDryRunKey: true}) 251 defer viperReset() 252 253 mapFS, mod, c := loadFixture(tc.fixture, ".") 254 defer c() 255 256 mut := mutator.New(mod, tc.covResult, newJobDealerStub(t), mutator.WithDirFs(mapFS)) 257 res := mut.Run(context.Background()) 258 got := res.Mutants 259 260 if res.Module != expectedModule { 261 t.Errorf("expected module to be %q, got %q", expectedModule, res.Module) 262 } 263 264 if tc.token == token.ILLEGAL { 265 if len(got) != 0 { 266 t.Errorf("expected no mutator found") 267 } 268 269 return 270 } 271 272 for _, g := range got { 273 if g.Type() == tc.mutantType && g.Status() == tc.mutStatus && g.Pos() > 0 { 274 // PASS 275 return 276 } 277 } 278 279 t.Errorf("expected tokenMutations list to contain the found mutation") 280 t.Log(got) 281 }) 282 } 283 } 284 285 func TestMutantSkipDisabled(t *testing.T) { 286 t.Parallel() 287 for _, mt := range mutant.Types { 288 mt := mt 289 t.Run(mt.String(), func(t *testing.T) { 290 t.Parallel() 291 mapFS, mod, c := loadFixture(defaultFixture, ".") 292 defer c() 293 294 viperSet(map[string]any{ 295 configuration.UnleashDryRunKey: true, 296 configuration.MutantTypeEnabledKey(mt): false, 297 }) 298 defer viperReset() 299 300 mut := mutator.New(mod, coveredPosition(defaultFixture), newJobDealerStub(t), mutator.WithDirFs(mapFS)) 301 res := mut.Run(context.Background()) 302 got := res.Mutants 303 304 for _, m := range got { 305 if m.Type() == mt { 306 t.Fatalf("expected %q not to be in the found tokens", mt) 307 } 308 } 309 }) 310 } 311 } 312 313 func TestSkipTestAndNonGoFiles(t *testing.T) { 314 t.Parallel() 315 f, _ := os.Open("testdata/fixtures/geq_go") 316 file, _ := io.ReadAll(f) 317 318 sys := fstest.MapFS{ 319 "file_test.go": {Data: file}, 320 "folder1/file": {Data: file}, 321 } 322 mod := gomodule.GoModule{ 323 Name: "example.com", 324 Root: ".", 325 CallingDir: ".", 326 } 327 viperSet(map[string]any{configuration.UnleashDryRunKey: true}) 328 defer viperReset() 329 mut := mutator.New(mod, coverage.Result{}, newJobDealerStub(t), mutator.WithDirFs(sys)) 330 res := mut.Run(context.Background()) 331 332 if got := res.Mutants; len(got) != 0 { 333 t.Errorf("should not receive results") 334 } 335 } 336 337 func TestStopsOnCancel(t *testing.T) { 338 mapFS, mod, c := loadFixture(defaultFixture, ".") 339 defer c() 340 341 mut := mutator.New(mod, coveredPosition(defaultFixture), newJobDealerStub(t), 342 mutator.WithDirFs(mapFS)) 343 344 ctx, cancel := context.WithCancel(context.Background()) 345 cancel() 346 res := mut.Run(ctx) 347 348 if len(res.Mutants) > 0 { 349 t.Errorf("expected to receive no mutants, got %d", len(res.Mutants)) 350 } 351 } 352 353 func TestPackageDiscovery(t *testing.T) { 354 testCases := []struct { 355 name string 356 fromPkg string 357 wantPath string 358 intMode bool 359 }{ 360 { 361 name: "from root, normal mode", 362 fromPkg: ".", 363 intMode: false, 364 wantPath: "example.com", 365 }, 366 { 367 name: "from subpackage, normal mode", 368 fromPkg: "testdata/main/fixture", 369 intMode: false, 370 wantPath: "example.com/testdata/main", 371 }, 372 } 373 for _, tc := range testCases { 374 tc := tc 375 t.Run(tc.name, func(t *testing.T) { 376 viperSet(map[string]any{ 377 configuration.UnleashIntegrationMode: tc.intMode, 378 configuration.UnleashTagsKey: "tag1 tag2", 379 }) 380 defer viperReset() 381 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 382 defer c() 383 384 jds := newJobDealerStub(t) 385 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 386 387 _ = mut.Run(context.Background()) 388 389 got := jds.gotMutants[0].Pkg() 390 391 if got != tc.wantPath { 392 t.Errorf("want %q, got %q", tc.wantPath, got) 393 394 } 395 }) 396 } 397 } 398 399 func TestPackageDiscovery(t *testing.T) { 400 testCases := []struct { 401 name string 402 fromPkg string 403 wantPath string 404 intMode bool 405 }{ 406 { 407 name: "from root, normal mode", 408 fromPkg: ".", 409 intMode: false, 410 wantPath: "example.com", 411 }, 412 { 413 name: "from subpackage, normal mode", 414 fromPkg: "testdata/main/fixture", 415 intMode: false, 416 wantPath: "example.com/testdata/main", 417 }, 418 } 419 for _, tc := range testCases { 420 tc := tc 421 t.Run(tc.name, func(t *testing.T) { 422 viperSet(map[string]any{ 423 configuration.UnleashIntegrationMode: tc.intMode, 424 configuration.UnleashTagsKey: "tag1 tag2", 425 }) 426 defer viperReset() 427 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 428 defer c() 429 430 jds := newJobDealerStub(t) 431 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 432 433 _ = mut.Run(context.Background()) 434 435 got := jds.gotMutants[0].Pkg() 436 437 if got != tc.wantPath { 438 t.Errorf("want %q, got %q", tc.wantPath, got) 439 440 } 441 }) 442 } 443 } 444 445 func TestPackageDiscovery(t *testing.T) { 446 testCases := []struct { 447 name string 448 fromPkg string 449 wantPath string 450 intMode bool 451 }{ 452 { 453 name: "from root, normal mode", 454 fromPkg: ".", 455 intMode: false, 456 wantPath: "example.com", 457 }, 458 { 459 name: "from subpackage, normal mode", 460 fromPkg: "testdata/main/fixture", 461 intMode: false, 462 wantPath: "example.com/testdata/main", 463 }, 464 } 465 for _, tc := range testCases { 466 tc := tc 467 t.Run(tc.name, func(t *testing.T) { 468 viperSet(map[string]any{ 469 configuration.UnleashIntegrationMode: tc.intMode, 470 configuration.UnleashTagsKey: "tag1 tag2", 471 }) 472 defer viperReset() 473 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 474 defer c() 475 476 jds := newJobDealerStub(t) 477 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 478 479 _ = mut.Run(context.Background()) 480 481 got := jds.gotMutants[0].Pkg() 482 483 if got != tc.wantPath { 484 t.Errorf("want %q, got %q", tc.wantPath, got) 485 486 } 487 }) 488 } 489 } 490 491 func TestPackageDiscovery(t *testing.T) { 492 testCases := []struct { 493 name string 494 fromPkg string 495 wantPath string 496 intMode bool 497 }{ 498 { 499 name: "from root, normal mode", 500 fromPkg: ".", 501 intMode: false, 502 wantPath: "example.com", 503 }, 504 { 505 name: "from subpackage, normal mode", 506 fromPkg: "testdata/main/fixture", 507 intMode: false, 508 wantPath: "example.com/testdata/main", 509 }, 510 } 511 for _, tc := range testCases { 512 tc := tc 513 t.Run(tc.name, func(t *testing.T) { 514 viperSet(map[string]any{ 515 configuration.UnleashIntegrationMode: tc.intMode, 516 configuration.UnleashTagsKey: "tag1 tag2", 517 }) 518 defer viperReset() 519 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 520 defer c() 521 522 jds := newJobDealerStub(t) 523 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 524 525 _ = mut.Run(context.Background()) 526 527 got := jds.gotMutants[0].Pkg() 528 529 if got != tc.wantPath { 530 t.Errorf("want %q, got %q", tc.wantPath, got) 531 532 } 533 }) 534 } 535 } 536 537 func TestPackageDiscovery(t *testing.T) { 538 testCases := []struct { 539 name string 540 fromPkg string 541 wantPath string 542 intMode bool 543 }{ 544 { 545 name: "from root, normal mode", 546 fromPkg: ".", 547 intMode: false, 548 wantPath: "example.com", 549 }, 550 { 551 name: "from subpackage, normal mode", 552 fromPkg: "testdata/main/fixture", 553 intMode: false, 554 wantPath: "example.com/testdata/main", 555 }, 556 } 557 for _, tc := range testCases { 558 tc := tc 559 t.Run(tc.name, func(t *testing.T) { 560 viperSet(map[string]any{ 561 configuration.UnleashIntegrationMode: tc.intMode, 562 configuration.UnleashTagsKey: "tag1 tag2", 563 }) 564 defer viperReset() 565 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 566 defer c() 567 568 jds := newJobDealerStub(t) 569 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 570 571 _ = mut.Run(context.Background()) 572 573 got := jds.gotMutants[0].Pkg() 574 575 if got != tc.wantPath { 576 t.Errorf("want %q, got %q", tc.wantPath, got) 577 578 } 579 }) 580 } 581 } 582 583 func TestPackageDiscovery(t *testing.T) { 584 testCases := []struct { 585 name string 586 fromPkg string 587 wantPath string 588 intMode bool 589 }{ 590 { 591 name: "from root, normal mode", 592 fromPkg: ".", 593 intMode: false, 594 wantPath: "example.com", 595 }, 596 { 597 name: "from subpackage, normal mode", 598 fromPkg: "testdata/main/fixture", 599 intMode: false, 600 wantPath: "example.com/testdata/main", 601 }, 602 } 603 for _, tc := range testCases { 604 tc := tc 605 t.Run(tc.name, func(t *testing.T) { 606 viperSet(map[string]any{ 607 configuration.UnleashIntegrationMode: tc.intMode, 608 configuration.UnleashTagsKey: "tag1 tag2", 609 }) 610 defer viperReset() 611 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 612 defer c() 613 614 jds := newJobDealerStub(t) 615 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 616 617 _ = mut.Run(context.Background()) 618 619 got := jds.gotMutants[0].Pkg() 620 621 if got != tc.wantPath { 622 t.Errorf("want %q, got %q", tc.wantPath, got) 623 624 } 625 }) 626 } 627 } 628 func TestPackageDiscovery(t *testing.T) { 629 testCases := []struct { 630 name string 631 fromPkg string 632 wantPath string 633 intMode bool 634 }{ 635 { 636 name: "from root, normal mode", 637 fromPkg: ".", 638 intMode: false, 639 wantPath: "example.com", 640 }, 641 { 642 name: "from subpackage, normal mode", 643 fromPkg: "testdata/main/fixture", 644 intMode: false, 645 wantPath: "example.com/testdata/main", 646 }, 647 } 648 for _, tc := range testCases { 649 tc := tc 650 t.Run(tc.name, func(t *testing.T) { 651 viperSet(map[string]any{ 652 configuration.UnleashIntegrationMode: tc.intMode, 653 configuration.UnleashTagsKey: "tag1 tag2", 654 }) 655 defer viperReset() 656 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 657 defer c() 658 659 jds := newJobDealerStub(t) 660 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 661 662 _ = mut.Run(context.Background()) 663 664 got := jds.gotMutants[0].Pkg() 665 666 if got != tc.wantPath { 667 t.Errorf("want %q, got %q", tc.wantPath, got) 668 669 } 670 }) 671 } 672 } 673 func TestPackageDiscovery(t *testing.T) { 674 testCases := []struct { 675 name string 676 fromPkg string 677 wantPath string 678 intMode bool 679 }{ 680 { 681 name: "from root, normal mode", 682 fromPkg: ".", 683 intMode: false, 684 wantPath: "example.com", 685 }, 686 { 687 name: "from subpackage, normal mode", 688 fromPkg: "testdata/main/fixture", 689 intMode: false, 690 wantPath: "example.com/testdata/main", 691 }, 692 } 693 for _, tc := range testCases { 694 tc := tc 695 t.Run(tc.name, func(t *testing.T) { 696 viperSet(map[string]any{ 697 configuration.UnleashIntegrationMode: tc.intMode, 698 configuration.UnleashTagsKey: "tag1 tag2", 699 }) 700 defer viperReset() 701 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 702 defer c() 703 704 jds := newJobDealerStub(t) 705 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 706 707 _ = mut.Run(context.Background()) 708 709 got := jds.gotMutants[0].Pkg() 710 711 if got != tc.wantPath { 712 t.Errorf("want %q, got %q", tc.wantPath, got) 713 714 } 715 }) 716 } 717 } 718 func TestPackageDiscovery(t *testing.T) { 719 testCases := []struct { 720 name string 721 fromPkg string 722 wantPath string 723 intMode bool 724 }{ 725 { 726 name: "from root, normal mode", 727 fromPkg: ".", 728 intMode: false, 729 wantPath: "example.com", 730 }, 731 { 732 name: "from subpackage, normal mode", 733 fromPkg: "testdata/main/fixture", 734 intMode: false, 735 wantPath: "example.com/testdata/main", 736 }, 737 } 738 for _, tc := range testCases { 739 tc := tc 740 t.Run(tc.name, func(t *testing.T) { 741 viperSet(map[string]any{ 742 configuration.UnleashIntegrationMode: tc.intMode, 743 configuration.UnleashTagsKey: "tag1 tag2", 744 }) 745 defer viperReset() 746 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 747 defer c() 748 749 jds := newJobDealerStub(t) 750 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 751 752 _ = mut.Run(context.Background()) 753 754 got := jds.gotMutants[0].Pkg() 755 756 if got != tc.wantPath { 757 t.Errorf("want %q, got %q", tc.wantPath, got) 758 759 } 760 }) 761 } 762 } 763 func TestPackageDiscovery(t *testing.T) { 764 testCases := []struct { 765 name string 766 fromPkg string 767 wantPath string 768 intMode bool 769 }{ 770 { 771 name: "from root, normal mode", 772 fromPkg: ".", 773 intMode: false, 774 wantPath: "example.com", 775 }, 776 { 777 name: "from subpackage, normal mode", 778 fromPkg: "testdata/main/fixture", 779 intMode: false, 780 wantPath: "example.com/testdata/main", 781 }, 782 } 783 for _, tc := range testCases { 784 tc := tc 785 t.Run(tc.name, func(t *testing.T) { 786 viperSet(map[string]any{ 787 configuration.UnleashIntegrationMode: tc.intMode, 788 configuration.UnleashTagsKey: "tag1 tag2", 789 }) 790 defer viperReset() 791 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 792 defer c() 793 794 jds := newJobDealerStub(t) 795 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 796 797 _ = mut.Run(context.Background()) 798 799 got := jds.gotMutants[0].Pkg() 800 801 if got != tc.wantPath { 802 t.Errorf("want %q, got %q", tc.wantPath, got) 803 804 } 805 }) 806 } 807 } 808 func TestPackageDiscovery(t *testing.T) { 809 testCases := []struct { 810 name string 811 fromPkg string 812 wantPath string 813 intMode bool 814 }{ 815 { 816 name: "from root, normal mode", 817 fromPkg: ".", 818 intMode: false, 819 wantPath: "example.com", 820 }, 821 { 822 name: "from subpackage, normal mode", 823 fromPkg: "testdata/main/fixture", 824 intMode: false, 825 wantPath: "example.com/testdata/main", 826 }, 827 } 828 for _, tc := range testCases { 829 tc := tc 830 t.Run(tc.name, func(t *testing.T) { 831 viperSet(map[string]any{ 832 configuration.UnleashIntegrationMode: tc.intMode, 833 configuration.UnleashTagsKey: "tag1 tag2", 834 }) 835 defer viperReset() 836 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 837 defer c() 838 839 jds := newJobDealerStub(t) 840 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 841 842 _ = mut.Run(context.Background()) 843 844 got := jds.gotMutants[0].Pkg() 845 846 if got != tc.wantPath { 847 t.Errorf("want %q, got %q", tc.wantPath, got) 848 849 } 850 }) 851 } 852 } 853 func TestPackageDiscovery(t *testing.T) { 854 testCases := []struct { 855 name string 856 fromPkg string 857 wantPath string 858 intMode bool 859 }{ 860 { 861 name: "from root, normal mode", 862 fromPkg: ".", 863 intMode: false, 864 wantPath: "example.com", 865 }, 866 { 867 name: "from subpackage, normal mode", 868 fromPkg: "testdata/main/fixture", 869 intMode: false, 870 wantPath: "example.com/testdata/main", 871 }, 872 } 873 for _, tc := range testCases { 874 tc := tc 875 t.Run(tc.name, func(t *testing.T) { 876 viperSet(map[string]any{ 877 configuration.UnleashIntegrationMode: tc.intMode, 878 configuration.UnleashTagsKey: "tag1 tag2", 879 }) 880 defer viperReset() 881 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 882 defer c() 883 884 jds := newJobDealerStub(t) 885 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 886 887 _ = mut.Run(context.Background()) 888 889 got := jds.gotMutants[0].Pkg() 890 891 if got != tc.wantPath { 892 t.Errorf("want %q, got %q", tc.wantPath, got) 893 894 } 895 }) 896 } 897 } 898 func TestPackageDiscovery(t *testing.T) { 899 testCases := []struct { 900 name string 901 fromPkg string 902 wantPath string 903 intMode bool 904 }{ 905 { 906 name: "from root, normal mode", 907 fromPkg: ".", 908 intMode: false, 909 wantPath: "example.com", 910 }, 911 { 912 name: "from subpackage, normal mode", 913 fromPkg: "testdata/main/fixture", 914 intMode: false, 915 wantPath: "example.com/testdata/main", 916 }, 917 } 918 for _, tc := range testCases { 919 tc := tc 920 t.Run(tc.name, func(t *testing.T) { 921 viperSet(map[string]any{ 922 configuration.UnleashIntegrationMode: tc.intMode, 923 configuration.UnleashTagsKey: "tag1 tag2", 924 }) 925 defer viperReset() 926 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 927 defer c() 928 929 jds := newJobDealerStub(t) 930 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 931 932 _ = mut.Run(context.Background()) 933 934 got := jds.gotMutants[0].Pkg() 935 936 if got != tc.wantPath { 937 t.Errorf("want %q, got %q", tc.wantPath, got) 938 939 } 940 }) 941 } 942 } 943 func TestPackageDiscovery(t *testing.T) { 944 testCases := []struct { 945 name string 946 fromPkg string 947 wantPath string 948 intMode bool 949 }{ 950 { 951 name: "from root, normal mode", 952 fromPkg: ".", 953 intMode: false, 954 wantPath: "example.com", 955 }, 956 { 957 name: "from subpackage, normal mode", 958 fromPkg: "testdata/main/fixture", 959 intMode: false, 960 wantPath: "example.com/testdata/main", 961 }, 962 } 963 for _, tc := range testCases { 964 tc := tc 965 t.Run(tc.name, func(t *testing.T) { 966 viperSet(map[string]any{ 967 configuration.UnleashIntegrationMode: tc.intMode, 968 configuration.UnleashTagsKey: "tag1 tag2", 969 }) 970 defer viperReset() 971 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 972 defer c() 973 974 jds := newJobDealerStub(t) 975 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 976 977 _ = mut.Run(context.Background()) 978 979 got := jds.gotMutants[0].Pkg() 980 981 if got != tc.wantPath { 982 t.Errorf("want %q, got %q", tc.wantPath, got) 983 984 } 985 }) 986 } 987 } 988 func TestPackageDiscovery(t *testing.T) { 989 testCases := []struct { 990 name string 991 fromPkg string 992 wantPath string 993 intMode bool 994 }{ 995 { 996 name: "from root, normal mode", 997 fromPkg: ".", 998 intMode: false, 999 wantPath: "example.com", 1000 }, 1001 { 1002 name: "from subpackage, normal mode", 1003 fromPkg: "testdata/main/fixture", 1004 intMode: false, 1005 wantPath: "example.com/testdata/main", 1006 }, 1007 } 1008 for _, tc := range testCases { 1009 tc := tc 1010 t.Run(tc.name, func(t *testing.T) { 1011 viperSet(map[string]any{ 1012 configuration.UnleashIntegrationMode: tc.intMode, 1013 configuration.UnleashTagsKey: "tag1 tag2", 1014 }) 1015 defer viperReset() 1016 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 1017 defer c() 1018 1019 jds := newJobDealerStub(t) 1020 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 1021 1022 _ = mut.Run(context.Background()) 1023 1024 got := jds.gotMutants[0].Pkg() 1025 1026 if got != tc.wantPath { 1027 t.Errorf("want %q, got %q", tc.wantPath, got) 1028 1029 } 1030 }) 1031 } 1032 } 1033 func TestPackageDiscovery(t *testing.T) { 1034 testCases := []struct { 1035 name string 1036 fromPkg string 1037 wantPath string 1038 intMode bool 1039 }{ 1040 { 1041 name: "from root, normal mode", 1042 fromPkg: ".", 1043 intMode: false, 1044 wantPath: "example.com", 1045 }, 1046 { 1047 name: "from subpackage, normal mode", 1048 fromPkg: "testdata/main/fixture", 1049 intMode: false, 1050 wantPath: "example.com/testdata/main", 1051 }, 1052 } 1053 for _, tc := range testCases { 1054 tc := tc 1055 t.Run(tc.name, func(t *testing.T) { 1056 viperSet(map[string]any{ 1057 configuration.UnleashIntegrationMode: tc.intMode, 1058 configuration.UnleashTagsKey: "tag1 tag2", 1059 }) 1060 defer viperReset() 1061 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 1062 defer c() 1063 1064 jds := newJobDealerStub(t) 1065 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 1066 1067 _ = mut.Run(context.Background()) 1068 1069 got := jds.gotMutants[0].Pkg() 1070 1071 if got != tc.wantPath { 1072 t.Errorf("want %q, got %q", tc.wantPath, got) 1073 1074 } 1075 }) 1076 } 1077 } 1078 func TestPackageDiscovery(t *testing.T) { 1079 testCases := []struct { 1080 name string 1081 fromPkg string 1082 wantPath string 1083 intMode bool 1084 }{ 1085 { 1086 name: "from root, normal mode", 1087 fromPkg: ".", 1088 intMode: false, 1089 wantPath: "example.com", 1090 }, 1091 { 1092 name: "from subpackage, normal mode", 1093 fromPkg: "testdata/main/fixture", 1094 intMode: false, 1095 wantPath: "example.com/testdata/main", 1096 }, 1097 } 1098 for _, tc := range testCases { 1099 tc := tc 1100 t.Run(tc.name, func(t *testing.T) { 1101 viperSet(map[string]any{ 1102 configuration.UnleashIntegrationMode: tc.intMode, 1103 configuration.UnleashTagsKey: "tag1 tag2", 1104 }) 1105 defer viperReset() 1106 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 1107 defer c() 1108 1109 jds := newJobDealerStub(t) 1110 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 1111 1112 _ = mut.Run(context.Background()) 1113 1114 got := jds.gotMutants[0].Pkg() 1115 1116 if got != tc.wantPath { 1117 t.Errorf("want %q, got %q", tc.wantPath, got) 1118 1119 } 1120 }) 1121 } 1122 } 1123 func TestPackageDiscovery(t *testing.T) { 1124 testCases := []struct { 1125 name string 1126 fromPkg string 1127 wantPath string 1128 intMode bool 1129 }{ 1130 { 1131 name: "from root, normal mode", 1132 fromPkg: ".", 1133 intMode: false, 1134 wantPath: "example.com", 1135 }, 1136 { 1137 name: "from subpackage, normal mode", 1138 fromPkg: "testdata/main/fixture", 1139 intMode: false, 1140 wantPath: "example.com/testdata/main", 1141 }, 1142 } 1143 for _, tc := range testCases { 1144 tc := tc 1145 t.Run(tc.name, func(t *testing.T) { 1146 viperSet(map[string]any{ 1147 configuration.UnleashIntegrationMode: tc.intMode, 1148 configuration.UnleashTagsKey: "tag1 tag2", 1149 }) 1150 defer viperReset() 1151 mapFS, mod, c := loadFixture(defaultFixture, tc.fromPkg) 1152 defer c() 1153 1154 jds := newJobDealerStub(t) 1155 mut := mutator.New(mod, coveredPosition(defaultFixture), jds, mutator.WithDirFs(mapFS)) 1156 1157 _ = mut.Run(context.Background()) 1158 1159 got := jds.gotMutants[0].Pkg() 1160 1161 if got != tc.wantPath { 1162 t.Errorf("want %q, got %q", tc.wantPath, got) 1163 1164 } 1165 }) 1166 } 1167 }