Skip to content

Commit

Permalink
Fix option parsing (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz authored Oct 11, 2024
1 parent 943e5e0 commit 39d24c8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/Basic.CompilerLog.UnitTests/ExportUtilTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,43 @@ public void ExportUnixPaths()
Assert.Contains(args[1], lines);
}

[Fact]
public void ExportWithUnsafeOption()
{
RunDotNet("new console --name example --output .");

var projectFileContent = """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
""";
File.WriteAllText(Path.Combine(RootDirectory, "example.csproj"), projectFileContent, DefaultEncoding);

var codeContent = """
unsafe class C { }
""";
File.WriteAllText(Path.Combine(RootDirectory, "Code.cs"), codeContent, DefaultEncoding);

RunDotNet("build -bl -nr:false");

var binlog = Path.Combine(RootDirectory, "msbuild.binlog");
var complog = Path.Combine(RootDirectory, "msbuild.complog");
var result = CompilerLogUtil.TryConvertBinaryLog(binlog, complog);
Assert.True(result.Succeeded);

TestExport(
compilerLogFilePath: complog,
expectedCount: 1,
includeAnalyzers: false,
runBuild: true);
}

private void EmbedLineCore(string contentFilePath)
{
RunDotNet($"new console --name example --output .");
Expand Down
13 changes: 12 additions & 1 deletion src/Basic.CompilerLog.Util/ExportUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,18 @@ private static string MaybeQuoteArgument(string arg)

private static bool IsOption(ReadOnlySpan<char> str) => OptionsRegex.IsMatch(str);

private const string OptionRegexContent = @"^/[a-z0-9]+:";
/// <summary>
/// Options start with a slash, then contain a colon and continue with a path,
/// or end with +/- or nothing. Examples:
/// <list type="bullet">
/// <item><c>/ref:...</c></item>
/// <item><c>/unsafe+</c></item>
/// <item><c>/checked-</c></item>
/// <item><c>/noconfig</c></item>
/// </list>
/// </summary>
/* lang=regex */
private const string OptionRegexContent = @"^/[a-z0-9]+(:|[+-]?$)";

#if NET
[GeneratedRegex(OptionRegexContent, RegexOptions.IgnoreCase)]
Expand Down

0 comments on commit 39d24c8

Please sign in to comment.