Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,38 @@ public void InstallLocationFile_ReallyLongInstallPathIsParsedCorrectly()
}
}

[Fact]
[SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")]
public void InstallLocationFile_MissingFile()
{
var fixture = sharedTestState.PortableAppFixture.Copy();

var appExe = fixture.TestProject.AppExe;
string testArtifactsPath = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "missingInstallLocation"));
using (new TestArtifact(testArtifactsPath))
using (var testOnlyProductBehavior = TestOnlyProductBehavior.Enable(appExe))
{
Directory.CreateDirectory(testArtifactsPath);

string directory = Path.Combine(testArtifactsPath, "installLocationOverride");
Directory.CreateDirectory(directory);
string nonExistentLocationFile = Path.Combine(directory, "install_location");
string defaultInstallLocation = Path.Combine(testArtifactsPath, "defaultInstallLocation");

Command.Create(appExe)
.CaptureStdErr()
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.InstallLocationFilePath,
nonExistentLocationFile)
.EnvironmentVariable(
Constants.TestOnlyEnvironmentVariables.DefaultInstallPath,
defaultInstallLocation)
.DotNetRoot(null)
.Execute()
.Should().NotHaveStdErrContaining("The install_location file");
}
}

public class SharedTestState : IDisposable
{
public string BaseDirectory { get; }
Expand Down
10 changes: 9 additions & 1 deletion src/native/corehost/hostmisc/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,15 @@ bool pal::get_dotnet_self_registered_dir(pal::string_t* recv)
FILE* install_location_file = pal::file_open(install_location_file_path, "r");
if (install_location_file == nullptr)
{
trace::error(_X("The install_location file ['%s'] failed to open: %s."), install_location_file_path.c_str(), pal::strerror(errno));
if (errno == ENOENT)
{
trace::verbose(_X("The install_location file ['%s'] does not exist - skipping."), install_location_file_path.c_str());
}
else
{
trace::error(_X("The install_location file ['%s'] failed to open: %s."), install_location_file_path.c_str(), pal::strerror(errno));
}

return false;
}

Expand Down