Skip to content

Commit

Permalink
Fix inheritance of ReferenceAssemblies, OutputKind, and Documentation…
Browse files Browse the repository at this point in the history
…Mode
  • Loading branch information
sharwell committed Dec 23, 2020
1 parent bc230aa commit f20d80e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public EvaluatedProjectState(ProjectState state, ReferenceAssemblies defaultRefe
state.AssemblyName,
state.Language,
state.ReferenceAssemblies ?? defaultReferenceAssemblies,
state.OutputKind,
state.DocumentationMode,
state.OutputKind ?? OutputKind.DynamicallyLinkedLibrary,
state.DocumentationMode ?? DocumentationMode.Diagnose,
state.Sources.ToImmutableArray(),
state.AdditionalFiles.ToImmutableArray(),
state.AdditionalProjectReferences.ToImmutableArray(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ internal ProjectState(ProjectState sourceState)
/// </value>
public ReferenceAssemblies? ReferenceAssemblies { get; set; }

public OutputKind OutputKind { get; set; } = OutputKind.DynamicallyLinkedLibrary;
public OutputKind? OutputKind { get; set; }

public DocumentationMode DocumentationMode { get; set; } = DocumentationMode.Diagnose;
public DocumentationMode? DocumentationMode { get; set; }

/// <summary>
/// Gets the set of source files for analyzer or code fix testing. Files may be added to this list using one of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ Microsoft.CodeAnalysis.Testing.ProjectState.AdditionalFilesFactories.get -> Syst
Microsoft.CodeAnalysis.Testing.ProjectState.AdditionalProjectReferences.get -> System.Collections.Generic.List<string>
Microsoft.CodeAnalysis.Testing.ProjectState.AdditionalReferences.get -> Microsoft.CodeAnalysis.Testing.MetadataReferenceCollection
Microsoft.CodeAnalysis.Testing.ProjectState.AssemblyName.get -> string
Microsoft.CodeAnalysis.Testing.ProjectState.DocumentationMode.get -> Microsoft.CodeAnalysis.DocumentationMode
Microsoft.CodeAnalysis.Testing.ProjectState.DocumentationMode.get -> Microsoft.CodeAnalysis.DocumentationMode?
Microsoft.CodeAnalysis.Testing.ProjectState.DocumentationMode.set -> void
Microsoft.CodeAnalysis.Testing.ProjectState.Language.get -> string
Microsoft.CodeAnalysis.Testing.ProjectState.Name.get -> string
Microsoft.CodeAnalysis.Testing.ProjectState.OutputKind.get -> Microsoft.CodeAnalysis.OutputKind
Microsoft.CodeAnalysis.Testing.ProjectState.OutputKind.get -> Microsoft.CodeAnalysis.OutputKind?
Microsoft.CodeAnalysis.Testing.ProjectState.OutputKind.set -> void
Microsoft.CodeAnalysis.Testing.ProjectState.ProjectState(string name, string language, string defaultPrefix, string defaultExtension) -> void
Microsoft.CodeAnalysis.Testing.ProjectState.ReferenceAssemblies.get -> Microsoft.CodeAnalysis.Testing.ReferenceAssemblies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,17 @@ public SolutionState WithInheritedValuesApplied(SolutionState? baseState, Immuta
}

var result = new SolutionState(Name, Language, DefaultPrefix, DefaultExtension);

result.ReferenceAssemblies = ReferenceAssemblies;
result.OutputKind = OutputKind;
result.DocumentationMode = DocumentationMode;

if (inheritanceMode != StateInheritanceMode.Explicit && baseState != null)
{
result.ReferenceAssemblies ??= baseState.ReferenceAssemblies;
result.OutputKind ??= baseState.OutputKind;
result.DocumentationMode ??= baseState.DocumentationMode;

if (Sources.Count == 0)
{
result.Sources.AddRange(baseState.Sources);
Expand Down Expand Up @@ -261,6 +270,9 @@ public SolutionState WithProcessedMarkup(MarkupOptions markupOptions, Diagnostic
var result = new SolutionState(Name, Language, DefaultPrefix, DefaultExtension);
result.MarkupHandling = MarkupMode.None;
result.InheritanceMode = StateInheritanceMode.Explicit;
result.ReferenceAssemblies = ReferenceAssemblies;
result.OutputKind = OutputKind;
result.DocumentationMode = DocumentationMode;
result.Sources.AddRange(testSources);
result.AdditionalFiles.AddRange(additionalFiles);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,23 @@ class TestClass {
.AddPackages(ImmutableArray.Create(new PackageIdentity("Microsoft.CodeAnalysis", "3.3.1"))),
}.RunAsync();
}

#if !(NETCOREAPP1_1 || NET46)
[Fact]
public async Task TestTopLevelStatements()
{
await new CSharpTest
{
TestState =
{
OutputKind = OutputKind.ConsoleApplication,
Sources =
{
@"return 0;",
},
},
}.RunAsync();
}
#endif
}
}

0 comments on commit f20d80e

Please sign in to comment.