diff options
| author | JassJam <[email protected]> | 2026-02-23 12:28:50 +0000 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-03-14 00:08:40 +0800 |
| commit | 9946d1814f4af9ef67e5accd9404e0fc69290f6f (patch) | |
| tree | f669ea003ab4947aabb7732696aefa4e62f5793c | |
| parent | 95fa1f158a4044b9851ce6c0f4ff21f3427ce83e (diff) | |
feat: add initial test files
37 files changed, 325 insertions, 0 deletions
diff --git a/tests/projects/csharp/console/.gitignore b/tests/projects/csharp/console/.gitignore new file mode 100644 index 000000000..6b8d3af38 --- /dev/null +++ b/tests/projects/csharp/console/.gitignore @@ -0,0 +1,6 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ diff --git a/tests/projects/csharp/console/src/Program.cs b/tests/projects/csharp/console/src/Program.cs new file mode 100644 index 000000000..c7d5272d9 --- /dev/null +++ b/tests/projects/csharp/console/src/Program.cs @@ -0,0 +1,2 @@ +Console.WriteLine("hello xmake!"); + diff --git a/tests/projects/csharp/console/src/test.csproj b/tests/projects/csharp/console/src/test.csproj new file mode 100644 index 000000000..9dbab4973 --- /dev/null +++ b/tests/projects/csharp/console/src/test.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> +</Project> + diff --git a/tests/projects/csharp/console/test.lua b/tests/projects/csharp/console/test.lua new file mode 100644 index 000000000..5ab8adc69 --- /dev/null +++ b/tests/projects/csharp/console/test.lua @@ -0,0 +1,10 @@ +import("lib.detect.find_tool") + +function test_build(t) + local dotnet = find_tool("dotnet") + if dotnet then + t:build() + else + return t:skip("dotnet not found") + end +end diff --git a/tests/projects/csharp/console/xmake.lua b/tests/projects/csharp/console/xmake.lua new file mode 100644 index 000000000..25cd801f0 --- /dev/null +++ b/tests/projects/csharp/console/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("test") + set_kind("binary") + add_rules("csharp") + add_files("src/Program.cs", "src/test.csproj") diff --git a/tests/projects/csharp/console_with_runtime_json/.gitignore b/tests/projects/csharp/console_with_runtime_json/.gitignore new file mode 100644 index 000000000..53e577525 --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/.gitignore @@ -0,0 +1,7 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ + diff --git a/tests/projects/csharp/console_with_runtime_json/src/Program.cs b/tests/projects/csharp/console_with_runtime_json/src/Program.cs new file mode 100644 index 000000000..2c9b0783b --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/src/Program.cs @@ -0,0 +1,17 @@ +using System.Text.Json; + +var runtimeFile = Path.Combine(AppContext.BaseDirectory, "runtime.json"); +if (!File.Exists(runtimeFile)) +{ + Console.WriteLine("runtime.json missing"); + return; +} + +var json = File.ReadAllText(runtimeFile); +using var doc = JsonDocument.Parse(json); +var runtime = doc.RootElement.TryGetProperty("runtime", out var value) + ? value.GetString() + : "unknown"; + +Console.WriteLine($"runtime={runtime}"); + diff --git a/tests/projects/csharp/console_with_runtime_json/src/app.csproj b/tests/projects/csharp/console_with_runtime_json/src/app.csproj new file mode 100644 index 000000000..4e754bb15 --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/src/app.csproj @@ -0,0 +1,14 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + <ItemGroup> + <None Include="runtime.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + </ItemGroup> +</Project> + diff --git a/tests/projects/csharp/console_with_runtime_json/src/runtime.json b/tests/projects/csharp/console_with_runtime_json/src/runtime.json new file mode 100644 index 000000000..15bec810d --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/src/runtime.json @@ -0,0 +1,7 @@ +{ + "runtime": "xmake", + "featureFlags": { + "sample": true + } +} + diff --git a/tests/projects/csharp/console_with_runtime_json/test.lua b/tests/projects/csharp/console_with_runtime_json/test.lua new file mode 100644 index 000000000..5ab8adc69 --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/test.lua @@ -0,0 +1,10 @@ +import("lib.detect.find_tool") + +function test_build(t) + local dotnet = find_tool("dotnet") + if dotnet then + t:build() + else + return t:skip("dotnet not found") + end +end diff --git a/tests/projects/csharp/console_with_runtime_json/xmake.lua b/tests/projects/csharp/console_with_runtime_json/xmake.lua new file mode 100644 index 000000000..8d8539b26 --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("app") + set_kind("binary") + add_rules("csharp") + add_files("src/Program.cs", "src/app.csproj") diff --git a/tests/projects/csharp/exe_with_library/.gitignore b/tests/projects/csharp/exe_with_library/.gitignore new file mode 100644 index 000000000..6b8d3af38 --- /dev/null +++ b/tests/projects/csharp/exe_with_library/.gitignore @@ -0,0 +1,6 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ diff --git a/tests/projects/csharp/exe_with_library/src/app/Program.cs b/tests/projects/csharp/exe_with_library/src/app/Program.cs new file mode 100644 index 000000000..3cf7cb84a --- /dev/null +++ b/tests/projects/csharp/exe_with_library/src/app/Program.cs @@ -0,0 +1,4 @@ +using MyLib; + +Console.WriteLine(Greeter.Greet("xmake")); + diff --git a/tests/projects/csharp/exe_with_library/src/app/app.csproj b/tests/projects/csharp/exe_with_library/src/app/app.csproj new file mode 100644 index 000000000..e5e49a685 --- /dev/null +++ b/tests/projects/csharp/exe_with_library/src/app/app.csproj @@ -0,0 +1,12 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + <ItemGroup> + <ProjectReference Include="../lib/lib.csproj" /> + </ItemGroup> +</Project> + diff --git a/tests/projects/csharp/exe_with_library/src/lib/Greeter.cs b/tests/projects/csharp/exe_with_library/src/lib/Greeter.cs new file mode 100644 index 000000000..546dd4b6f --- /dev/null +++ b/tests/projects/csharp/exe_with_library/src/lib/Greeter.cs @@ -0,0 +1,10 @@ +namespace MyLib; + +public static class Greeter +{ + public static string Greet(string name) + { + return $"hello {name}!"; + } +} + diff --git a/tests/projects/csharp/exe_with_library/src/lib/lib.csproj b/tests/projects/csharp/exe_with_library/src/lib/lib.csproj new file mode 100644 index 000000000..30c56ecb5 --- /dev/null +++ b/tests/projects/csharp/exe_with_library/src/lib/lib.csproj @@ -0,0 +1,8 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> +</Project> + diff --git a/tests/projects/csharp/exe_with_library/test.lua b/tests/projects/csharp/exe_with_library/test.lua new file mode 100644 index 000000000..5ab8adc69 --- /dev/null +++ b/tests/projects/csharp/exe_with_library/test.lua @@ -0,0 +1,10 @@ +import("lib.detect.find_tool") + +function test_build(t) + local dotnet = find_tool("dotnet") + if dotnet then + t:build() + else + return t:skip("dotnet not found") + end +end diff --git a/tests/projects/csharp/exe_with_library/xmake.lua b/tests/projects/csharp/exe_with_library/xmake.lua new file mode 100644 index 000000000..063e051db --- /dev/null +++ b/tests/projects/csharp/exe_with_library/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +target("mylib") + set_kind("shared") + add_rules("csharp") + add_files("src/lib/*.cs", "src/lib/lib.csproj") + +target("app") + set_kind("binary") + add_rules("csharp") + add_deps("mylib") + add_files("src/app/*.cs", "src/app/app.csproj") diff --git a/tests/projects/csharp/exe_with_package/.gitignore b/tests/projects/csharp/exe_with_package/.gitignore new file mode 100644 index 000000000..6b8d3af38 --- /dev/null +++ b/tests/projects/csharp/exe_with_package/.gitignore @@ -0,0 +1,6 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ diff --git a/tests/projects/csharp/exe_with_package/src/Program.cs b/tests/projects/csharp/exe_with_package/src/Program.cs new file mode 100644 index 000000000..518015e2a --- /dev/null +++ b/tests/projects/csharp/exe_with_package/src/Program.cs @@ -0,0 +1,4 @@ +using Humanizer; + +Console.WriteLine(1234.ToWords()); + diff --git a/tests/projects/csharp/exe_with_package/src/app.csproj b/tests/projects/csharp/exe_with_package/src/app.csproj new file mode 100644 index 000000000..0521e2a0c --- /dev/null +++ b/tests/projects/csharp/exe_with_package/src/app.csproj @@ -0,0 +1,12 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + <ItemGroup> + <PackageReference Include="Humanizer.Core" Version="2.14.1" /> + </ItemGroup> +</Project> + diff --git a/tests/projects/csharp/exe_with_package/test.lua b/tests/projects/csharp/exe_with_package/test.lua new file mode 100644 index 000000000..5ab8adc69 --- /dev/null +++ b/tests/projects/csharp/exe_with_package/test.lua @@ -0,0 +1,10 @@ +import("lib.detect.find_tool") + +function test_build(t) + local dotnet = find_tool("dotnet") + if dotnet then + t:build() + else + return t:skip("dotnet not found") + end +end diff --git a/tests/projects/csharp/exe_with_package/xmake.lua b/tests/projects/csharp/exe_with_package/xmake.lua new file mode 100644 index 000000000..8d8539b26 --- /dev/null +++ b/tests/projects/csharp/exe_with_package/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("app") + set_kind("binary") + add_rules("csharp") + add_files("src/Program.cs", "src/app.csproj") diff --git a/tests/projects/csharp/multiple_library/.gitignore b/tests/projects/csharp/multiple_library/.gitignore new file mode 100644 index 000000000..6b8d3af38 --- /dev/null +++ b/tests/projects/csharp/multiple_library/.gitignore @@ -0,0 +1,6 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ diff --git a/tests/projects/csharp/multiple_library/src/libalpha/Alpha.cs b/tests/projects/csharp/multiple_library/src/libalpha/Alpha.cs new file mode 100644 index 000000000..f203d9c9e --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/libalpha/Alpha.cs @@ -0,0 +1,10 @@ +namespace LibAlpha; + +public static class Alpha +{ + public static string Message() + { + return "alpha"; + } +} + diff --git a/tests/projects/csharp/multiple_library/src/libalpha/libalpha.csproj b/tests/projects/csharp/multiple_library/src/libalpha/libalpha.csproj new file mode 100644 index 000000000..30c56ecb5 --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/libalpha/libalpha.csproj @@ -0,0 +1,8 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> +</Project> + diff --git a/tests/projects/csharp/multiple_library/src/libbeta/Beta.cs b/tests/projects/csharp/multiple_library/src/libbeta/Beta.cs new file mode 100644 index 000000000..5e431039f --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/libbeta/Beta.cs @@ -0,0 +1,12 @@ +using LibAlpha; + +namespace LibBeta; + +public static class Beta +{ + public static string Message() + { + return Alpha.Message() + "+beta"; + } +} + diff --git a/tests/projects/csharp/multiple_library/src/libbeta/libbeta.csproj b/tests/projects/csharp/multiple_library/src/libbeta/libbeta.csproj new file mode 100644 index 000000000..15502d321 --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/libbeta/libbeta.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + <ItemGroup> + <ProjectReference Include="../libalpha/libalpha.csproj" /> + </ItemGroup> +</Project> + diff --git a/tests/projects/csharp/multiple_library/src/sample/Program.cs b/tests/projects/csharp/multiple_library/src/sample/Program.cs new file mode 100644 index 000000000..2292a8af9 --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/sample/Program.cs @@ -0,0 +1,3 @@ +using LibBeta; + +Console.WriteLine(Beta.Message());
\ No newline at end of file diff --git a/tests/projects/csharp/multiple_library/src/sample/sample.csproj b/tests/projects/csharp/multiple_library/src/sample/sample.csproj new file mode 100644 index 000000000..459440d0e --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/sample/sample.csproj @@ -0,0 +1,14 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="../libbeta/libbeta.csproj" /> + </ItemGroup> + +</Project> diff --git a/tests/projects/csharp/multiple_library/test.lua b/tests/projects/csharp/multiple_library/test.lua new file mode 100644 index 000000000..5ab8adc69 --- /dev/null +++ b/tests/projects/csharp/multiple_library/test.lua @@ -0,0 +1,10 @@ +import("lib.detect.find_tool") + +function test_build(t) + local dotnet = find_tool("dotnet") + if dotnet then + t:build() + else + return t:skip("dotnet not found") + end +end diff --git a/tests/projects/csharp/multiple_library/xmake.lua b/tests/projects/csharp/multiple_library/xmake.lua new file mode 100644 index 000000000..b4be98c99 --- /dev/null +++ b/tests/projects/csharp/multiple_library/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.debug", "mode.release") + +target("libalpha") + set_kind("shared") + add_rules("csharp") + add_files("src/libalpha/*.cs", "src/libalpha/libalpha.csproj") + +target("libbeta") + set_kind("shared") + add_rules("csharp") + add_deps("libalpha") + add_files("src/libbeta/*.cs", "src/libbeta/libbeta.csproj") + +target("sample") + set_kind("binary") + add_rules("csharp") + add_deps("libbeta") + add_files("src/sample/*.cs", "src/sample/sample.csproj") diff --git a/tests/projects/csharp/web_project/.gitignore b/tests/projects/csharp/web_project/.gitignore new file mode 100644 index 000000000..53e577525 --- /dev/null +++ b/tests/projects/csharp/web_project/.gitignore @@ -0,0 +1,7 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ + diff --git a/tests/projects/csharp/web_project/src/Program.cs b/tests/projects/csharp/web_project/src/Program.cs new file mode 100644 index 000000000..7e432aaf0 --- /dev/null +++ b/tests/projects/csharp/web_project/src/Program.cs @@ -0,0 +1,8 @@ +var builder = WebApplication.CreateBuilder(args); +var app = builder.Build(); + +app.MapGet("/", () => "hello web xmake!"); +app.MapGet("/health", () => Results.Ok(new { status = "ok" })); + +app.Run(); + diff --git a/tests/projects/csharp/web_project/src/webapp.csproj b/tests/projects/csharp/web_project/src/webapp.csproj new file mode 100644 index 000000000..4715481ee --- /dev/null +++ b/tests/projects/csharp/web_project/src/webapp.csproj @@ -0,0 +1,8 @@ +<Project Sdk="Microsoft.NET.Sdk.Web"> + <PropertyGroup> + <TargetFramework>net8.0</TargetFramework> + <Nullable>enable</Nullable> + <ImplicitUsings>enable</ImplicitUsings> + </PropertyGroup> +</Project> + diff --git a/tests/projects/csharp/web_project/test.lua b/tests/projects/csharp/web_project/test.lua new file mode 100644 index 000000000..5ab8adc69 --- /dev/null +++ b/tests/projects/csharp/web_project/test.lua @@ -0,0 +1,10 @@ +import("lib.detect.find_tool") + +function test_build(t) + local dotnet = find_tool("dotnet") + if dotnet then + t:build() + else + return t:skip("dotnet not found") + end +end diff --git a/tests/projects/csharp/web_project/xmake.lua b/tests/projects/csharp/web_project/xmake.lua new file mode 100644 index 000000000..d1e5504c3 --- /dev/null +++ b/tests/projects/csharp/web_project/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("webapp") + set_kind("binary") + add_rules("csharp") + add_files("src/Program.cs", "src/webapp.csproj") |
