public void ShouldWarnAboutMissingGitConfiguration() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingFilePath = Path.Join(_testSetup.WorkingDirectory, "hello.txt"); // Create and commit a test file File.WriteAllText(workingFilePath, "First line of text"); CommitAll(_testSetup.Repository); var configurationValues = new[] { "user.name", "user.email" } .SelectMany(key => Enum.GetValues(typeof(ConfigurationLevel)) .Cast <ConfigurationLevel>() .Select(level => _testSetup.Repository.Config.Get <string>(key, level))) .Where(c => c != null) .ToList(); try { configurationValues.ForEach(c => _testSetup.Repository.Config.Unset(c.Key, c.Level)); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); Should.Throw <CommandLineExitException>(() => workingCopy.Versionize(new VersionizeOptions())); _testPlatformAbstractions.Messages.Last().ShouldStartWith("Warning: Git configuration is missing"); } finally { configurationValues.ForEach(c => _testSetup.Repository.Config.Set(c.Key, c.Value, c.Level)); } }
public void ShouldPrereleaseToCurrentMaximumPrereleaseVersion() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); var fileCommitter = new FileCommitter(_testSetup); // Release an initial version fileCommitter.CommitChange("chore: initial commit"); workingCopy.Versionize(new VersionizeOptions()); // Prerelease as minor alpha fileCommitter.CommitChange("feat: feature pre-release"); workingCopy.Versionize(new VersionizeOptions { Prerelease = "alpha" }); // Prerelease as major alpha fileCommitter.CommitChange("chore: initial commit\n\nBREAKING CHANGE: This is a breaking change"); workingCopy.Versionize(new VersionizeOptions { Prerelease = "alpha" }); var versionTagNames = VersionTagNames.ToList(); versionTagNames.ShouldBe(new[] { "v1.0.0", "v1.1.0-alpha.0", "v2.0.0-alpha.0" }); }
public ProgramTests() { _testSetup = TestSetup.Create(); TempProject.CreateCsharpProject(_testSetup.WorkingDirectory, "1.1.0"); _testPlatformAbstractions = new TestPlatformAbstractions(); CommandLineUI.Platform = _testPlatformAbstractions; }
public void ShouldVerifyThatSemanticVersionTagCanBeParsed() { TempProject.CreateCsharpProject(Path.Join(_testSetup.WorkingDirectory, "project1"), "2.0.0"); var commit = CommitAll(_testSetup.Repository); var tag = _testSetup.Repository.Tags.Add("vNext", commit, GetAuthorSignature(), "Some annotation message without a version included"); tag.IsSemanticVersionTag().ShouldBeFalse(); }
public void ShouldSelectLightweight() { TempProject.CreateCsharpProject(Path.Join(_testSetup.WorkingDirectory, "project1"), "2.0.0"); var commit = CommitAll(_testSetup.Repository); _testSetup.Repository.Tags.Add("v2.0.0", commit); var versionTag = _testSetup.Repository.SelectVersionTag(new Version(2, 0, 0)); versionTag.ToString().ShouldBe("refs/tags/v2.0.0"); }
public void ShouldDetectConsistentVersions() { var tempDir = TempDir.Create(); TempProject.CreateCsharpProject(Path.Join(tempDir, "project1")); TempProject.CreateCsharpProject(Path.Join(tempDir, "project2")); var projects = Projects.Discover(tempDir); projects.HasInconsistentVersioning().ShouldBeFalse(); }
public void ShouldSelectAnnotatedTags() { TempProject.CreateCsharpProject(Path.Join(_testSetup.WorkingDirectory, "project1"), "2.0.0"); var commit = CommitAll(_testSetup.Repository); _testSetup.Repository.Tags.Add("v2.0.0", commit, GetAuthorSignature(), "Some annotation message without a version included"); var versionTag = _testSetup.Repository.SelectVersionTag(new Version(2, 0, 0)); versionTag.ToString().ShouldBe("refs/tags/v2.0.0"); }
public void ShouldExitIfWorkingCopyIsDirty() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); Should.Throw <CommandLineExitException>(() => workingCopy.Versionize(new VersionizeOptions())); _testPlatformAbstractions.Messages.ShouldHaveSingleItem(); _testPlatformAbstractions.Messages[0].ShouldBe($"Repository {_testSetup.WorkingDirectory} is dirty. Please commit your changes."); }
public void ShouldExitIfReleaseAsSpecifiedVersionIsInvalid() { TempProject.CreateCsharpProject(Path.Join(_testSetup.WorkingDirectory, "project1"), "1.1.0"); CommitAll(_testSetup.Repository); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); Should.Throw <CommandLineExitException>(() => workingCopy.Versionize(new VersionizeOptions { ReleaseAs = "kanguru" })); }
public void ShouldExitIfProjectsUseInconsistentNaming() { TempProject.CreateCsharpProject(Path.Join(_testSetup.WorkingDirectory, "project1"), "1.1.0"); TempProject.CreateCsharpProject(Path.Join(_testSetup.WorkingDirectory, "project2"), "2.0.0"); CommitAll(_testSetup.Repository); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); Should.Throw <CommandLineExitException>(() => workingCopy.Versionize(new VersionizeOptions())); _testPlatformAbstractions.Messages[0].ShouldBe($"Some projects in {_testSetup.WorkingDirectory} have an inconsistent <Version> defined in their csproj file. Please update all versions to be consistent or remove the <Version> elements from projects that should not be versioned"); }
public void ShouldDiscoverAllProjects() { var tempDir = TempDir.Create(); TempProject.CreateCsharpProject(Path.Join(tempDir, "project1")); TempProject.CreateCsharpProject(Path.Join(tempDir, "project2")); TempProject.CreateVBProject(Path.Join(tempDir, "project3")); var projects = Projects.Discover(tempDir); projects.GetProjectFiles().Count().ShouldBe(3); }
public void ShouldReadConfigurationFromConfigFile() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); File.WriteAllText(Path.Join(_testSetup.WorkingDirectory, "hello.txt"), "First commit"); File.WriteAllText(Path.Join(_testSetup.WorkingDirectory, ".versionize"), @"{ ""skipDirty"": true }"); var exitCode = Program.Main(new[] { "-w", _testSetup.WorkingDirectory }); exitCode.ShouldBe(0); File.Exists(Path.Join(_testSetup.WorkingDirectory, "CHANGELOG.md")).ShouldBeTrue(); _testSetup.Repository.Commits.Count().ShouldBe(1); }
public void ShouldReleaseAsSpecifiedVersion() { TempProject.CreateCsharpProject(Path.Join(_testSetup.WorkingDirectory, "project1"), "1.1.0"); CommitAll(_testSetup.Repository); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); workingCopy.Versionize(new VersionizeOptions { ReleaseAs = "2.0.0" }); _testSetup.Repository.Tags.Select(t => t.FriendlyName).ShouldBe(new[] { "v2.0.0" }); }
public void ShouldWriteAllVersionsToProjectFiles() { var tempDir = TempDir.Create(); TempProject.CreateCsharpProject(Path.Join(tempDir, "project1"), "1.1.1"); TempProject.CreateCsharpProject(Path.Join(tempDir, "project2"), "1.1.1"); var projects = Projects.Discover(tempDir); projects.WriteVersion(new SemanticVersion(2, 0, 0)); var updated = Projects.Discover(tempDir); updated.Version.ShouldBe(SemanticVersion.Parse("2.0.0")); }
public void ShouldExitForInvalidReleaseAsReleases() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); var fileCommitter = new FileCommitter(_testSetup); // Release an initial version fileCommitter.CommitChange("chore: initial commit"); workingCopy.Versionize(new VersionizeOptions()); // Release as lower than current version fileCommitter.CommitChange("feat: some feature"); Should.Throw <CommandLineExitException>(() => workingCopy.Versionize(new VersionizeOptions { ReleaseAs = "0.9.0" })); }
public void ShouldEmitAUsefulErrorMessageForDuplicateTags() { TempProject.CreateCsharpProject(Path.Join(_testSetup.WorkingDirectory, "project1"), "1.1.0"); CommitAll(_testSetup.Repository); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); workingCopy.Versionize(new VersionizeOptions { ReleaseAs = "2.0.0" }); Should.Throw <CommandLineExitException>(() => workingCopy.Versionize(new VersionizeOptions { ReleaseAs = "2.0.0" })); _testPlatformAbstractions.Messages.Last().ShouldBe("Version 2.0.0 already exists. Please use a different version."); }
public void ShouldExitWithNonZeroExitCodeForInsignificantCommits() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); var fileCommitter = new FileCommitter(_testSetup); // Release an initial version first fileCommitter.CommitChange("chore: initial commit"); workingCopy.Versionize(new VersionizeOptions()); // Insignificant change release fileCommitter.CommitChange("chore: insignificant change"); Should.Throw <CommandLineExitException>(() => workingCopy.Versionize(new VersionizeOptions { ExitInsignificantCommits = true })); _testPlatformAbstractions.Messages.Last().ShouldStartWith("Version was not affected by commits since last release"); }
public void ShouldPerformADryRun() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); File.WriteAllText(Path.Join(_testSetup.WorkingDirectory, "hello.txt"), "First commit"); CommitAll(_testSetup.Repository, "feat: first commit"); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); workingCopy.Versionize(new VersionizeOptions { DryRun = true, SkipDirty = true }); _testPlatformAbstractions.Messages.Count.ShouldBe(7); _testPlatformAbstractions.Messages[0].ShouldBe("Discovered 1 versionable projects"); _testPlatformAbstractions.Messages[3].ShouldBe("\n---"); _testPlatformAbstractions.Messages[4].ShouldContain("* first commit"); _testPlatformAbstractions.Messages[5].ShouldBe("---\n"); var wasChangelogWritten = File.Exists(Path.Join(_testSetup.WorkingDirectory, "CHANGELOG.md")); Assert.False(wasChangelogWritten); }
public void ShouldIgnoreInsignificantCommits() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingFilePath = Path.Join(_testSetup.WorkingDirectory, "hello.txt"); // Create and commit a test file File.WriteAllText(workingFilePath, "First line of text"); CommitAll(_testSetup.Repository); // Run versionize var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); workingCopy.Versionize(new VersionizeOptions()); // Add insignificant change File.AppendAllText(workingFilePath, "This is another line of text"); CommitAll(_testSetup.Repository, "chore: Added line of text"); // Get last commit var lastCommit = _testSetup.Repository.Head.Tip; // Run versionize, ignoring insignificant commits try { workingCopy.Versionize(new VersionizeOptions { IgnoreInsignificantCommits = true }); throw new InvalidOperationException("Expected to throw in Versionize call"); } catch (CommandLineExitException ex) { ex.ExitCode.ShouldBe(0); } lastCommit.ShouldBe(_testSetup.Repository.Head.Tip); }
public void ShouldAddSuffixToReleaseCommitMessage() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingFilePath = Path.Join(_testSetup.WorkingDirectory, "hello.txt"); // Create and commit a test file File.WriteAllText(workingFilePath, "First line of text"); CommitAll(_testSetup.Repository); // Run versionize var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); const string suffix = "[skip ci]"; workingCopy.Versionize(new VersionizeOptions { CommitSuffix = suffix }); // Get last commit var lastCommit = _testSetup.Repository.Head.Tip; lastCommit.Message.ShouldContain(suffix); }
public void ShouldExitForInvalidPrereleaseSequences() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); var fileCommitter = new FileCommitter(_testSetup); // Release an initial version fileCommitter.CommitChange("chore: initial commit"); workingCopy.Versionize(new VersionizeOptions()); // Prerelease a minor beta fileCommitter.CommitChange("feat: feature pre-release"); workingCopy.Versionize(new VersionizeOptions { Prerelease = "beta" }); // Try Prerelease a minor alpha fileCommitter.CommitChange("feat: feature pre-release"); Should.Throw <CommandLineExitException>(() => workingCopy.Versionize(new VersionizeOptions { Prerelease = "alpha" })); }
public void ShouldAggregatePrereleases() { TempProject.CreateCsharpProject(_testSetup.WorkingDirectory); var workingCopy = WorkingCopy.Discover(_testSetup.WorkingDirectory); var fileCommitter = new FileCommitter(_testSetup); // Release an initial version fileCommitter.CommitChange("feat: initial commit"); workingCopy.Versionize(new VersionizeOptions { AggregatePrereleases = true }); // Prerelease as patch alpha fileCommitter.CommitChange("fix: a fix"); workingCopy.Versionize(new VersionizeOptions { Prerelease = "alpha", AggregatePrereleases = true }); // Prerelease as minor alpha fileCommitter.CommitChange("feat: a feature"); workingCopy.Versionize(new VersionizeOptions { Prerelease = "alpha", AggregatePrereleases = true }); // Full release workingCopy.Versionize(new VersionizeOptions { AggregatePrereleases = true }); // Full release fileCommitter.CommitChange("feat: another feature"); workingCopy.Versionize(new VersionizeOptions { AggregatePrereleases = true }); var versionTagNames = VersionTagNames.ToList(); versionTagNames.ShouldBe(new[] { "v1.0.0", "v1.0.1-alpha.0", "v1.1.0", "v1.1.0-alpha.0", "v1.2.0" }); var commitDate = DateTime.Now.ToString("yyyy-M-d"); var changelogContents = File.ReadAllText(Path.Join(_testSetup.WorkingDirectory, "CHANGELOG.md")); var sb = new ChangelogStringBuilder(); sb.Append(ChangelogOptions.Preamble); sb.Append("<a name=\"1.2.0\"></a>"); sb.Append($"## 1.2.0 ({commitDate})", 2); sb.Append("### Features", 2); sb.Append("* another feature", 2); sb.Append("<a name=\"1.1.0\"></a>"); sb.Append($"## 1.1.0 ({commitDate})", 2); sb.Append("### Features", 2); sb.Append("* a feature", 2); sb.Append("### Bug Fixes", 2); sb.Append("* a fix", 2); sb.Append("<a name=\"1.1.0-alpha.0\"></a>"); sb.Append($"## 1.1.0-alpha.0 ({commitDate})", 2); sb.Append("### Features", 2); sb.Append("* a feature", 2); sb.Append("### Bug Fixes", 2); sb.Append("* a fix", 2); sb.Append("<a name=\"1.0.1-alpha.0\"></a>"); sb.Append($"## 1.0.1-alpha.0 ({commitDate})", 2); sb.Append("### Bug Fixes", 2); sb.Append("* a fix", 2); sb.Append("<a name=\"1.0.0\"></a>"); sb.Append($"## 1.0.0 ({commitDate})", 2); sb.Append("### Features", 2); sb.Append("* initial commit", 2); Assert.Equal(sb.Build(), changelogContents); }