Exemplo n.º 1
0
        public void Simple()
        {
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(@"

                <Project DefaultTargets=`a` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`a` >
	                    <CallTarget Targets=`b` />
                    </Target>
                    <Target Name=`b` >
	                    <Message Text=`Inside B` />
                    </Target>
                </Project>
                ");

            logger.AssertLogContains("Inside B");
        }
Exemplo n.º 2
0
        public void VerifyNoWarningForOrder()
        {
            // Create a project file that has an expression
            MockLogger ml = ObjectModelHelpers.BuildProjectExpectSuccess(@"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                        <Target Name=`Build`>
                            <Message Text=`expression 1 is true ` Condition=`$(a) == 1 and $(b) == 2 and $(c) == 3`/>
                        </Target>
                    </Project>
                ");

            // Make sure the log contains the correct strings.
            Assert.DoesNotContain("MSB4130:", ml.FullLog); // "No need to warn for this expression - (a) == 1 and $(b) == 2 and $(c) == 3."

            ml = ObjectModelHelpers.BuildProjectExpectSuccess(@"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                        <Target Name=`Build`>
                            <Message Text=`expression 1 is true ` Condition=`$(a) == 1 or $(b) == 2 or $(c) == 3`/>
                        </Target>
                    </Project>
                ");

            // Make sure the log contains the correct strings.
            Assert.DoesNotContain("MSB4130:", ml.FullLog); // "No need to warn for this expression - (a) == 1 or $(b) == 2 or $(c) == 3."

            ml = ObjectModelHelpers.BuildProjectExpectSuccess(@"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                        <Target Name=`Build`>
                            <Message Text=`expression 1 is true ` Condition=`($(a) == 1 and $(b) == 2) or $(c) == 3`/>
                        </Target>
                    </Project>
                ");

            // Make sure the log contains the correct strings.
            Assert.DoesNotContain("MSB4130:", ml.FullLog); // "No need to warn for this expression - ($(a) == 1 and $(b) == 2) or $(c) == 3."

            ml = ObjectModelHelpers.BuildProjectExpectSuccess(@"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                        <Target Name=`Build`>
                            <Message Text=`expression 1 is true ` Condition=`($(a) == 1 or $(b) == 2) and $(c) == 3`/>
                        </Target>
                    </Project>
                ");

            // Make sure the log contains the correct strings.
            Assert.DoesNotContain("MSB4130:", ml.FullLog); // "No need to warn for this expression - ($(a) == 1 or $(b) == 2) and $(c) == 3."
        }
Exemplo n.º 3
0
        public void Simple()
        {
            MockLogger log = ObjectModelHelpers.BuildProjectExpectSuccess(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>

                    <ItemGroup>
                        <AToB Include=`a;b`/>
                    </ItemGroup>

                    <Target Name=`Build`>
                        <CreateItem Include=`%(AToB.Identity)`>
                            <Output ItemName=`AToBBatched` TaskParameter=`Include`/>
                        </CreateItem>
                        <Message Text=`[AToBBatched: @(AToBBatched)]`/>
                    </Target>

                </Project>
                ");

            log.AssertLogContains("[AToBBatched: a;b]");
        }
Exemplo n.º 4
0
        public void CreateBlankProperty()
        {
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(@"

                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                        <PropertyGroup>
                            <NumberOfProcessors>Twenty</NumberOfProcessors>
                        </PropertyGroup>

                        <Target Name=`Build`>
                            <CreateProperty Value=``>
                                <Output PropertyName=`NumberOfProcessors` TaskParameter=`Value`/>
                            </CreateProperty>
                            <Message Text=`NumberOfProcessors='$(NumberOfProcessors)'`/>
                        </Target>
                    </Project>

                ");

            logger.AssertLogContains("NumberOfProcessors=''");
        }
Exemplo n.º 5
0
        public void ContinueOnErrorShouldConvertErrorsToWarnings()
        {
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(@"

                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>

                    <Target Name=`Build`>

                        <Copy SourceFiles=`RandomNonExistentSourceFile.123456789`
                              DestinationFiles=`foo`
                              ContinueOnError=`true` />

                    </Target>

                </Project>
        
                ");

            Assertion.AssertEquals("Expected zero errors", 0, logger.ErrorCount);
            Assertion.AssertEquals("Expected one warning", 1, logger.WarningCount);
        }
Exemplo n.º 6
0
        public void VerifyWarningForOrder()
        {
            // Create a project file that has an expression
            MockLogger ml = ObjectModelHelpers.BuildProjectExpectSuccess(String.Format(@"
                    <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>
                        <Target Name=`Build`>
                            <Message Text=`expression 1 is true ` Condition=`$(a) == 1 and $(b) == 2 or $(c) == 3`/>
                        </Target>
                    </Project>
                ", new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));

            // Make sure the log contains the correct strings.
            Assertion.Assert("Need to warn for this expression - (a) == 1 and $(b) == 2 or $(c) == 3.",
                             ml.FullLog.Contains("MSB4130:"));

            ml = ObjectModelHelpers.BuildProjectExpectSuccess(String.Format(@"
                    <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>
                        <Target Name=`Build`>
                            <Message Text=`expression 1 is true ` Condition=`$(a) == 1 or $(b) == 2 and $(c) == 3`/>
                        </Target>
                    </Project>
                ", new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));

            // Make sure the log contains the correct strings.
            Assertion.Assert("Need to warn for this expression - (a) == 1 or $(b) == 2 and $(c) == 3.",
                             ml.FullLog.Contains("MSB4130:"));

            ml = ObjectModelHelpers.BuildProjectExpectSuccess(String.Format(@"
                    <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>
                        <Target Name=`Build`>
                            <Message Text=`expression 1 is true ` Condition=`($(a) == 1 or $(b) == 2 and $(c) == 3) or $(d) == 4`/>
                        </Target>
                    </Project>
                ", new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));

            // Make sure the log contains the correct strings.
            Assertion.Assert("Need to warn for this expression - ($(a) == 1 or $(b) == 2 and $(c) == 3) or $(d) == 4.",
                             ml.FullLog.Contains("MSB4130:"));
        }
Exemplo n.º 7
0
        public void BinaryLoggerShouldNotThrowWhenMetadataCannotBeExpanded()
        {
            var binaryLogger = new BinaryLogger
            {
                Parameters = $"LogFile={_logFile}"
            };

            const string project = @"
<Project>
<ItemDefinitionGroup>
  <F>
   <MetadataFileName>a\b\%(Filename).c</MetadataFileName>
  </F>
 </ItemDefinitionGroup>
 <ItemGroup>
  <F Include=""-in &quot;x\y\z&quot;"" />
 </ItemGroup>
 <Target Name=""X"" />
</Project>";

            ObjectModelHelpers.BuildProjectExpectSuccess(project, binaryLogger);
        }
Exemplo n.º 8
0
        public void CaptureTargetOutputsRunningEachTargetSeparately()
        {
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(@"

                <Project DefaultTargets = `CallT` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
	                <Target Name = `a` Outputs = `a.txt`/>
	                <Target Name = `b` Outputs = `b.txt`/>
	                <Target Name = `c` Outputs = `c.txt`/>
	                <Target Name = `CallT`>
		                <CallTarget
			                Targets = `a;b;c`
			                RunEachTargetSeparately = `true`>
			                <Output TaskParameter= `TargetOutputs` ItemName = `TaskOut`/>
		                </CallTarget>
		                <Message Text = `CallTarget Outputs: @(TaskOut)`/>
	                </Target>
                </Project>
                ");

            // All three targets should have been run.
            logger.AssertLogContains("CallTarget Outputs: a.txt;b.txt;c.txt");
        }
Exemplo n.º 9
0
        public void CreatePropertyWithLiteralSemicolon()
        {
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(@"

                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                        <Target Name=`Build`>
                            <CreateProperty Value=`Clean%3BBuild`>
                                <Output PropertyName=`TargetsToRunLaterProperty` TaskParameter=`Value`/>
                            </CreateProperty>
                            <Message Text=`TargetsToRunLaterProperty = $(TargetsToRunLaterProperty)`/>
                            <CreateItem Include=`$(TargetsToRunLaterProperty)`>
                                <Output ItemName=`TargetsToRunLaterItem` TaskParameter=`Include`/>
                            </CreateItem>
                            <Message Text=`TargetsToRunLaterItem = @(TargetsToRunLaterItem,'----')`/>
                        </Target>
                    </Project>

                ");

            logger.AssertLogContains("TargetsToRunLaterProperty = Clean;Build");
            logger.AssertLogContains("TargetsToRunLaterItem = Clean;Build");
        }
Exemplo n.º 10
0
        public void ItemsPickUpItemDefinitionMetadata()
        {
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(@"
                <Project DefaultTargets=`t` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <ItemDefinitionGroup>
                        <ItemWithDefinition>
                            <SomeMetadata>foo</SomeMetadata>
                        </ItemWithDefinition>
                    </ItemDefinitionGroup>
                    
                    <ItemGroup>
                        <ItemWithDefinition Include=`foo.cs` />
                    </ItemGroup>

                    <Target Name=`t`>
                        <Message Text=`[%(ItemWithDefinition.SomeMetadata)]` />
                    </Target>
                </Project>
            ");

            logger.AssertLogContains("[foo]");
        }
Exemplo n.º 11
0
        public void TestBinaryLoggerRoundtrip()
        {
            var binaryLogger = new BinaryLogger();

            binaryLogger.Parameters = _logFile;

            var mockLogFromBuild = new MockLogger();

            // build and log into binary logger and mockLogger1
            ObjectModelHelpers.BuildProjectExpectSuccess(s_testProject, binaryLogger, mockLogFromBuild);

            var mockLogFromPlayback = new MockLogger();

            var binaryLogReader = new BinaryLogReplayEventSource();

            mockLogFromPlayback.Initialize(binaryLogReader);

            // read the binary log and replay into mockLogger2testassembly
            binaryLogReader.Replay(_logFile);

            // the binlog will have more information than recorded by the text log
            Assert.Contains(mockLogFromBuild.FullLog, mockLogFromPlayback.FullLog);
        }