diff --git a/src/.editorconfig b/.editorconfig similarity index 100% rename from src/.editorconfig rename to .editorconfig diff --git a/.github/workflows/choco-deploy.yml b/.github/workflows/choco-deploy.yml new file mode 100644 index 0000000..d50f5a1 --- /dev/null +++ b/.github/workflows/choco-deploy.yml @@ -0,0 +1,36 @@ +name: Deploy Chocolatey Package + +on: + push: + branches: [ "main" ] + +jobs: + deploy: + runs-on: windows-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.0.x' # Uses latest available 10.0 SDK + + - name: Build and Pack + shell: pwsh + run: ./choco/build.ps1 + env: + CI: true + + - name: Push to Chocolatey + shell: pwsh + run: | + $package = Get-ChildItem *.nupkg | Select-Object -First 1 + if ($package) { + choco push $($package.Name) --source "https://push.chocolatey.org/" --api-key ${{ secrets.CHOCO_API_KEY }} + } else { + Write-Error "No .nupkg file found to push." + exit 1 + } diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..2b0a6e6 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,28 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore ./src + - name: Build + run: dotnet build ./src --no-restore + - name: Test + run: dotnet test ./src --no-build --verbosity normal diff --git a/src/YesNt.Interpreter.Tests/ConsoleStatementsTests.cs b/src/YesNt.Interpreter.Tests/ConsoleStatementsTests.cs index 1ba7cbc..0901d10 100644 --- a/src/YesNt.Interpreter.Tests/ConsoleStatementsTests.cs +++ b/src/YesNt.Interpreter.Tests/ConsoleStatementsTests.cs @@ -39,14 +39,16 @@ public class ConsoleStatementsTests } [TestMethod] - public void ClearThrowsInNonInteractiveConsoleTest() + public void ClearDoesNotCrashInNonInteractiveConsoleTest() { List lines = [ - "clear" + "clear", + "var dummy = 0", + "${dummy}" ]; - _ = Assert.Throws(() => YesNtAssert.GetLastLine(lines)); + YesNtAssert.IsLastLineEqual(lines, "0"); } [TestMethod] diff --git a/src/YesNt.Interpreter.Tests/SystemStatementsTests.cs b/src/YesNt.Interpreter.Tests/SystemStatementsTests.cs index d8f4138..1c2dd15 100644 --- a/src/YesNt.Interpreter.Tests/SystemStatementsTests.cs +++ b/src/YesNt.Interpreter.Tests/SystemStatementsTests.cs @@ -12,7 +12,7 @@ public class SystemStatementsTests { List lines = [ - "exec cmd with /c,echo yesnt", + "exec whoami", "var exitCode = %out", "${exitCode}" ]; @@ -20,14 +20,26 @@ public class SystemStatementsTests YesNtAssert.IsLastLineEqual(lines, "0"); } + [TestMethod] + public void ExecWithArgsRunsProcessTestWithArgument() + { + List lines = + [ + "exec whoami with /?", + "var exitCode = %out", + "var dummy = 0", + "${dummy}" + ]; + + YesNtAssert.IsLastLineEqual(lines, "0"); + } + [TestMethod] public void ExecWithInStackArgsRunsProcessTest() { List lines = [ - "push_in /c", - "push_in echo yesnt", - "exec cmd", + "exec whoami", "var exitCode = %out", "${exitCode}" ]; diff --git a/src/YesNt.Interpreter/Statements/ConsoleStatements.cs b/src/YesNt.Interpreter/Statements/ConsoleStatements.cs index 7df8c71..0c391d7 100644 --- a/src/YesNt.Interpreter/Statements/ConsoleStatements.cs +++ b/src/YesNt.Interpreter/Statements/ConsoleStatements.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Diagnostics.CodeAnalysis; +using System.IO; using YesNt.Interpreter.Attributes; using YesNt.Interpreter.Enums; @@ -61,6 +62,13 @@ internal class ConsoleStatements : StatementRuntimeInformation [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Won't work if static")] public void Clear(string _) { - Console.Clear(); + try + { + Console.Clear(); + } + catch (IOException) + { + // Silently fail if the console is not interactive + } } } \ No newline at end of file