|
| 1 | +using System.Collections.Generic; |
1 | 2 | using System.IO;
|
2 |
| -using GitTools.Testing; |
| 3 | +using GitVersion.Core.Tests.Helpers; |
| 4 | +using GitVersion.Extensions; |
3 | 5 | using GitVersion.Logging;
|
4 | 6 | using GitVersion.Model;
|
5 |
| -using GitVersion.Core.Tests.Helpers; |
| 7 | +using GitVersion.Model.Configuration; |
| 8 | +using GitTools.Testing; |
6 | 9 | using Microsoft.Extensions.DependencyInjection;
|
7 | 10 | using NUnit.Framework;
|
8 | 11 | using Shouldly;
|
@@ -364,26 +367,232 @@ public void OverrideconfigWithNoOptions()
|
364 | 367 | arguments.OverrideConfig.ShouldBeNull();
|
365 | 368 | }
|
366 | 369 |
|
367 |
| - [Test] |
368 |
| - public void OverrideconfigWithSingleTagprefixOption() |
369 |
| - { |
370 |
| - var arguments = argumentParser.ParseArguments("/overrideconfig tag-prefix=sample"); |
371 |
| - arguments.OverrideConfig.TagPrefix.ShouldBe("sample"); |
372 |
| - } |
373 |
| - |
374 |
| - [TestCase("tag-prefix=sample;tag-prefix=other")] |
375 |
| - [TestCase("tag-prefix=sample;param2=other")] |
376 |
| - public void OverrideconfigWithSeveralOptions(string options) |
| 370 | + [TestCaseSource(nameof(OverrideconfigWithInvalidOptionTestData))] |
| 371 | + public string OverrideconfigWithInvalidOption(string options) |
377 | 372 | {
|
378 | 373 | var exception = Assert.Throws<WarningException>(() => argumentParser.ParseArguments($"/overrideconfig {options}"));
|
379 |
| - exception.Message.ShouldContain("Can't specify multiple /overrideconfig options"); |
| 374 | + return exception.Message; |
380 | 375 | }
|
381 | 376 |
|
382 |
| - [TestCase("tag-prefix=sample=asdf")] |
383 |
| - public void OverrideconfigWithInvalidOption(string options) |
| 377 | + private static IEnumerable<TestCaseData> OverrideconfigWithInvalidOptionTestData() |
384 | 378 | {
|
385 |
| - var exception = Assert.Throws<WarningException>(() => argumentParser.ParseArguments($"/overrideconfig {options}")); |
386 |
| - exception.Message.ShouldContain("Could not parse /overrideconfig option"); |
| 379 | + yield return new TestCaseData("tag-prefix=sample=asdf") |
| 380 | + { |
| 381 | + ExpectedResult = "Could not parse /overrideconfig option: tag-prefix=sample=asdf. Ensure it is in format 'key=value'." |
| 382 | + }; |
| 383 | + yield return new TestCaseData("unknown-option=25") |
| 384 | + { |
| 385 | + ExpectedResult = "Could not parse /overrideconfig option: unknown-option=25. Unsuported 'key'." |
| 386 | + }; |
| 387 | + yield return new TestCaseData("update-build-number=1") |
| 388 | + { |
| 389 | + ExpectedResult = "Could not parse /overrideconfig option: update-build-number=1. Ensure that 'value' is 'true' or 'false'." |
| 390 | + }; |
| 391 | + yield return new TestCaseData("tag-pre-release-weight=invalid-value") |
| 392 | + { |
| 393 | + ExpectedResult = "Could not parse /overrideconfig option: tag-pre-release-weight=invalid-value. Ensure that 'value' is valid integer number." |
| 394 | + }; |
| 395 | + yield return new TestCaseData("assembly-versioning-scheme=WrongEnumValue") |
| 396 | + { |
| 397 | + ExpectedResult = "Could not parse /overrideconfig option: assembly-versioning-scheme=WrongEnumValue. Ensure that 'value' is valid for specified 'key' enumeration: \r\nMajorMinorPatchTag\r\nMajorMinorPatch\r\nMajorMinor\r\nMajor\r\nNone\r\n" |
| 398 | + }; |
| 399 | + } |
| 400 | + |
| 401 | + [TestCaseSource(nameof(OverrideconfigWithSingleOptionTestData))] |
| 402 | + public void OverrideconfigWithSingleOptions(string options, Config expected) |
| 403 | + { |
| 404 | + var arguments = argumentParser.ParseArguments($"/overrideconfig {options}"); |
| 405 | + arguments.OverrideConfig.ShouldBeEquivalentTo(expected); |
| 406 | + } |
| 407 | + |
| 408 | + private static IEnumerable<TestCaseData> OverrideconfigWithSingleOptionTestData() |
| 409 | + { |
| 410 | + yield return new TestCaseData( |
| 411 | + "assembly-versioning-scheme=MajorMinor", |
| 412 | + new Config |
| 413 | + { |
| 414 | + AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor, |
| 415 | + } |
| 416 | + ); |
| 417 | + yield return new TestCaseData( |
| 418 | + "assembly-file-versioning-scheme=\"MajorMinorPatch\"", |
| 419 | + new Config |
| 420 | + { |
| 421 | + AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch, |
| 422 | + } |
| 423 | + ); |
| 424 | + yield return new TestCaseData( |
| 425 | + "assembly-informational-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"", |
| 426 | + new Config |
| 427 | + { |
| 428 | + AssemblyInformationalFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}", |
| 429 | + } |
| 430 | + ); |
| 431 | + yield return new TestCaseData( |
| 432 | + "assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"", |
| 433 | + new Config |
| 434 | + { |
| 435 | + AssemblyVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}", |
| 436 | + } |
| 437 | + ); |
| 438 | + yield return new TestCaseData( |
| 439 | + "assembly-file-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"", |
| 440 | + new Config |
| 441 | + { |
| 442 | + AssemblyFileVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}", |
| 443 | + } |
| 444 | + ); |
| 445 | + yield return new TestCaseData( |
| 446 | + "mode=ContinuousDelivery", |
| 447 | + new Config |
| 448 | + { |
| 449 | + VersioningMode = GitVersion.VersionCalculation.VersioningMode.ContinuousDelivery |
| 450 | + } |
| 451 | + ); |
| 452 | + yield return new TestCaseData( |
| 453 | + "tag-prefix=sample", |
| 454 | + new Config |
| 455 | + { |
| 456 | + TagPrefix = "sample" |
| 457 | + } |
| 458 | + ); |
| 459 | + yield return new TestCaseData( |
| 460 | + "continuous-delivery-fallback-tag=cd-tag", |
| 461 | + new Config |
| 462 | + { |
| 463 | + ContinuousDeploymentFallbackTag = "cd-tag" |
| 464 | + } |
| 465 | + ); |
| 466 | + yield return new TestCaseData( |
| 467 | + "next-version=1", |
| 468 | + new Config |
| 469 | + { |
| 470 | + NextVersion = "1" |
| 471 | + } |
| 472 | + ); |
| 473 | + yield return new TestCaseData( |
| 474 | + "major-version-bump-message=\"This is major version bump message.\"", |
| 475 | + new Config |
| 476 | + { |
| 477 | + MajorVersionBumpMessage = "This is major version bump message." |
| 478 | + } |
| 479 | + ); |
| 480 | + yield return new TestCaseData( |
| 481 | + "minor-version-bump-message=\"This is minor version bump message.\"", |
| 482 | + new Config |
| 483 | + { |
| 484 | + MinorVersionBumpMessage = "This is minor version bump message." |
| 485 | + } |
| 486 | + ); |
| 487 | + yield return new TestCaseData( |
| 488 | + "patch-version-bump-message=\"This is patch version bump message.\"", |
| 489 | + new Config |
| 490 | + { |
| 491 | + PatchVersionBumpMessage = "This is patch version bump message." |
| 492 | + } |
| 493 | + ); |
| 494 | + yield return new TestCaseData( |
| 495 | + "no-bump-message=\"This is no bump message.\"", |
| 496 | + new Config |
| 497 | + { |
| 498 | + NoBumpMessage = "This is no bump message." |
| 499 | + } |
| 500 | + ); |
| 501 | + yield return new TestCaseData( |
| 502 | + "legacy-semver-padding=99", |
| 503 | + new Config |
| 504 | + { |
| 505 | + LegacySemVerPadding = 99 |
| 506 | + } |
| 507 | + ); |
| 508 | + yield return new TestCaseData( |
| 509 | + "build-metadata-padding=30", |
| 510 | + new Config |
| 511 | + { |
| 512 | + BuildMetaDataPadding = 30 |
| 513 | + } |
| 514 | + ); |
| 515 | + yield return new TestCaseData( |
| 516 | + "commits-since-version-source-padding=5", |
| 517 | + new Config |
| 518 | + { |
| 519 | + CommitsSinceVersionSourcePadding = 5 |
| 520 | + } |
| 521 | + ); |
| 522 | + yield return new TestCaseData( |
| 523 | + "tag-pre-release-weight=2", |
| 524 | + new Config |
| 525 | + { |
| 526 | + TagPreReleaseWeight = 2 |
| 527 | + } |
| 528 | + ); |
| 529 | + yield return new TestCaseData( |
| 530 | + "commit-message-incrementing=MergeMessageOnly", |
| 531 | + new Config |
| 532 | + { |
| 533 | + CommitMessageIncrementing = CommitMessageIncrementMode.MergeMessageOnly |
| 534 | + } |
| 535 | + ); |
| 536 | + yield return new TestCaseData( |
| 537 | + "increment=Minor", |
| 538 | + new Config |
| 539 | + { |
| 540 | + Increment = IncrementStrategy.Minor |
| 541 | + } |
| 542 | + ); |
| 543 | + yield return new TestCaseData( |
| 544 | + "commit-date-format=\"MM/dd/yyyy h:mm tt\"", |
| 545 | + new Config |
| 546 | + { |
| 547 | + CommitDateFormat = "MM/dd/yyyy h:mm tt" |
| 548 | + } |
| 549 | + ); |
| 550 | + yield return new TestCaseData( |
| 551 | + "update-build-number=true", |
| 552 | + new Config |
| 553 | + { |
| 554 | + UpdateBuildNumber = true |
| 555 | + } |
| 556 | + ); |
| 557 | + } |
| 558 | + |
| 559 | + [TestCaseSource(nameof(OverrideconfigWithMultipleOptionsTestData))] |
| 560 | + public void OverrideconfigWithMultipleOptions(string options, Config expected) |
| 561 | + { |
| 562 | + var arguments = argumentParser.ParseArguments($"/overrideconfig {options}"); |
| 563 | + arguments.OverrideConfig.ShouldBeEquivalentTo(expected); |
| 564 | + } |
| 565 | + |
| 566 | + private static IEnumerable<TestCaseData> OverrideconfigWithMultipleOptionsTestData() |
| 567 | + { |
| 568 | + yield return new TestCaseData( |
| 569 | + "tag-prefix=sample;assembly-versioning-scheme=MajorMinor", |
| 570 | + new Config |
| 571 | + { |
| 572 | + TagPrefix = "sample", |
| 573 | + AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinor, |
| 574 | + } |
| 575 | + ); |
| 576 | + yield return new TestCaseData( |
| 577 | + "tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\"", |
| 578 | + new Config |
| 579 | + { |
| 580 | + TagPrefix = "sample", |
| 581 | + AssemblyVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}" |
| 582 | + } |
| 583 | + ); |
| 584 | + yield return new TestCaseData( |
| 585 | + "tag-prefix=sample;assembly-versioning-format=\"{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}\";update-build-number=true;assembly-versioning-scheme=MajorMinorPatchTag;mode=ContinuousDelivery;tag-pre-release-weight=4", |
| 586 | + new Config |
| 587 | + { |
| 588 | + TagPrefix = "sample", |
| 589 | + AssemblyVersioningFormat = "{Major}.{Minor}.{Patch}.{env:CI_JOB_ID ?? 0}", |
| 590 | + UpdateBuildNumber = true, |
| 591 | + AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag, |
| 592 | + VersioningMode = GitVersion.VersionCalculation.VersioningMode.ContinuousDelivery, |
| 593 | + TagPreReleaseWeight = 4 |
| 594 | + } |
| 595 | + ); |
387 | 596 | }
|
388 | 597 |
|
389 | 598 | [Test]
|
|
0 commit comments