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 @@ -3190,9 +3190,7 @@ private static string ComposeExpectedProjectString(string expectedItem)
</Project>";
expectedItem = AdjustSpacesForItem(expectedItem);

expected = ObjectModelHelpers.CleanupFileContents(string.Format(expected, expectedItem));

return expected;
return ObjectModelHelpers.CleanupFileContents(string.Format(expected, expectedItem));
}

/// <summary>
Expand Down Expand Up @@ -3269,8 +3267,7 @@ private static string AdjustSpacesForItem(string expectedItem)
sb.Append(itemSpace + splits[splits.Length -1]);
}

expectedItem = sb.ToString();
return expectedItem;
return sb.ToString();
}
}
}
13 changes: 5 additions & 8 deletions src/Build.UnitTests/BackEnd/LoggingServicesLogMethod_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ public void LogFatalErrorNullException()
string helpKeyword;
string resourceName = "FatalTaskError";
string parameters = "TaskName";
string message = null;

string message;
GenerateMessageFromExceptionAndResource(null, resourceName, out errorCode, out helpKeyword, out message, parameters);
ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
service.LogFatalError(s_buildEventContext, null, fileInfo, resourceName, parameters);
Expand Down Expand Up @@ -347,8 +346,7 @@ public void LogFatalTaskError()
string helpKeyword;
string resourceName = "FatalTaskError";
string parameters = "TaskName";
string message = null;

string message;
GenerateMessageFromExceptionAndResource(exception, resourceName, out errorCode, out helpKeyword, out message, parameters);
ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
service.LogFatalTaskError(s_buildEventContext, exception, fileInfo, parameters);
Expand Down Expand Up @@ -1381,8 +1379,7 @@ private void TestTargetFinished(string targetName, string projectFile, string pr
/// <param name="projectFileOfTarget">ProjectFileOfTarget to test</param>
private void TestTargetStartedEvent(string targetName, string projectFile, string projectFileOfTarget)
{
string message = String.Empty;

string message;
if (String.Equals(projectFile, projectFileOfTarget, StringComparison.OrdinalIgnoreCase))
{
message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TargetStartedProjectEntry", targetName, projectFile);
Expand All @@ -1409,7 +1406,7 @@ private void TestTargetStartedEvent(string targetName, string projectFile, strin
private void TestTargetStartedWithParentTargetEvent(string targetName, string projectFile, string projectFileOfTarget)
{
string parentTargetName = "MyParentTarget";
string message = String.Empty;
string message;
if (String.Equals(projectFile, projectFileOfTarget, StringComparison.OrdinalIgnoreCase))
{
message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TargetStartedProjectDepends", targetName, projectFile, parentTargetName);
Expand All @@ -1435,7 +1432,7 @@ private void TestTargetStartedWithParentTargetEvent(string targetName, string pr
/// </summary>
private void LogProjectStartedTestHelper(string projectFile, string targetNames)
{
string message = string.Empty;
string message;
if (!String.IsNullOrEmpty(targetNames))
{
message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForTopLevelProjectWithTargetNames", Path.GetFileName(projectFile), targetNames);
Expand Down
3 changes: 1 addition & 2 deletions src/Build.UnitTests/BackEnd/RequestBuilder_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ private BuildRequestConfiguration CreateTestProject(int configId)
string projectFile = GetTestProjectFile(configId);
File.WriteAllText(projectFile, projectFileContents.Replace('`', '"'));

string defaultToolsVersion = null;
defaultToolsVersion = FrameworkLocationHelper.PathToDotNetFrameworkV20 == null
string defaultToolsVersion = FrameworkLocationHelper.PathToDotNetFrameworkV20 == null
? ObjectModelHelpers.MSBuildDefaultToolsVersion
: "2.0";

Expand Down
6 changes: 2 additions & 4 deletions src/Build.UnitTests/BackEnd/SdkResolverService_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,8 @@ public void AssertResolutionWarnsIfResolvedVersionIsDifferentFromReferencedVersi
var expectedPath2 = "Second/Path/To/Return/From/Resolver";

var sdk = new SdkReference("foo", "1.0", null);

Dictionary<string, string> propertiesToAdd = null;
Dictionary<string, SdkResultItem> itemsToAdd = null;

Dictionary<string, string> propertiesToAdd;
Dictionary<string, SdkResultItem> itemsToAdd;
CreateMockSdkResultPropertiesAndItems(out propertiesToAdd, out itemsToAdd);

var resolver = new SdkUtilities.ConfigurableMockSdkResolver(
Expand Down
2 changes: 1 addition & 1 deletion src/Build.UnitTests/BackEnd/TaskBuilder_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ private void TestSTATask(bool requireSTA, bool failTask, bool throwException)
MockLogger logger = new MockLogger();
logger.AllowTaskCrashes = throwException;

string taskAssemblyName = null;
string taskAssemblyName;
Project project = CreateSTATestProject(requireSTA, failTask, throwException, out taskAssemblyName);

List<ILogger> loggers = new List<ILogger>();
Expand Down
4 changes: 2 additions & 2 deletions src/Build.UnitTests/BackEnd/TaskHostTaskCancelled_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using Microsoft.Build.BackEnd;
using Xunit;
using Shouldly;

namespace Microsoft.Build.UnitTests.BackEnd
{
Expand Down Expand Up @@ -35,8 +36,7 @@ public void TestTranslation()

((ITranslatable)cancelled).Translate(TranslationHelpers.GetWriteTranslator());
INodePacket packet = TaskHostTaskCancelled.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

TaskHostTaskCancelled deserializedCancelled = packet as TaskHostTaskCancelled;
packet.ShouldBeOfType<TaskHostTaskCancelled>();
}
}
}
2 changes: 1 addition & 1 deletion src/Build.UnitTests/BackEnd/TaskRegistry_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ private void RetrieveAndValidateRegisteredTaskRecord
string expectedArchitecture
)
{
bool retrievedFromCache = false;
bool retrievedFromCache;
var record = registry.GetTaskRegistrationRecord(TestTaskName, null, taskParameters, exactMatchRequired, _targetLoggingContext, _elementLocation, out retrievedFromCache);

if (shouldBeRetrieved)
Expand Down
21 changes: 10 additions & 11 deletions src/Build.UnitTests/ConsoleLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,10 +1422,9 @@ private void WriteAndValidateProperties(BaseConsoleLogger cl, SimulatedConsole s
properties.Add("prop1", "val1");
properties.Add("prop2", "val2");
properties.Add("pro(p3)", "va%3b%253b%3bl3");
string prop1 = string.Empty;
string prop2 = string.Empty;
string prop3 = string.Empty;

string prop1;
string prop2;
string prop3;
if (cl is SerialConsoleLogger)
{
var propertyList = ((SerialConsoleLogger)cl).ExtractPropertyList(properties);
Expand Down Expand Up @@ -1624,7 +1623,7 @@ private void WriteEnvironment(BaseConsoleLogger cl, SimulatedConsole sc, bool ex
// Being careful not to make locale assumptions here, eg about sorting
foreach (KeyValuePair<string, string> kvp in _environment)
{
string message = String.Empty;
string message;
if (cl is ParallelConsoleLogger)
{
message = String.Format(CultureInfo.CurrentCulture, "{0} = {1}", kvp.Key, kvp.Value);
Expand Down Expand Up @@ -1665,12 +1664,12 @@ private void WriteAndValidateItems(BaseConsoleLogger cl, SimulatedConsole sc, bo

items.Add("type(3)", taskItem3);

string item1type = string.Empty;
string item2type = string.Empty;
string item3type = string.Empty;
string item1spec = string.Empty;
string item2spec = string.Empty;
string item3spec = string.Empty;
string item1type;
string item2type;
string item3type;
string item1spec;
string item2spec;
string item3spec;
string item3metadatum = string.Empty;

if (cl is SerialConsoleLogger)
Expand Down
4 changes: 1 addition & 3 deletions src/Build.UnitTests/Construction/ElementLocation_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,7 @@ private string GetLocations(string content, bool readOnly)
}
}

locations = locations.Replace(file, "c:\\foo\\bar.csproj");

return locations;
return locations.Replace(file, "c:\\foo\\bar.csproj");
}
finally
{
Expand Down
19 changes: 4 additions & 15 deletions src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,8 @@ public void AddNewErrorWarningMessageElement()
Project project = new Project(projectXml);

project.Build(logger);

string code = null;
string keyword = null;
string code;
string keyword;
string text = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out code, out keyword, "SolutionParseUnknownProjectType", "proj1.csproj");

// check the error event
Expand All @@ -215,9 +214,6 @@ public void AddNewErrorWarningMessageElement()
Assert.Equal(text, warning.Message);
Assert.Equal(code, warning.Code);
Assert.Equal(keyword, warning.HelpKeyword);

code = null;
keyword = null;
text = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out code, out keyword, "SolutionInvalidSolutionConfiguration");

// check the warning event
Expand All @@ -227,9 +223,6 @@ public void AddNewErrorWarningMessageElement()
Assert.Equal(text, error.Message);
Assert.Equal(code, error.Code);
Assert.Equal(keyword, error.HelpKeyword);

code = null;
keyword = null;
text = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out code, out keyword, "SolutionVenusProjectNoClean");

// check the message event
Expand Down Expand Up @@ -1317,16 +1310,14 @@ public void ToolsVersionOverrideCausesToolsetRedirect()
EndGlobalSection
EndGlobal
";

ProjectInstance[] instances = null;
SolutionFile solution = SolutionFile_Tests.ParseSolutionHelper(solutionFileContents);
bool caughtException = false;

try
{
// SolutionProjectGenerator.Generate() is used at build-time, and creates evaluation- and
// execution-model projects; as such it will throw if fed an explicitly invalid toolsversion
instances = SolutionProjectGenerator.Generate(solution, null, "invalid", _buildEventContext, CreateMockLoggingService());
ProjectInstance[] instances = SolutionProjectGenerator.Generate(solution, null, "invalid", _buildEventContext, CreateMockLoggingService());
}
catch (InvalidProjectFileException)
{
Expand Down Expand Up @@ -1730,9 +1721,7 @@ public void SolutionGeneratorEscapingProjectFilePaths()
EndGlobal
";

SolutionFile solution = null;

solution = SolutionFile_Tests.ParseSolutionHelper(solutionFileContents);
SolutionFile solution = SolutionFile_Tests.ParseSolutionHelper(solutionFileContents);

// Creating a ProjectRootElement shouldn't affect the ProjectCollection at all
Assert.Empty(ProjectCollection.GlobalProjectCollection.LoadedProjects);
Expand Down
9 changes: 3 additions & 6 deletions src/Build.UnitTests/Definition/ItemDefinitionGroup_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,12 @@ public void ItemDefinitionMetadataCopiedToTaskItem()
Assert.True(p.ItemDefinitions.ContainsKey("ItemA"));

ProjectInstance pi = p.CreateProjectInstance();
ITaskItem noMetaItem = null;
ITaskItem withMetaItem;

List<ProjectItemDefinitionInstance> itemdefs = new List<ProjectItemDefinitionInstance>();
itemdefs.Add(pi.ItemDefinitions["ItemA"]);

noMetaItem = new TaskItem("NoMetaItem", pi.FullPath);
ITaskItem noMetaItem = new TaskItem("NoMetaItem", pi.FullPath);
withMetaItem = new TaskItem("WithMetaItem", "WithMetaItem", null, itemdefs, ".", false, pi.FullPath);

// Copy the metadata on the item with no metadata onto the item with metadata
Expand Down Expand Up @@ -623,13 +622,12 @@ public void ItemDefinitionMetadataCopiedToTaskItem2()
Assert.True(p.ItemDefinitions.ContainsKey("ItemA"));

ProjectInstance pi = p.CreateProjectInstance();
ITaskItem noMetaItem = null;
ITaskItem withMetaItem;

List<ProjectItemDefinitionInstance> itemdefs = new List<ProjectItemDefinitionInstance>();
itemdefs.Add(pi.ItemDefinitions["ItemA"]);

noMetaItem = new TaskItem("NoMetaItem", pi.FullPath);
ITaskItem noMetaItem = new TaskItem("NoMetaItem", pi.FullPath);
noMetaItem.SetMetadata("MetaA", "NEWMETA_A");

withMetaItem = new TaskItem("WithMetaItem", "WithMetaItem", null, itemdefs, ".", false, pi.FullPath);
Expand Down Expand Up @@ -665,13 +663,12 @@ public void ItemDefinitionMetadataCopiedToTaskItem3()
Assert.True(p.ItemDefinitions.ContainsKey("ItemA"));

ProjectInstance pi = p.CreateProjectInstance();
ITaskItem noMetaItem = null;
ITaskItem withMetaItem = null;

List<ProjectItemDefinitionInstance> itemdefs = new List<ProjectItemDefinitionInstance>();
itemdefs.Add(pi.ItemDefinitions["ItemA"]);

noMetaItem = new TaskItem("NoMetaItem", pi.FullPath);
ITaskItem noMetaItem = new TaskItem("NoMetaItem", pi.FullPath);

// No the ideal way to get the first item, but there is no other way since GetItems returns an IEnumerable :(
foreach (ProjectItemInstance item in pi.GetItems("ItemA"))
Expand Down
16 changes: 4 additions & 12 deletions src/Build.UnitTests/Definition/ToolsVersion_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,8 @@ public void CustomToolsVersionIsHonored()
Toolset source = p.GetToolset("Current");
Toolset potato = new Toolset("potato", source.ToolsPath, ProjectCollection.GlobalProjectCollection, source.ToolsPath);
p.AddToolset(potato);

bool success = false;
Project project = p.LoadProject(projectPath, "potato");
success = project.Build(mockLogger);
bool success = project.Build(mockLogger);

Assert.True(success);
mockLogger.AssertLogContains("[potato]");
Expand All @@ -489,15 +487,13 @@ public void ToolsVersionFallbackIfCurrentToolsVersionDoesNotExist()
MockLogger mockLogger = new MockLogger();
LoggingService service = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
service.RegisterLogger(mockLogger);

bool success = false;
Project project = new Project(XmlReader.Create(new StringReader(@"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Foo'>
</Target>
</Project>")), null /* no global properties */, null /* don't explicitly set the toolsversion */, p);

Assert.Equal("4.0", project.ToolsVersion);
success = project.Build(mockLogger);
bool success = project.Build(mockLogger);

Assert.True(success);
mockLogger.AssertLogContains("\"4.0\"");
Expand Down Expand Up @@ -636,16 +632,14 @@ public void ToolsVersionFallbackIfCurrentToolsVersionDoesNotExist_CreateProjectI
MockLogger mockLogger = new MockLogger();
LoggingService service = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
service.RegisterLogger(mockLogger);

bool success = false;
Project project = new Project(XmlReader.Create(new StringReader(@"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Foo'>
</Target>
</Project>")), null /* no global properties */, null /* don't explicitly set the toolsversion */, p);

ProjectInstance pi = project.CreateProjectInstance();
Assert.Equal("4.0", pi.ToolsVersion);
success = pi.Build(new ILogger[] { mockLogger });
bool success = pi.Build(new ILogger[] { mockLogger });

Assert.True(success);
mockLogger.AssertLogContains("\"4.0\"");
Expand Down Expand Up @@ -790,16 +784,14 @@ public void ToolsVersionFallbackIfCurrentToolsVersionDoesNotExist_ProjectInstanc
MockLogger mockLogger = new MockLogger();
LoggingService service = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
service.RegisterLogger(mockLogger);

bool success = false;
Project project = new Project(XmlReader.Create(new StringReader(@"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Foo'>
</Target>
</Project>")), null /* no global properties */, null /* don't explicitly set the toolsversion */, p);

ProjectInstance pi = new ProjectInstance(project.Xml, null /* no global properties */, null /* don't explicitly set the toolsversion */, p);
Assert.Equal("4.0", pi.ToolsVersion);
success = pi.Build(new ILogger[] { mockLogger });
bool success = pi.Build(new ILogger[] { mockLogger });

Assert.True(success);
mockLogger.AssertLogContains("\"4.0\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,9 @@ public void ExtensionPathsTest_Basic1()

var reader = GetStandardConfigurationReader();
Dictionary<string, Toolset> toolsets = new Dictionary<string, Toolset>(StringComparer.OrdinalIgnoreCase);
string msbuildOverrideTasksPath = null;
string defaultOverrideToolsVersion = null;
reader.ReadToolsets(toolsets, new PropertyDictionary<ProjectPropertyInstance>(), new PropertyDictionary<ProjectPropertyInstance>(), true, out msbuildOverrideTasksPath, out defaultOverrideToolsVersion);
reader.ReadToolsets(toolsets, new PropertyDictionary<ProjectPropertyInstance>(),
new PropertyDictionary<ProjectPropertyInstance>(), true,
out string msbuildOverrideTasksPath, out string defaultOverrideToolsVersion);

Dictionary<string, ProjectImportPathMatch> pathsTable = toolsets["2.0"].ImportPropertySearchPathsTable;
if (NativeMethodsShared.IsWindows)
Expand Down
Loading