-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #680 from sharwell/more-projects
Fully support additional projects
- Loading branch information
Showing
40 changed files
with
881 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 93 additions & 55 deletions
148
src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...deAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/Model/EvaluatedProjectState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Microsoft.CodeAnalysis.Testing.Model | ||
{ | ||
/// <summary> | ||
/// Represents an evaluated <see cref="ProjectState"/>. | ||
/// </summary> | ||
public sealed class EvaluatedProjectState | ||
{ | ||
public EvaluatedProjectState(ProjectState state, ReferenceAssemblies defaultReferenceAssemblies) | ||
: this( | ||
state.Name, | ||
state.AssemblyName, | ||
state.Language, | ||
state.ReferenceAssemblies ?? defaultReferenceAssemblies, | ||
state.OutputKind ?? OutputKind.DynamicallyLinkedLibrary, | ||
state.DocumentationMode ?? DocumentationMode.Diagnose, | ||
state.Sources.ToImmutableArray(), | ||
state.AdditionalFiles.ToImmutableArray(), | ||
state.AdditionalProjectReferences.ToImmutableArray(), | ||
state.AdditionalReferences.ToImmutableArray()) | ||
{ | ||
} | ||
|
||
private EvaluatedProjectState( | ||
string name, | ||
string assemblyName, | ||
string language, | ||
ReferenceAssemblies referenceAssemblies, | ||
OutputKind outputKind, | ||
DocumentationMode documentationMode, | ||
ImmutableArray<(string filename, SourceText content)> sources, | ||
ImmutableArray<(string filename, SourceText content)> additionalFiles, | ||
ImmutableArray<string> additionalProjectReferences, | ||
ImmutableArray<MetadataReference> additionalReferences) | ||
{ | ||
Name = name; | ||
AssemblyName = assemblyName; | ||
Language = language; | ||
ReferenceAssemblies = referenceAssemblies; | ||
OutputKind = outputKind; | ||
DocumentationMode = documentationMode; | ||
Sources = sources; | ||
AdditionalFiles = additionalFiles; | ||
AdditionalProjectReferences = additionalProjectReferences; | ||
AdditionalReferences = additionalReferences; | ||
} | ||
|
||
public string Name { get; } | ||
|
||
public string AssemblyName { get; } | ||
|
||
public string Language { get; } | ||
|
||
public ReferenceAssemblies ReferenceAssemblies { get; } | ||
|
||
public OutputKind OutputKind { get; } | ||
|
||
public DocumentationMode DocumentationMode { get; } | ||
|
||
public ImmutableArray<(string filename, SourceText content)> Sources { get; } | ||
|
||
public ImmutableArray<(string filename, SourceText content)> AdditionalFiles { get; } | ||
|
||
public ImmutableArray<string> AdditionalProjectReferences { get; } | ||
|
||
public ImmutableArray<MetadataReference> AdditionalReferences { get; } | ||
|
||
public EvaluatedProjectState WithSources(ImmutableArray<(string filename, SourceText content)> sources) | ||
{ | ||
if (sources == Sources) | ||
{ | ||
return this; | ||
} | ||
|
||
return With(sources: sources); | ||
} | ||
|
||
private EvaluatedProjectState With( | ||
Optional<string> name = default, | ||
Optional<string> assemblyName = default, | ||
Optional<string> language = default, | ||
Optional<ReferenceAssemblies> referenceAssemblies = default, | ||
Optional<OutputKind> outputKind = default, | ||
Optional<DocumentationMode> documentationMode = default, | ||
Optional<ImmutableArray<(string filename, SourceText content)>> sources = default, | ||
Optional<ImmutableArray<(string filename, SourceText content)>> additionalFiles = default, | ||
Optional<ImmutableArray<string>> additionalProjectReferences = default, | ||
Optional<ImmutableArray<MetadataReference>> additionalReferences = default) | ||
{ | ||
return new EvaluatedProjectState( | ||
GetValueOrDefault(name, Name), | ||
GetValueOrDefault(assemblyName, AssemblyName), | ||
GetValueOrDefault(language, Language), | ||
GetValueOrDefault(referenceAssemblies, ReferenceAssemblies), | ||
GetValueOrDefault(outputKind, OutputKind), | ||
GetValueOrDefault(documentationMode, DocumentationMode), | ||
GetValueOrDefault(sources, Sources), | ||
GetValueOrDefault(additionalFiles, AdditionalFiles), | ||
GetValueOrDefault(additionalProjectReferences, AdditionalProjectReferences), | ||
GetValueOrDefault(additionalReferences, AdditionalReferences)); | ||
} | ||
|
||
private static T GetValueOrDefault<T>(Optional<T> optionalValue, T defaultValue) | ||
{ | ||
return optionalValue.HasValue ? optionalValue.Value : defaultValue; | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...crosoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/ProjectCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.CodeAnalysis.Testing | ||
{ | ||
public class ProjectCollection : Dictionary<string, ProjectState> | ||
{ | ||
private readonly string _defaultLanguage; | ||
private readonly string _defaultExtension; | ||
|
||
public ProjectCollection(string defaultLanguage, string defaultExtension) | ||
{ | ||
_defaultLanguage = defaultLanguage; | ||
_defaultExtension = defaultExtension; | ||
} | ||
|
||
public new ProjectState this[string projectName] | ||
{ | ||
get | ||
{ | ||
if (TryGetValue(projectName, out var project)) | ||
{ | ||
return project; | ||
} | ||
|
||
return this[projectName, _defaultLanguage]; | ||
} | ||
} | ||
|
||
public ProjectState this[string projectName, string language] | ||
{ | ||
get | ||
{ | ||
var project = this.GetOrAdd(projectName, () => new ProjectState(projectName, _defaultLanguage, $"/{projectName}/Test", _defaultExtension)); | ||
if (project.Language != language) | ||
{ | ||
throw new InvalidOperationException(); | ||
} | ||
|
||
return project; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.