Skip to content

Commit

Permalink
Release v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidL344 committed Oct 7, 2024
2 parents 82ab7a2 + d6553eb commit e9a2c44
Show file tree
Hide file tree
Showing 56 changed files with 531 additions and 146 deletions.
4 changes: 2 additions & 2 deletions Athena.Cli/Commands/ConfigCommands.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Text.Json;
using Athena.Cli.Commands.Internal;
using Athena.Core.Configuration;
using Athena.Core.Model;
using Athena.Core.Parser;
using Athena.Core.Runner;
using Athena.Desktop.Configuration;
using Athena.Desktop.Runner;
using Cocona;
using Microsoft.Extensions.Logging;

Expand Down
2 changes: 1 addition & 1 deletion Athena.Cli/Commands/IntegrationCommands.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Athena.Cli.Commands.Internal;
using Athena.Core.Desktop;
using Athena.Desktop.System;
using Cocona;
using Microsoft.Extensions.Logging;
using Spectre.Console;
Expand Down
4 changes: 2 additions & 2 deletions Athena.Cli/Commands/RunCommands.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Athena.Cli.Commands.Internal;
using Athena.Cli.Model;
using Athena.Cli.Terminal;
using Athena.Core.Configuration;
using Athena.Core.Extensions;
using Athena.Core.Model;
using Athena.Core.Options;
using Athena.Core.Parser;
using Athena.Core.Runner;
using Athena.Desktop.Configuration;
using Athena.Desktop.Runner;
using Cocona;
using Microsoft.Extensions.Logging;

Expand Down
9 changes: 3 additions & 6 deletions Athena.Core.Tests/Athena.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Athena.Core\Athena.Core.csproj" />
<ProjectReference Include="..\Athena.Core\Athena.Core.csproj" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" />
</ItemGroup>

<ItemGroup>
<Folder Include="Internal\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Athena.Core.Configuration;
using Athena.Core.Extensions.DependencyInjection;
using Athena.Core.Internal;
using Athena.Core.Options;
using Athena.Core.Parser;
using Athena.Core.Runner;
using Athena.Desktop.Configuration;
using Athena.Desktop.Runner;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

Expand Down
30 changes: 30 additions & 0 deletions Athena.Core.Tests/Extensions/OpenerExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Athena.Core.Extensions;
using Athena.Core.Model;

namespace Athena.Core.Tests.Extensions;

public class OpenerExtensionsTests
{
[Fact]
public void GetAppEntryIndex__ReturnsTheCorrectIndex__WhenEntryNameIsSpecified()
{
// Arrange
const int expectedIndex = 1;
var fileExtension = new FileExtension
{
Name = "Text file",
AppList =
[
"vi.open",
"notepad.open", // The expected index is 1
"nano.open"
]
};

// Act
var result = fileExtension.GetAppEntryIndex("notepad.open");

// Assert
Assert.Equal(expectedIndex, result);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Athena.Core.Configuration;
using Athena.Core.Internal;
using Athena.Core.Internal.Helpers;
using Athena.Desktop.Configuration;
using Athena.Desktop.Helpers;

namespace Athena.Core.Tests.Internal.Helpers;
namespace Athena.Core.Tests.Helpers;

[Collection("Sequential")]
public class ConfigHelperTests : IDisposable
Expand Down Expand Up @@ -160,13 +160,16 @@ public void IsConfigUpToDate__ThrowsException__WhenTheConfigVersionIsNewerThanTh
{
// Arrange
var config = new Config { Version = $"{int.MaxValue}.{int.MaxValue}.{int.MaxValue}" };
var expected = $"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Minor}.{ThisAssembly.Git.SemVer.Patch}";

// Act
var exception = Record.Exception(() => ConfigHelper.IsConfigUpToDate(config, out _));

// Assert
Assert.IsType<ApplicationException>(exception);
Assert.Equal("The configuration version is newer than the application version!", exception.Message);
Assert.Equal(
$"The configuration version ({config.Version}) is newer than the application version ({expected})!",
exception.Message);
}

[Fact]
Expand Down
54 changes: 54 additions & 0 deletions Athena.Core.Tests/Helpers/ParserHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Athena.Core.Internal.Helpers;

namespace Athena.Core.Tests.Helpers;

public class ParserHelperTests
{
[Theory]
[InlineData("file:///file.mp4")]
[InlineData("file://file.mp4")]
public void ParseStreamPath__RemovesFileProtocol__WhenItExists(string filePath)
{
// Arrange
var expected = Path.GetFullPath(filePath.Split("://").LastOrDefault()!);

// Act
var result = ParserHelper.ParseStreamPath(filePath, []);

// Assert
Assert.Equal(expected, result);
}

[Theory]
[InlineData("athena:https://example.com/file.mp4")]
[InlineData("stream:https://example.com/file.mp4")]
public void ParseStreamPath__RemovesFileProtocol__WhenProtocolIsStreamable(string filePath)
{
// Arrange
var expected = string.Join(null, filePath.Substring(filePath.Split(":").FirstOrDefault()!.Length + 1));

// Act
var result = ParserHelper.ParseStreamPath(filePath, ["athena", "stream"]);

// Assert
Assert.Equal(expected, result);
}

[Theory]
[InlineData("$1")]
[InlineData("$TEST")]
[InlineData("$1TEST")]
[InlineData("$TEST1")]
public void ExpandEnvironmentVariables__ConvertsUnixFormat__WhenItIsPresent(string variable)
{
// Arrange
var expected = variable.Replace('$', '%');
if (!int.TryParse(expected.Substring(1), out _)) expected += "%";

// Act
var result = ParserHelper.ExpandEnvironmentVariables(variable);

// Assert
Assert.Equal(expected, result);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Athena.Core.Internal.Helpers;
using Athena.Desktop.Helpers;

namespace Athena.Core.Tests.Internal.Helpers;
namespace Athena.Core.Tests.Helpers;

public class SystemHelperTests
{
Expand Down
12 changes: 7 additions & 5 deletions Athena.Core.Tests/Parser/AppEntryParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Athena.Core.Configuration;
using Athena.Core.Internal;
using Athena.Core.Model;
using Athena.Core.Options;
using Athena.Core.Parser;
using Athena.Desktop.Configuration;
using Microsoft.Extensions.Logging;

namespace Athena.Core.Tests.Parser;
Expand Down Expand Up @@ -180,19 +180,21 @@ public void GetAppDefinition__ThrowsException__WhenTheAppEntryIsEmpty(string app
Assert.Equal("The app entry name is invalid!", exception.Message);
}

[Fact]
public void GetFriendlyNames__ReturnsFriendlyNames__WhenTheyExist()
[Theory]
[InlineData(true)]
[InlineData(false)]
public void GetFriendlyNames__ReturnsFriendlyNames__WhenTheyExist(bool multiline)
{
// Arrange
var parser = new AppEntryParser(_configPaths, _jsonSerializerOptions, _logger);
var expected = new[] { "mpv (Play)" };
var expected = new[] { multiline ? "mpv (Play)\r\n mpv %1" : "mpv (Play)" };

// Act
var result = parser.GetFriendlyNames(new FileExtension
{
Name = "MP4 Video",
AppList = [ "mpv.play" ]
});
}, multiline: multiline);

// Assert
Assert.Equivalent(expected, result);
Expand Down
2 changes: 1 addition & 1 deletion Athena.Core.Tests/Parser/OpenerParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Athena.Core.Configuration;
using Athena.Core.Internal;
using Athena.Core.Model;
using Athena.Core.Options;
using Athena.Core.Parser;
using Athena.Desktop.Configuration;
using Microsoft.Extensions.Logging;

namespace Athena.Core.Tests.Parser;
Expand Down
43 changes: 35 additions & 8 deletions Athena.Core.Tests/Parser/PathParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Athena.Core.Configuration;
using System.Text.RegularExpressions;
using Athena.Core.Internal;
using Athena.Core.Options;
using Athena.Core.Parser;
using Athena.Desktop.Configuration;
using Microsoft.Extensions.Logging;

namespace Athena.Core.Tests.Parser;

public class PathParserTests : IDisposable
public partial class PathParserTests : IDisposable
{
private readonly string _workingDir;
private readonly string _testsConfigDir;
Expand Down Expand Up @@ -74,14 +75,17 @@ public void GetPath__ReturnsPath__WhenFilePathHasEnvironmentVariables(string fil
Environment.SetEnvironmentVariable("CURRENT_DIR", _workingDir);
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
filePath = filePath
.Replace("$HOME", "$USERPROFILE")
.Replace("$HOME", "%USERPROFILE%")
.Replace("%HOME%", "%USERPROFILE%");

filePath = Environment.ExpandEnvironmentVariables(filePath
.Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))
.Replace("$HOME", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))
.Replace("$CURRENT_DIR", _workingDir));
var expected = filePath;

var expected = filePath
.Replace('/', Path.DirectorySeparatorChar)
.Replace('\\', Path.DirectorySeparatorChar);

// Act
var result = parser.GetPath(filePath, options);
Expand All @@ -104,10 +108,30 @@ public void GetPath__ReturnsPath__WhenFilePathIsAbsolute(string filePath)
// Arrange
var options = new ParserOptions { OpenLocally = true };
var parser = new PathParser(_logger);
var expected = filePath.StartsWith('\\')
? $"{Path.GetPathRoot(Directory.GetCurrentDirectory())}{filePath
.Remove(0, 1).Replace('\\', Path.DirectorySeparatorChar)}"
: filePath;

var expected = filePath;

if (OperatingSystem.IsWindows())
{
if (filePath.StartsWith('/') || filePath.StartsWith('\\'))
expected = $"{Path.GetPathRoot(Directory.GetCurrentDirectory())}{filePath
.Remove(0, 1)}";

expected = expected.Replace('/', Path.DirectorySeparatorChar);
}

if (OperatingSystem.IsLinux())
{
var windowsDriveRegex = WindowsDriveRegex();
var windowsDriveMatch = windowsDriveRegex.Match(filePath);

if (windowsDriveMatch.Success)
expected = $"/{expected.Remove(0, windowsDriveMatch.Length)}";

// Making sure it's not a Windows network drive that starts with "\\" instead of "/"
if (!expected.StartsWith(@"\\"))
expected = expected.Replace('\\', Path.DirectorySeparatorChar);
}

// Act
var result = parser.GetPath(filePath, options);
Expand Down Expand Up @@ -171,4 +195,7 @@ public void GetPath__ReturnsPath__WhenFilePathIsRemote(string filePath)
// Assert
Assert.Equal(expected, result);
}

[GeneratedRegex(@"^[a-zA-Z]:[\\|\/]")]
private static partial Regex WindowsDriveRegex();
}
13 changes: 9 additions & 4 deletions Athena.Core.Tests/Runner/AppRunnerTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Reflection;
using System.Text;
using Athena.Core.Options;
using Athena.Core.Runner;
using Athena.Desktop.Runner;
using CliWrap;
using CliWrap.Buffered;
using Microsoft.Extensions.Logging;
Expand All @@ -10,6 +9,7 @@ namespace Athena.Core.Tests.Runner;

public class AppRunnerTests
{
private readonly string[] _builtinCommands = ["echo"];
private readonly StringBuilder _stdOutBuffer;
private readonly StringBuilder _stdErrBuffer;
private readonly AppRunner _runner;
Expand All @@ -36,11 +36,12 @@ private void ClearBuffers()
_stdErrBuffer.Clear();
}

[Theory]
[SkippableTheory]
[InlineData("echo", "Hello, World!", "Hello, World!")]
public async Task Run__RunsCommand__WhenItExists(string executablePath, string arguments, string expectedStdOut)
{
// Arrange
Skip.If(IsSkippable(executablePath));
ClearBuffers();

// Act
Expand All @@ -52,13 +53,14 @@ public async Task Run__RunsCommand__WhenItExists(string executablePath, string a
Assert.Empty(_stdErrBuffer.ToString().Trim());
}

[Theory]
[SkippableTheory]
[InlineData("dotnet", "--version")]
[InlineData("dotnet", "--help")]
[InlineData("echo", "Hello, World!")]
public async Task Run__ReturnsCorrectOutput__WhenExecutionFinishes(string executablePath, string arguments)
{
// Arrange
Skip.If(IsSkippable(executablePath));
ClearBuffers();
var stdOut = new StringBuilder();
var stdErr = new StringBuilder();
Expand Down Expand Up @@ -114,4 +116,7 @@ public async Task Run__ThrowsException__WhenItDoesNotExist(string executablePath
Assert.Empty(_stdOutBuffer.ToString().Trim());
Assert.Empty(_stdErrBuffer.ToString().Trim());
}

private bool IsSkippable(string commandName)
=> OperatingSystem.IsWindows() && _builtinCommands.Contains(commandName);
}
Loading

0 comments on commit e9a2c44

Please sign in to comment.