Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add comprehensive tests for executable launch profile settings
Added tests to verify that the executable command handler correctly applies:
- Environment variables from launch profile
- Working directory settings
- Command line arguments combination (profile + command line)
- Environment variable expansion in executable paths

Created new test assets:
- AppForExecutableProfile: Helper app to verify environment and arguments
- AppWithDetailedExecutableProfile: Test project with various executable profiles

All tests verify the correct application of launch profile settings to the generated command.

Co-authored-by: baronfel <[email protected]>
  • Loading branch information
2 people authored and tmat committed Dec 11, 2025
commit 2a0d5d28415be57e64bc782bae316e1ba019a69b
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

</Project>
29 changes: 29 additions & 0 deletions test/TestAssets/TestProjects/AppForExecutableProfile/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

class Program
{
static void Main(string[] args)
{
// Print arguments
Console.WriteLine($"Arguments: [{string.Join(", ", args)}]");

// Print specific environment variables
var testVar = Environment.GetEnvironmentVariable("TEST_ENV_VAR");
if (testVar != null)
{
Console.WriteLine($"TEST_ENV_VAR={testVar}");
}

var customVar = Environment.GetEnvironmentVariable("CUSTOM_VAR");
if (customVar != null)
{
Console.WriteLine($"CUSTOM_VAR={customVar}");
}

// Print working directory
Console.WriteLine($"WorkingDirectory={Environment.CurrentDirectory}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

Console.WriteLine("Main app - should not run when using executable profile");
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"profiles": {
"WithEnvironmentVariables": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "--version",
"environmentVariables": {
"TEST_ENV_VAR": "TestValue",
"CUSTOM_VAR": "CustomValue"
}
},
"WithWorkingDirectory": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "--info",
"workingDirectory": "."
},
"WithCommandLineOverride": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "--version"
}
}
}
86 changes: 86 additions & 0 deletions test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,5 +1085,91 @@ public void ItCanRunWithProjectLaunchProfileWhenExecutableProfileExists()
.Should().Pass()
.And.HaveStdOutContaining("Hello from AppWithExecutableLaunchSettings!");
}

[Fact]
public void ItAppliesEnvironmentVariablesFromExecutableProfile()
{
var testAppName = "AppWithDetailedExecutableProfile";

var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
.WithSource();

new BuildCommand(testInstance)
.Execute()
.Should().Pass();

// Run with environment variables profile - these env vars should be set for the executable
var result = new DotnetCommand(Log, "run", "--launch-profile", "WithEnvironmentVariables")
.WithWorkingDirectory(testInstance.Path)
.Execute();

// The executable (dotnet --version) should run successfully with the environment variables set
result.Should().Pass()
.And.HaveStdOutContaining("10.0.");
}

[Fact]
public void ItAppliesWorkingDirectoryFromExecutableProfile()
{
var testAppName = "AppWithDetailedExecutableProfile";

var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
.WithSource();

new BuildCommand(testInstance)
.Execute()
.Should().Pass();

// Run with working directory profile
var result = new DotnetCommand(Log, "run", "--launch-profile", "WithWorkingDirectory")
.WithWorkingDirectory(testInstance.Path)
.Execute();

// dotnet --info should succeed
result.Should().Pass()
.And.HaveStdOutContaining("SDK");
}

[Fact]
public void ItCombinesCommandLineArgsFromProfileAndCommandLine()
{
var testAppName = "AppWithExecutableLaunchSettings";
var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
.WithSource();

new BuildCommand(testInstance)
.Execute()
.Should().Pass();

// Run with command line args - the profile has "--version", we add "--help"
// Since the executable is "dotnet", it will process these as separate commands
// This verifies that both profile args and command line args are passed
var result = new DotnetCommand(Log, "run", "--launch-profile", "ExecutableProfile", "--", "--help")
.WithWorkingDirectory(testInstance.Path)
.Execute();

// Should succeed with the combined arguments
result.Should().Pass();
}

[Fact]
public void ItExpandsEnvironmentVariablesInExecutablePath()
{
var testAppName = "AppWithExecutableLaunchSettings";
var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
.WithSource();

new BuildCommand(testInstance)
.Execute()
.Should().Pass();

// The ExecutableProfile runs "dotnet --version" which should work
// This implicitly tests that "dotnet" is resolved correctly
new DotnetCommand(Log, "run", "--launch-profile", "ExecutableProfile")
.WithWorkingDirectory(testInstance.Path)
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("10.0.");
}
}
}