Skip to content

Commit

Permalink
Cli dotnet framework (#357)
Browse files Browse the repository at this point in the history
- RC v4.8.12.0
---

## Changes

### CLI

- added option to run scripts under .NET Framework (`css -netfx <script>`)
- added option to run scripts as external process (`css -rx <script>`)
- extended verbose mode output

### CSScriptLib

- <no changes>
  • Loading branch information
oleg-shilo authored Dec 15, 2023
1 parent fd3f7b0 commit a8e87ab
Show file tree
Hide file tree
Showing 29 changed files with 1,127 additions and 405 deletions.
39 changes: 18 additions & 21 deletions .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,16 @@ jobs:
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Solution_Name: .\src\CS-Script.sln # Replace with your solution name, i.e. MyWpfApp.sln.WpfApp.Tests\MyWpfApp.Tests.csproj.approj.
Solution_Name: .\src\CS-Script.sln
CLI_Test_Proj_Name: .\src\Tests.cscs\Tests.CLI.csproj
CSScriptLib_Test_Proj_Name: .\src\Tests.CSScriptLib\Tests.CSScriptLib.csproj

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Init1
run: pwd
- name: Init2
run: ls

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v3
Expand All @@ -79,25 +76,25 @@ jobs:
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.0.2

# - name: Restore the application
# run: dotnet restore $env:Solution_Name
- name: Restore the application
run: dotnet restore $env:Solution_Name

- name: Build the solution
run: ./1.build-release.cmd
working-directory: src

- name: Test the solution
run: ./2.run-tests.cmd
working-directory: src

# - name: Build the solution
# run: dotnet build .\src\CS-Script.sln
# run: dotnet build $env:Solution_Name

# # Execute all unit tests in the solution
# - name: Execute unit tests
# run: dotnet test .\src\Tests.CSScriptLib\Tests.CSScriptLib.csproj
# - name: Execute CSScriptLib unit tests
# run: dotnet test $env:CSScriptLib_Test_Proj_Name

# # Execute all unit tests in the solution
# - name: Execute unit tests
# run: dotnet test .\src\Tests.cscs\Tests.CLI.csproj

# # Restore the application to populate the obj folder with RuntimeIdentifiers
# - name: Restore the application
# run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
# env:
# Configuration: ${{ matrix.configuration }}
# - name: Execute CLI unit tests
# run: dotnet test $env:CLI_Test_Proj_Name -e CI="true"

# # Build distributions
# - name: Build distros
Expand Down
343 changes: 135 additions & 208 deletions help.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/2.run-tests.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ echo off

.\out\Windows\css.exe -servers:stop
dotnet test ".\Tests.CSScriptLib\Tests.CSScriptLib.csproj"
dotnet test ".\Tests.cscs\Tests.CLI.csproj"
dotnet test ".\Tests.cscs\Tests.CLI.csproj" -e CI="true"
1 change: 1 addition & 0 deletions src/BuildServer/out/build.runtimeconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "8.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/CSScriptLib/src/CSScriptLib/CSScriptLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>4.8.11.0</Version>
<Version>4.8.12.0</Version>
<Authors>Oleg Shilo</Authors>
<Description>CS-Script engine Class Library for .NET 5 (and higher)</Description>
<Copyright>(C) 2018-2023 Oleg Shilo</Copyright>
Expand All @@ -30,14 +30,16 @@

### CLI

- Added using build-server on Linux. Now Win and Linux build-drver support is identical.
- added option to run scripts under .NET Framework (`css -netfx &lt;script&gt;`)
- added option to run scripts as external process (`css -rx &lt;script&gt;`)
- extended verbose mode output

### CSScriptLib

- &lt;no changes&gt;</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyVersion>4.8.11.0</AssemblyVersion>
<FileVersion>4.8.11.0</FileVersion>
<AssemblyVersion>4.8.12.0</AssemblyVersion>
<FileVersion>4.8.12.0</FileVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>css_logo.png</PackageIcon>
</PropertyGroup>
Expand Down
15 changes: 14 additions & 1 deletion src/CSScriptLib/src/CSScriptLib/Evaluator.Roslyn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,20 @@ public override IEvaluator ReferenceAssembly(Assembly assembly)
return instance;
}

public new T Eval<T>(string scriptText, CompileInfo info)
/// <summary>
/// Evals the specified script text.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="scriptText">The script text.</param>
/// <param name="info">The information.</param>
/// <returns></returns>
/// <exception cref="System.Exception">
/// This method is only available for Roslyn evaluator.
/// or
/// The parameter `{nameof(info)}.{nameof(info.CodeKind)}` must be set to `{nameof(SourceCodeKind.Script)}`.
/// </exception>
/// <exception cref="System.InvalidOperationException">Script entry point method could be found.</exception>
public T Eval<T>(string scriptText, CompileInfo info)
{
// triggered by #355: Error in Eval using a referenced assembly with unloading enabled.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.CodeAnalysis.Common.4.1.0\lib\netstandard2.0\Microsoft.CodeAnalysis.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
Expand Down
13 changes: 7 additions & 6 deletions src/Tests.CSScriptLib/Evaluator.Api.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public class Script
{{
public int Sum(int a, int b) => Calc.Sum(a ,b);
}}");
Assert.True(false, "Expected compile error was not detected");

Assert.Fail("Expected compile error was not detected");
}
catch (Exception e)
{
Expand Down Expand Up @@ -259,7 +260,7 @@ static public int Sum(int a, int b)
}
}");
new_evaluator.LoadFile(primaryScript);
Assert.True(false, "Expected compile error was not detected");
Assert.Fail("Expected compile error was not detected");
}
catch (Exception e)
{
Expand Down Expand Up @@ -289,7 +290,7 @@ public class Script
{{
public int Sum(int a, int b) => Calc.Sum(a ,b)
}}");
Assert.True(false, "Expected compile error was not detected");
Assert.Fail("Expected compile error was not detected");
}
catch (Exception e)
{
Expand All @@ -308,7 +309,7 @@ public class Script
public int Sum(int a, int b) => a = b
}}");

Assert.True(false, "Expected compile error was not detected");
Assert.Fail("Expected compile error was not detected");
}
catch (Exception e)
{
Expand All @@ -331,7 +332,7 @@ public int Sum(int a, int b) => a + b

new_evaluator.LoadFile(script);

Assert.True(false, "Expected compile error was not detected");
Assert.Fail("Expected compile error was not detected");
}
catch (Exception e)
{
Expand Down Expand Up @@ -363,7 +364,7 @@ static public int Sum(int a, int b)
}
}");
new_evaluator.LoadFile(primaryScript);
Assert.True(false, "Expected compile error was not detected");
Assert.Fail("Expected compile error was not detected");
}
catch (Exception e)
{
Expand Down
53 changes: 53 additions & 0 deletions src/Tests.cscs/CliAlgorithms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using CSScripting;
using Xunit;

namespace CLI
{
public class CliAlgorithms
{
string ToCode(string staticMain)
{
return @"
using System;
using System.Xml;
using WixSharp;
public class Script
{
$staticMain$
{
}
}
".Replace("$staticMain$", staticMain);
}

[Fact]
public void inject_asm_probing_in_void_main_with_args()
{
var processedCode = CSSUtils.InjectModuleInitializer(ToCode(
"static public void Main(string[] args)"), "HostingRuntime.Init();");

Assert.Contains("static void Main(string[] args) { HostingRuntime.Init(); impl_Main(args); } static public void impl_Main(string[] args)",
processedCode);
}

[Fact]
public void inject_asm_probing_in_nonvoid_main_with_args()
{
var processedCode = CSSUtils.InjectModuleInitializer(ToCode(
"static public int Main(string[] args)"), "HostingRuntime.Init();");
Assert.Contains("static int Main(string[] args) { HostingRuntime.Init(); return impl_Main(args); } static public int impl_Main(string[] args)",
processedCode);
}

[Fact]
public void inject_asm_probing_in_void_main_with_no_args()
{
var processedCode = CSSUtils.InjectModuleInitializer(ToCode(
"static public void Main()"), "HostingRuntime.Init();");

Assert.Contains("static void Main() { HostingRuntime.Init(); impl_Main(); } static public void impl_Main()",
processedCode);
}
}
}
1 change: 1 addition & 0 deletions src/Tests.cscs/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static string Run(this string exe, string args = null, string dir = null)
process.Start();

var output = process.StandardOutput.ReadToEnd();
output += process.StandardError.ReadToEnd();
process.WaitForExit();

return output;
Expand Down
Loading

0 comments on commit a8e87ab

Please sign in to comment.