-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: changelog path option overwrites CHANGELOG.md if multiple projec…
…ts point to the same location (#148) Detect duplicate changelog paths during config read. Inform the user and exit with an error message. Introduce new config folder tests with ConfigProviderTests.cs
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using McMaster.Extensions.CommandLineUtils; | ||
using Newtonsoft.Json; | ||
using Shouldly; | ||
using Versionize.CommandLine; | ||
using Versionize.Config; | ||
using Versionize.Tests.TestSupport; | ||
using Xunit; | ||
|
||
namespace Versionize.Tests.Config; | ||
|
||
public class ConfigProviderTests : IDisposable | ||
{ | ||
private readonly TestSetup _testSetup; | ||
private readonly TestPlatformAbstractions _testPlatformAbstractions; | ||
|
||
public ConfigProviderTests() | ||
{ | ||
_testSetup = TestSetup.Create(); | ||
|
||
_testPlatformAbstractions = new TestPlatformAbstractions(); | ||
CommandLineUI.Platform = _testPlatformAbstractions; | ||
} | ||
|
||
[Fact] | ||
public void ShouldExitIfChangelogPathsPointingToSameLocation() | ||
{ | ||
var projects = new[] | ||
{ | ||
new ProjectOptions | ||
{ | ||
Name = "Project1", | ||
Path = "project1", | ||
Changelog = ChangelogOptions.Default with | ||
{ | ||
Header = "Project1 header", | ||
Path = "../docs" | ||
} | ||
}, | ||
new ProjectOptions | ||
{ | ||
Name = "Project2", | ||
Path = "project2", | ||
Changelog = ChangelogOptions.Default with | ||
{ | ||
Header = "Project2 header", | ||
Path = "../docs" | ||
} | ||
} | ||
}; | ||
|
||
var config = new FileConfig | ||
{ | ||
SkipDirty = true, | ||
Projects = projects | ||
}; | ||
var json = JsonConvert.SerializeObject(config); | ||
File.WriteAllText(Path.Join(_testSetup.WorkingDirectory, ".versionize"), json); | ||
var cliConfig = CliConfig.Create(new CommandLineApplication()); | ||
|
||
Should.Throw<CommandLineExitException>(() => ConfigProvider.GetSelectedOptions(_testSetup.WorkingDirectory, cliConfig)); | ||
_testPlatformAbstractions.Messages[0].ShouldBe("Two or more projects have changelog paths pointing to the same location."); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_testSetup.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters