This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
forked from Squirrel/Squirrel.Windows
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
2,730 additions
and
2,965 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
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
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 |
---|---|---|
@@ -1,29 +1,25 @@ | ||
using Squirrel.CommandLine.Commands; | ||
using Xunit; | ||
namespace Squirrel.CommandLine.Tests; | ||
|
||
namespace Squirrel.CommandLine.Tests | ||
public abstract class BaseCommandTests<T> : TempFileTestBase | ||
where T : BaseCommand, new() | ||
{ | ||
public abstract class BaseCommandTests<T> : TempFileTestBase | ||
where T : BaseCommand, new() | ||
{ | ||
public virtual bool ShouldBeNonEmptyReleaseDir => false; | ||
|
||
[Fact] | ||
public void ReleaseDirectory_WithDirectory_ParsesValue() | ||
{ | ||
var releaseDirectory = CreateTempDirectory(); | ||
public virtual bool ShouldBeNonEmptyReleaseDir => false; | ||
|
||
if (ShouldBeNonEmptyReleaseDir) | ||
CreateTempFile(releaseDirectory, "anything"); | ||
[Fact] | ||
public void ReleaseDirectory_WithDirectory_ParsesValue() | ||
{ | ||
var releaseDirectory = CreateTempDirectory(); | ||
|
||
BaseCommand command = new T(); | ||
if (ShouldBeNonEmptyReleaseDir) | ||
CreateTempFile(releaseDirectory, "anything"); | ||
|
||
var cli = GetRequiredDefaultOptions() + $"--outputDir \"{releaseDirectory.FullName}\""; | ||
var parseResult = command.ParseAndApply(cli); | ||
BaseCommand command = new T(); | ||
|
||
Assert.Equal(releaseDirectory.FullName, command.ReleaseDirectory); | ||
} | ||
var cli = GetRequiredDefaultOptions() + $"--outputDir \"{releaseDirectory.FullName}\""; | ||
var parseResult = command.ParseAndApply(cli); | ||
|
||
protected virtual string GetRequiredDefaultOptions() => ""; | ||
Assert.Equal(releaseDirectory.FullName, command.ReleaseDirectory); | ||
} | ||
|
||
protected virtual string GetRequiredDefaultOptions() => ""; | ||
} |
139 changes: 67 additions & 72 deletions
139
test/Squirrel.CommandLine.Tests/Commands/GitHubCommandTests.cs
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 |
---|---|---|
@@ -1,102 +1,97 @@ | ||
using System.CommandLine.Parsing; | ||
using Squirrel.CommandLine.Commands; | ||
using Xunit; | ||
namespace Squirrel.CommandLine.Tests.Commands; | ||
|
||
namespace Squirrel.CommandLine.Tests.Commands | ||
public abstract class GitHubCommandTests<T> : BaseCommandTests<T> | ||
where T : GitHubBaseCommand, new() | ||
{ | ||
public abstract class GitHubCommandTests<T> : BaseCommandTests<T> | ||
where T : GitHubBaseCommand, new() | ||
[Fact] | ||
public void RepoUrl_WithUrl_ParsesValue() | ||
{ | ||
[Fact] | ||
public void RepoUrl_WithUrl_ParsesValue() | ||
{ | ||
GitHubBaseCommand command = new T(); | ||
GitHubBaseCommand command = new T(); | ||
|
||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"http://clowd.squirrel.com\""); | ||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"http://clowd.squirrel.com\""); | ||
|
||
Assert.Empty(parseResult.Errors); | ||
Assert.Equal("http://clowd.squirrel.com/", command.RepoUrl); | ||
} | ||
Assert.Empty(parseResult.Errors); | ||
Assert.Equal("http://clowd.squirrel.com/", command.RepoUrl); | ||
} | ||
|
||
[Fact] | ||
public void RepoUrl_WithNonHttpValue_ShowsError() | ||
{ | ||
GitHubBaseCommand command = new T(); | ||
[Fact] | ||
public void RepoUrl_WithNonHttpValue_ShowsError() | ||
{ | ||
GitHubBaseCommand command = new T(); | ||
|
||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"file://clowd.squirrel.com\""); | ||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"file://clowd.squirrel.com\""); | ||
|
||
Assert.Equal(1, parseResult.Errors.Count); | ||
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol); | ||
Assert.StartsWith("--repoUrl must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message); | ||
} | ||
Assert.Equal(1, parseResult.Errors.Count); | ||
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol); | ||
Assert.StartsWith("--repoUrl must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message); | ||
} | ||
|
||
[Fact] | ||
public void RepoUrl_WithRelativeUrl_ShowsError() | ||
{ | ||
GitHubBaseCommand command = new T(); | ||
[Fact] | ||
public void RepoUrl_WithRelativeUrl_ShowsError() | ||
{ | ||
GitHubBaseCommand command = new T(); | ||
|
||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"clowd.squirrel.com\""); | ||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"clowd.squirrel.com\""); | ||
|
||
Assert.Equal(1, parseResult.Errors.Count); | ||
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol); | ||
Assert.StartsWith("--repoUrl must contain an absolute Uri.", parseResult.Errors[0].Message); | ||
} | ||
Assert.Equal(1, parseResult.Errors.Count); | ||
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol); | ||
Assert.StartsWith("--repoUrl must contain an absolute Uri.", parseResult.Errors[0].Message); | ||
} | ||
|
||
[Fact] | ||
public void Token_WithValue_ParsesValue() | ||
{ | ||
GitHubBaseCommand command = new T(); | ||
[Fact] | ||
public void Token_WithValue_ParsesValue() | ||
{ | ||
GitHubBaseCommand command = new T(); | ||
|
||
string cli = GetRequiredDefaultOptions() + $"--token \"abc\""; | ||
ParseResult parseResult = command.ParseAndApply(cli); | ||
string cli = GetRequiredDefaultOptions() + $"--token \"abc\""; | ||
ParseResult parseResult = command.ParseAndApply(cli); | ||
|
||
Assert.Equal("abc", command.Token); | ||
} | ||
Assert.Equal("abc", command.Token); | ||
} | ||
|
||
protected override string GetRequiredDefaultOptions() | ||
{ | ||
return $"--repoUrl \"https://clowd.squirrel.com\" "; | ||
} | ||
protected override string GetRequiredDefaultOptions() | ||
{ | ||
return $"--repoUrl \"https://clowd.squirrel.com\" "; | ||
} | ||
} | ||
|
||
public class GitHubDownloadCommandTests : GitHubCommandTests<GitHubDownloadCommand> | ||
public class GitHubDownloadCommandTests : GitHubCommandTests<GitHubDownloadCommand> | ||
{ | ||
[Fact] | ||
public void Pre_BareOption_SetsFlag() | ||
{ | ||
[Fact] | ||
public void Pre_BareOption_SetsFlag() | ||
{ | ||
var command = new GitHubDownloadCommand(); | ||
var command = new GitHubDownloadCommand(); | ||
|
||
string cli = GetRequiredDefaultOptions() + "--pre"; | ||
ParseResult parseResult = command.ParseAndApply(cli); | ||
string cli = GetRequiredDefaultOptions() + "--pre"; | ||
ParseResult parseResult = command.ParseAndApply(cli); | ||
|
||
Assert.True(command.Pre); | ||
} | ||
Assert.True(command.Pre); | ||
} | ||
} | ||
|
||
public class GitHubUploadCommandTests : GitHubCommandTests<GitHubUploadCommand> | ||
{ | ||
public override bool ShouldBeNonEmptyReleaseDir => true; | ||
public class GitHubUploadCommandTests : GitHubCommandTests<GitHubUploadCommand> | ||
{ | ||
public override bool ShouldBeNonEmptyReleaseDir => true; | ||
|
||
[Fact] | ||
public void Publish_BareOption_SetsFlag() | ||
{ | ||
var command = new GitHubUploadCommand(); | ||
[Fact] | ||
public void Publish_BareOption_SetsFlag() | ||
{ | ||
var command = new GitHubUploadCommand(); | ||
|
||
string cli = GetRequiredDefaultOptions() + "--publish"; | ||
ParseResult parseResult = command.ParseAndApply(cli); | ||
string cli = GetRequiredDefaultOptions() + "--publish"; | ||
ParseResult parseResult = command.ParseAndApply(cli); | ||
|
||
Assert.True(command.Publish); | ||
} | ||
Assert.True(command.Publish); | ||
} | ||
|
||
[Fact] | ||
public void ReleaseName_WithName_ParsesValue() | ||
{ | ||
var command = new GitHubUploadCommand(); | ||
[Fact] | ||
public void ReleaseName_WithName_ParsesValue() | ||
{ | ||
var command = new GitHubUploadCommand(); | ||
|
||
string cli = GetRequiredDefaultOptions() + $"--releaseName \"my release\""; | ||
ParseResult parseResult = command.ParseAndApply(cli); | ||
string cli = GetRequiredDefaultOptions() + $"--releaseName \"my release\""; | ||
ParseResult parseResult = command.ParseAndApply(cli); | ||
|
||
Assert.Equal("my release", command.ReleaseName); | ||
} | ||
Assert.Equal("my release", command.ReleaseName); | ||
} | ||
} |
66 changes: 31 additions & 35 deletions
66
test/Squirrel.CommandLine.Tests/Commands/HttpDownloadCommandTests.cs
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 |
---|---|---|
@@ -1,49 +1,45 @@ | ||
using System.CommandLine.Parsing; | ||
using Squirrel.CommandLine.Commands; | ||
using Xunit; | ||
| ||
namespace Squirrel.CommandLine.Tests.Commands; | ||
|
||
namespace Squirrel.CommandLine.Tests.Commands | ||
public class HttpDownloadCommandTests : BaseCommandTests<HttpDownloadCommand> | ||
{ | ||
public class HttpDownloadCommandTests : BaseCommandTests<HttpDownloadCommand> | ||
[Fact] | ||
public void Url_WithUrl_ParsesValue() | ||
{ | ||
[Fact] | ||
public void Url_WithUrl_ParsesValue() | ||
{ | ||
var command = new HttpDownloadCommand(); | ||
var command = new HttpDownloadCommand(); | ||
|
||
ParseResult parseResult = command.ParseAndApply($"--url \"http://clowd.squirrel.com\""); | ||
ParseResult parseResult = command.ParseAndApply($"--url \"http://clowd.squirrel.com\""); | ||
|
||
Assert.Empty(parseResult.Errors); | ||
Assert.Equal("http://clowd.squirrel.com/", command.Url); | ||
} | ||
Assert.Empty(parseResult.Errors); | ||
Assert.Equal("http://clowd.squirrel.com/", command.Url); | ||
} | ||
|
||
[Fact] | ||
public void Url_WithNonHttpValue_ShowsError() | ||
{ | ||
var command = new HttpDownloadCommand(); | ||
[Fact] | ||
public void Url_WithNonHttpValue_ShowsError() | ||
{ | ||
var command = new HttpDownloadCommand(); | ||
|
||
ParseResult parseResult = command.ParseAndApply($"--url \"file://clowd.squirrel.com\""); | ||
ParseResult parseResult = command.ParseAndApply($"--url \"file://clowd.squirrel.com\""); | ||
|
||
Assert.Equal(1, parseResult.Errors.Count); | ||
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol); | ||
Assert.StartsWith("--url must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message); | ||
} | ||
Assert.Equal(1, parseResult.Errors.Count); | ||
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol); | ||
Assert.StartsWith("--url must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message); | ||
} | ||
|
||
[Fact] | ||
public void Url_WithRelativeUrl_ShowsError() | ||
{ | ||
var command = new HttpDownloadCommand(); | ||
[Fact] | ||
public void Url_WithRelativeUrl_ShowsError() | ||
{ | ||
var command = new HttpDownloadCommand(); | ||
|
||
ParseResult parseResult = command.ParseAndApply($"--url \"clowd.squirrel.com\""); | ||
ParseResult parseResult = command.ParseAndApply($"--url \"clowd.squirrel.com\""); | ||
|
||
Assert.Equal(1, parseResult.Errors.Count); | ||
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol); | ||
Assert.StartsWith("--url must contain an absolute Uri.", parseResult.Errors[0].Message); | ||
} | ||
Assert.Equal(1, parseResult.Errors.Count); | ||
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol); | ||
Assert.StartsWith("--url must contain an absolute Uri.", parseResult.Errors[0].Message); | ||
} | ||
|
||
protected override string GetRequiredDefaultOptions() | ||
{ | ||
return $"--url \"https://clowd.squirrel.com\" "; | ||
} | ||
protected override string GetRequiredDefaultOptions() | ||
{ | ||
return $"--url \"https://clowd.squirrel.com\" "; | ||
} | ||
} |
Oops, something went wrong.