Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix command line activation not working properly in some cases #870

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ updates:

- package-ecosystem: "nuget"
# location of package manifests
directory: "/src/Notepads"
directory: "/src/Notepads.UnitTest"
schedule:
interval: "daily"
commit-message:
Expand Down
36 changes: 31 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Notepads CI/CD Pipeline

on:
on:
push:
paths-ignore:
- '**.md'
Expand Down Expand Up @@ -106,6 +106,8 @@ jobs:
is_release: ${{ matrix.release }}
env:
SOLUTION_NAME: src\Notepads.sln
PROJECT_NAME: src\Notepads\Notepads.csproj
TEST_PROJECT_NAME: src\Notepads.UnitTest\Notepads.UnitTest.csproj
CONFIGURATION: ${{ matrix.configuration }}
DEFAULT_DIR: ${{ github.workspace }}
steps:
Expand All @@ -124,6 +126,10 @@ jobs:
id: setup-nuget
uses: NuGet/setup-nuget@v1.0.5

- name: Setup VSTest
id: setup-vstest
uses: darenm/Setup-VSTest@v1

- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -156,7 +162,7 @@ jobs:
name: Bump GitHub tag
id: tag_generator
uses: soumyamahunt/github-tag-action@test-other-ver-support
with:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
latest_ver: ${{ steps.check_latest_tag.outputs.semver }}
default_bump: true
Expand Down Expand Up @@ -212,7 +218,7 @@ jobs:
id: init_sonar_scanner
shell: pwsh
run: |
$LOWERCASE_REPOSITORY_NAME = "${{ github.event.repository.name }}".ToLower()
$LOWERCASE_REPOSITORY_NAME = "${{ github.event.repository.name }}".ToLower()
.\.sonar\scanner\dotnet-sonarscanner begin `
/k:"${{ github.repository_owner }}_${{ github.event.repository.name }}" `
/o:"$LOWERCASE_REPOSITORY_NAME" `
Expand Down Expand Up @@ -250,9 +256,10 @@ jobs:
id: build_app
shell: pwsh
run: |
msbuild $env:SOLUTION_NAME `
msbuild $env:PROJECT_NAME `
/p:Platform=$env:PLATFORM `
/p:Configuration=$env:CONFIGURATION `
/p:AllowUnsafeBlocks=true `
/p:UapAppxPackageBuildMode=$env:UAP_APPX_PACKAGE_BUILD_MODE `
/p:AppxBundle=$env:APPX_BUNDLE `
/p:AppxPackageSigningEnabled=$env:APPX_PACKAGE_SIGNING_ENABLED `
Expand All @@ -277,9 +284,10 @@ jobs:
id: build_app_arm_debug
shell: pwsh
run: |
msbuild $env:SOLUTION_NAME `
msbuild $env:PROJECT_NAME `
/p:Platform=$env:PLATFORM `
/p:Configuration=$env:CONFIGURATION `
/p:AllowUnsafeBlocks=true `
/p:UapAppxPackageBuildMode=$env:UAP_APPX_PACKAGE_BUILD_MODE `
/p:AppxBundle=$env:APPX_BUNDLE `
/p:AppxBundlePlatforms=$env:APPX_BUNDLE_PLATFORMS
Expand Down Expand Up @@ -314,6 +322,24 @@ jobs:
name: Build artifacts
path: Artifacts/

- if: matrix.debug || matrix.release
name: Run Unit Tests
id: run_unittest
shell: pwsh
run: |
msbuild $env:TEST_PROJECT_NAME `
/p:Platform=$env:PLATFORM `
/p:Configuration=$env:CONFIGURATION `
/p:AllowUnsafeBlocks=true `
/p:AppxBundlePlatforms=$env:APPX_BUNDLE_PLATFORMS

$TEST_PATH = "$([System.IO.Path]::GetDirectoryName($env:TEST_PROJECT_NAME))$(
)\bin\$($env:PLATFORM)\$($env:CONFIGURATION)\Notepads.UnitTest.build.appxrecipe"
vstest.console.exe $TEST_PATH /framework:FrameworkUap10
env:
PLATFORM: x64
APPX_BUNDLE_PLATFORMS: x64

cd:
# "This job will execute when the workflow is triggered on a 'push event', the target branch is 'master' and the commit is intended to be a release."
if: needs.ci.outputs.is_release == 'true' && needs.ci.outputs.new_version != ''
Expand Down
10 changes: 6 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pool:
vmImage: 'windows-latest'

variables:
solution: '**/*.sln'
solution: '**\*.sln'
project: 'src\Notepads\Notepads.csproj'
buildPlatform: 'x86|x64|arm64'
buildConfiguration: 'Production'
appxPackageDir: '$(build.artifactStagingDirectory)\AppxPackages\\'
Expand All @@ -30,10 +31,11 @@ steps:
- task: VSBuild@1
inputs:
platform: 'x64'
solution: '$(solution)'
solution: '$(project)'
configuration: '$(buildConfiguration)'
msbuildArgs: '/p:AppxBundlePlatforms="$(buildPlatform)"
msbuildArgs: '/p:AllowUnsafeBlocks=true
/p:AppxBundlePlatforms="$(buildPlatform)"
/p:AppxPackageDir="$(appxPackageDir)"
/p:AppxBundle=Always
/p:UapAppxPackageBuildMode=StoreUpload
/p:AppxPackageSigningEnabled=false'
/p:AppxPackageSigningEnabled=false'
118 changes: 118 additions & 0 deletions src/Notepads.UnitTest/CommandLineTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
namespace Notepads.UnitTest
{
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Notepads.Utilities;

[TestClass]
public class CommandLineTest
{
private const string cmdArg = "notepads";
private const string pwshArg = "\"C:\\Users\\Test User\\AppData\\Local\\Microsoft\\WindowsApps\\Notepads.exe\"";

private const string windowsRoot = "C:";
private const string wslRoot = @"\\wsl$\Ubuntu";

private static IEnumerable<string[]> GetTestData(string root, string alias)
{
yield return new string[] { $"{root}\\", $"{alias} \"{root}\\1.txt\"", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"{root}\\1 2.txt\"", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} {root}\\1.txt", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} {root}\\1 2.txt", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"{root}\\2.txt\"", $"{root}\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"{root}\\2 3.txt\"", $"{root}\\2 3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} {root}\\2.txt", $"{root}\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} {root}\\2 3.txt", $"{root}\\2 3.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"\\1.txt\"", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"\\1 2.txt\"", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} \\1.txt", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \\1 2.txt", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"\\2.txt\"", $"{root}\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"\\2 3.txt\"", $"{root}\\2 3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \\2.txt", $"{root}\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \\2 3.txt", $"{root}\\2 3.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"1.txt\"", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"1 2.txt\"", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} 1.txt", $"{root}\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} 1 2.txt", $"{root}\\1 2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"2.txt\"", $"{root}\\1\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"2 3.txt\"", $"{root}\\1\\2 3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} 2.txt", $"{root}\\1\\2.txt" };
yield return new string[] { $"{root}\\1", $"{alias} 2 3.txt", $"{root}\\1\\2 3.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"1\\2.txt\"", $"{root}\\1\\2.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"1 2\\3 4.txt\"", $"{root}\\1 2\\3 4.txt" };
yield return new string[] { $"{root}\\", $"{alias} 1\\2.txt", $"{root}\\1\\2.txt" };
yield return new string[] { $"{root}\\", $"{alias} 1 2\\3 4.txt", $"{root}\\1 2\\3 4.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"2\\3.txt\"", $"{root}\\1\\2\\3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} \"2 3\\4 5.txt\"", $"{root}\\1\\2 3\\4 5.txt" };
yield return new string[] { $"{root}\\1", $"{alias} 2\\3.txt", $"{root}\\1\\2\\3.txt" };
yield return new string[] { $"{root}\\1", $"{alias} 2 3\\4 5.txt", $"{root}\\1\\2 3\\4 5.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"D:\\1.txt\"", $"D:\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"D:\\1\\2.txt\"", $"D:\\1\\2.txt" };
yield return new string[] { $"{root}\\", $"{alias} D:\\1.txt", $"D:\\1.txt" };
yield return new string[] { $"{root}\\", $"{alias} D:\\1\\2.txt", $"D:\\1\\2.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"D:\\1 2.txt\"", $"D:\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} \"D:\\1 2\\3 4.txt\"", $"D:\\1 2\\3 4.txt" };
yield return new string[] { $"{root}\\", $"{alias} D:\\1 2.txt", $"D:\\1 2.txt" };
yield return new string[] { $"{root}\\", $"{alias} D:\\1 2\\3 4.txt", $"D:\\1 2\\3 4.txt" };
}

private static IEnumerable<string[]> GetCommandPromptTestData()
{
return GetTestData(windowsRoot, cmdArg);
}

private static IEnumerable<string[]> GetPowerShellTestData()
{
return GetTestData(windowsRoot, pwshArg);
}

private static IEnumerable<string[]> GetWslTestData()
{
foreach(var data in GetTestData(wslRoot, pwshArg))
{
yield return data;
}

yield return new string[] { $"{wslRoot}\\", $"{pwshArg} \"/etc/sudo.conf\"", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\", $"{pwshArg} \"etc/sudo.conf\"", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\", $"{pwshArg} /etc/sudo.conf", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\", $"{pwshArg} etc/sudo.conf", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\etc", $"{pwshArg} \"/etc/sudo.conf\"", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\etc", $"{pwshArg} \"sudo.conf\"", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\etc", $"{pwshArg} /etc/sudo.conf", $"{wslRoot}\\etc\\sudo.conf" };
yield return new string[] { $"{wslRoot}\\etc", $"{pwshArg} sudo.conf", $"{wslRoot}\\etc\\sudo.conf" };
}

[DataTestMethod]
[DynamicData(nameof(GetCommandPromptTestData), DynamicDataSourceType.Method)]
public void CommandLineTestForCommandPrompt(string dir, string arg, string result)
{
Assert.AreEqual(
CommandLineUtility.GetAbsolutePathFromCommandLine(dir, arg),
result
);
}

[DataTestMethod]
[DynamicData(nameof(GetPowerShellTestData), DynamicDataSourceType.Method)]
public void CommandLineTestForPowerShell(string dir, string arg, string result)
{
Assert.AreEqual(
CommandLineUtility.GetAbsolutePathFromCommandLine(dir, arg),
result
);
}

[DataTestMethod]
[DynamicData(nameof(GetWslTestData), DynamicDataSourceType.Method)]
public void CommandLineTestForWsl(string dir, string arg, string result)
{
Assert.AreEqual(
CommandLineUtility.GetAbsolutePathFromCommandLine(dir, arg),
result
);
}
}
}