예제 #1
0
        public void DebugType()
        {
            var csc = new Csc();

            csc.Sources   = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType = "full";
            Assert.Equal("/debug:full /out:test.exe test.cs", csc.GenerateResponseFileContents());

            csc           = new Csc();
            csc.Sources   = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType = "pdbonly";
            Assert.Equal("/debug:pdbonly /out:test.exe test.cs", csc.GenerateResponseFileContents());

            csc           = new Csc();
            csc.Sources   = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType = "portable";
            Assert.Equal("/debug:portable /out:test.exe test.cs", csc.GenerateResponseFileContents());

            csc           = new Csc();
            csc.Sources   = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType = "embedded";
            Assert.Equal("/debug:embedded /out:test.exe test.cs", csc.GenerateResponseFileContents());

            csc           = new Csc();
            csc.Sources   = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType = null;
            Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());

            csc           = new Csc();
            csc.Sources   = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType = "";
            Assert.Equal("/debug: /out:test.exe test.cs", csc.GenerateResponseFileContents());
        }
예제 #2
0
        public void CloneTest()
        {
            var exp   = new Csc(new Number(1));
            var clone = exp.Clone();

            Assert.Equal(exp, clone);
        }
예제 #3
0
        public void CscArccsc()
        {
            var exp      = new Csc(new Arccsc(new Variable("x")));
            var expected = new Variable("x");

            SimpleTest(exp, expected);
        }
예제 #4
0
 public void TargetTypeBad()
 {
     var csc = new Csc();
     csc.TargetType = "bad";
     csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
     Assert.Equal("/out:test.exe /target:bad test.cs", csc.GenerateResponseFileContents());
 }
예제 #5
0
 public void TargetTypeDll()
 {
     var csc = new Csc();
     csc.TargetType = "library";
     csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
     Assert.Equal("/out:test.dll /target:library test.cs", csc.GenerateResponseFileContents());
 }
예제 #6
0
 public void RefOnly()
 {
     var csc = new Csc();
     csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
     csc.RefOnly = true;
     Assert.Equal("/out:test.exe /refonly test.cs", csc.GenerateResponseFileContents());
 }
예제 #7
0
 public void RefOut()
 {
     var csc = new Csc();
     csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
     csc.OutputRefAssembly = MSBuildUtil.CreateTaskItem("ref\\test.dll");
     Assert.Equal("/out:test.exe /refout:ref\\test.dll test.cs", csc.GenerateResponseFileContents());
 }
예제 #8
0
 public void OutputAssembly()
 {
     var csc = new Csc();
     csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
     csc.OutputAssembly = MSBuildUtil.CreateTaskItem("x.exe");
     Assert.Equal("/out:x.exe test.cs", csc.GenerateResponseFileContents());
 }
예제 #9
0
 public void LangVersionFlag()
 {
     var csc = new Csc();
     csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
     csc.LangVersion = "iso-1";
     Assert.Equal("/out:test.exe /langversion:iso-1 test.cs", csc.GenerateResponseFileContents());
 }
예제 #10
0
파일: CscTests.cs 프로젝트: nxoxn/EPPlus
        public void CscInCscdDoublesAsInputs()
        {
            var function = new Csc();

            var input1 = 20;
            var input2 = 100;
            var input3 = 1;
            var input4 = 1.0;
            var input5 = 1.5;
            var input6 = 1000;

            var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext);
            var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext);
            var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext);
            var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext);
            var result5 = function.Execute(FunctionsHelper.CreateArgs(input5), this.ParsingContext);
            var result6 = function.Execute(FunctionsHelper.CreateArgs(input6), this.ParsingContext);

            Assert.AreEqual(1.095355936, System.Math.Round(result1.ResultNumeric, 9));
            Assert.AreEqual(-1.974857531, System.Math.Round(result2.ResultNumeric, 9));
            Assert.AreEqual(1.188395106, System.Math.Round(result3.ResultNumeric, 9));
            Assert.AreEqual(1.188395106, System.Math.Round(result4.ResultNumeric, 9));
            Assert.AreEqual(1.002511304, System.Math.Round(result5.ResultNumeric, 9));
            Assert.AreEqual(1.209365997, System.Math.Round(result6.ResultNumeric, 9));
        }
예제 #11
0
        public void MultipleSourceFiles()
        {
            var csc = new Csc();

            csc.Sources = MSBuildUtil.CreateTaskItems("test1.cs", "test2.cs");
            Assert.Equal("/out:test1.exe test1.cs test2.cs", csc.GenerateResponseFileContents());
        }
예제 #12
0
        public void Embed()
        {
            var csc = new Csc();

            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType     = "portable";
            csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"test.cs", @"test.txt");
            Assert.Equal(@"/debug:portable /out:test.exe /embed:test.cs /embed:test.txt test.cs", csc.GenerateResponseFileContents());

            csc               = new Csc();
            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType     = "portable";
            csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"C:\x y\z.json");
            Assert.Equal(@"/debug:portable /out:test.exe /embed:""C:\x y\z.json"" test.cs", csc.GenerateResponseFileContents());

            csc               = new Csc();
            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType     = "portable";
            csc.EmbeddedFiles = null;
            Assert.Equal(@"/debug:portable /out:test.exe test.cs", csc.GenerateResponseFileContents());

            csc               = new Csc();
            csc.Sources       = MSBuildUtil.CreateTaskItems("test.cs");
            csc.DebugType     = "full";
            csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems();
            Assert.Equal(@"/debug:full /out:test.exe test.cs", csc.GenerateResponseFileContents());
        }
예제 #13
0
파일: CscTests.cs 프로젝트: nxoxn/EPPlus
        public void CscHandlesNormal12HourClockInputs()
        {
            var function = new Csc();

            var input1 = "00:00:00 AM";
            var input2 = "00:01:32 AM";
            var input3 = "12:00 PM";
            var input4 = "12:00 AM";
            var input5 = "1:00 PM";
            var input6 = "1:10:32 am";
            var input7 = "3:42:32 pm";

            var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext);
            var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext);
            var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext);
            var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext);
            var result5 = function.Execute(FunctionsHelper.CreateArgs(input5), this.ParsingContext);
            var result6 = function.Execute(FunctionsHelper.CreateArgs(input6), this.ParsingContext);
            var result7 = function.Execute(FunctionsHelper.CreateArgs(input7), this.ParsingContext);

            Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)result1.Result).Type);
            Assert.AreEqual(939.1306123, System.Math.Round(result2.ResultNumeric, 7));
            Assert.AreEqual(2.085829643, System.Math.Round(result3.ResultNumeric, 9));
            Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)result1.Result).Type);
            Assert.AreEqual(1.939620425, System.Math.Round(result5.ResultNumeric, 9));
            Assert.AreEqual(20.42404488, System.Math.Round(result6.ResultNumeric, 8));
            Assert.AreEqual(1.642597072, System.Math.Round(result7.ResultNumeric, 9));
        }
예제 #14
0
파일: CscTests.cs 프로젝트: nxoxn/EPPlus
        public void CscTestInputsWithDatesThatHaveSlashesInThem()
        {
            var function = new Csc();

            var input1 = "1/17/2011 2:00 am";
            var input2 = "17/01/2011 2:00 AM";
            var input3 = "17/Jan/2011 2:00 AM";
            var input4 = "17/January/2011 2:00 am";
            var input5 = "1/17/2011 2:00:00 am";
            var input6 = "17/01/2011 2:00:00 AM";
            var input7 = "17/Jan/2011 2:00:00 AM";
            var input8 = "17/January/2011 2:00:00 am";

            var result1 = function.Execute(FunctionsHelper.CreateArgs(input1), this.ParsingContext);
            var result2 = function.Execute(FunctionsHelper.CreateArgs(input2), this.ParsingContext);
            var result3 = function.Execute(FunctionsHelper.CreateArgs(input3), this.ParsingContext);
            var result4 = function.Execute(FunctionsHelper.CreateArgs(input4), this.ParsingContext);
            var result5 = function.Execute(FunctionsHelper.CreateArgs(input5), this.ParsingContext);
            var result6 = function.Execute(FunctionsHelper.CreateArgs(input6), this.ParsingContext);
            var result7 = function.Execute(FunctionsHelper.CreateArgs(input7), this.ParsingContext);
            var result8 = function.Execute(FunctionsHelper.CreateArgs(input8), this.ParsingContext);

            Assert.AreEqual(1.173980588, System.Math.Round(result1.ResultNumeric, 9));
            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result2.Result).Type);
            Assert.AreEqual(1.173980588, System.Math.Round(result3.ResultNumeric, 9));
            Assert.AreEqual(1.173980588, System.Math.Round(result4.ResultNumeric, 9));
            Assert.AreEqual(1.173980588, System.Math.Round(result5.ResultNumeric, 9));
            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result6.Result).Type);
            Assert.AreEqual(1.173980588, System.Math.Round(result7.ResultNumeric, 9));
            Assert.AreEqual(1.173980588, System.Math.Round(result8.ResultNumeric, 9));
        }
예제 #15
0
        public void DisableSdkPath()
        {
            var csc = new Csc();

            csc.DisableSdkPath = true;
            Assert.Equal(@"/nosdkpath", csc.GenerateResponseFileContents());
        }
예제 #16
0
        public void NullableReferenceTypes_Default_02()
        {
            var csc = new Csc();

            csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
            Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());
        }
예제 #17
0
        public void GetBoolWithDefault()
        {
            Csc t = new Csc();

            t.Bag["Key"] = true;

            Assert.AreEqual(true, t.GetBoolParameterWithDefault("Key", false));
        }
예제 #18
0
        public void ResourceAccessSanityCheck()
        {
            Csc        t      = new Csc();
            MockEngine engine = new MockEngine();

            t.BuildEngine = engine;
            t.Log.LogErrorFromResources("Beyond Good and Evil");
        }
예제 #19
0
        public void GetIntWithDefault()
        {
            Csc t = new Csc();

            t.Bag["Key"] = 5;

            Assert.AreEqual(5, t.GetIntParameterWithDefault("Key", 9));
        }
예제 #20
0
        private OptimizationLevel GetOpimizationLevel(BuildEnvironment environment, Csc csc)
        {
            var optimize = csc.Optimize;

            return(_expressionEngine.EvaluateCondition(optimize, environment)
                                ? OptimizationLevel.Release
                                : OptimizationLevel.Debug);
        }
예제 #21
0
        public void NullableReferenceTypes_Safeonlywarnings()
        {
            var csc = new Csc();

            csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
            csc.NullableContextOptions = "safeonlywarnings";
            Assert.Equal("/nullable:safeonlywarnings /out:test.exe test.cs", csc.GenerateResponseFileContents());
        }
예제 #22
0
        public void RuleSet_CommandLine()
        {
            Csc csc = new Csc();

            csc.CodeAnalysisRuleSet = "Bar.ruleset";

            CommandLine.ValidateHasParameter(csc, "/ruleset:Bar.ruleset");
        }
예제 #23
0
            public void Win32Icon()
            {
                Csc t = new Csc();

                t.Win32Icon = @"MyFile.ico /out:c:\windows\system32\notepad.exe";
                CommandLine.ValidateNoParameterStartsWith(t, "/out");
                CommandLine.ValidateHasParameter(t, @"/win32icon:MyFile.ico /out:c:\windows\system32\notepad.exe");
            }
예제 #24
0
        public void UnsafeBlocks()
        {
            Csc t = new Csc();

            t.AllowUnsafeBlocks = true;
            CommandLine.ValidateHasParameter(t, "/unsafe+");
            t.AllowUnsafeBlocks = false;
            CommandLine.ValidateHasParameter(t, "/unsafe-");
        }
예제 #25
0
        public void NonAliasedReference2()
        {
            Csc t = new Csc();

            TaskItem reference = new TaskItem("System.Xml.dll");

            t.References = new TaskItem[] { reference };
            CommandLine.ValidateHasParameter(t, "/reference:System.Xml.dll");
        }
예제 #26
0
        public void NullableReferenceTypes_NullableWins_Enable(string nullableContextOptions, string nullable)
        {
            var csc = new Csc();

            csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
            csc.NullableContextOptions = nullableContextOptions;
            csc.Nullable = nullable;
            Assert.Equal("/nullable:enable /out:test.exe test.cs", csc.GenerateResponseFileContents());
        }
예제 #27
0
        public void PreferredUILang()
        {
            Csc t = new Csc();

            CommandLine.ValidateNoParameterStartsWith(t, @"/preferreduilang:");

            t.PreferredUILang = "en-US";
            CommandLine.ValidateHasParameter(t, @"/preferreduilang:en-US");
        }
예제 #28
0
        public void ExecuteComplexNumberTest()
        {
            var complex = new Complex(3, 2);
            var exp     = new Csc(new ComplexNumber(complex));
            var result  = (Complex)exp.Execute();

            Assert.Equal(ComplexExtensions.Csc(complex), result);
            Assert.Equal(0.040300578856891527, result.Real, 15);
            Assert.Equal(0.27254866146294021, result.Imaginary, 15);
        }
예제 #29
0
        /// <summary>
        /// Analyzes the specified expression.
        /// </summary>
        /// <param name="exp">The expression.</param>
        /// <returns>
        /// The result of analysis.
        /// </returns>
        public override IExpression Analyze(Csc exp)
        {
            var unary = new UnaryMinus(exp.Argument.Clone().Analyze(this));
            var cot   = new Cot(exp.Argument.Clone());
            var csc   = new Csc(exp.Argument.Clone());
            var mul1  = new Mul(cot, csc);
            var mul2  = new Mul(unary, mul1);

            return(mul2);
        }
예제 #30
0
 public void FeaturesEmpty()
 {
     foreach (var cur in new[] { "", null })
     {
         var csc = new Csc();
         csc.Features = cur;
         csc.Sources  = MSBuildUtil.CreateTaskItems("test.cs");
         Assert.Equal("/out:test.exe test.cs", csc.GenerateResponseFileContents());
     }
 }
예제 #31
0
        public void FileTrackerDoNotRecordWriteAsRead()
        {
            Console.WriteLine("Test: FileTrackerDoNotRecordWriteAsRead");

            File.Delete("writenoread.read.1.tlog");
            File.Delete("writenoread.write.1.tlog");

            string testDirectory = Path.Combine(Directory.GetCurrentDirectory(), "FileTrackerDoNotRecordWriteAsRead");

            if (Directory.Exists(testDirectory))
            {
                ObjectModelHelpers.DeleteDirectory(testDirectory);
                Directory.Delete(testDirectory, true /* recursive delete */);
            }

            Directory.CreateDirectory(testDirectory);
            string codeFile = null;
            string writeFile = null;
            string outputFile = Path.Combine(testDirectory, "writenoread.exe");

            try
            {
                writeFile = Path.Combine(testDirectory, "test.out");
                codeFile = Path.Combine(testDirectory, "code.cs");
                string codeContent = @"
using System.IO; 
using System.Runtime.InteropServices;
class X 
{ 
    static void Main() 
    { 
        FileStream f = File.Open(@""" + writeFile + @""", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
        f.WriteByte(8);
        f.Close();
    }
}";

                File.WriteAllText(codeFile, codeContent);
                Csc csc = new Csc();
                csc.BuildEngine = new MockEngine();
                csc.Sources = new TaskItem[] { new TaskItem(codeFile) };
                csc.OutputAssembly = new TaskItem(outputFile);
                bool success = csc.Execute();

                Assert.True(success);

                string trackerPath = FileTracker.GetTrackerPath(ExecutableType.ManagedIL);
                string fileTrackerPath = FileTracker.GetFileTrackerPath(ExecutableType.ManagedIL);
                string commandArgs = "/d \"" + fileTrackerPath + "\" /o /c \"" + outputFile + "\"";

                int exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs);
                Console.WriteLine("");
                Assert.Equal(0, exit);
            }
            finally
            {
                // Doesn't delete the directory itself, but deletes its contents.  If you try to delete the directory, 
                // even after calling this method, it sometimes throws IO exceptions due to not recognizing that the 
                // contents have been deleted yet. 
                ObjectModelHelpers.DeleteDirectory(testDirectory);
            }

            if (writeFile != null)
            {
                FileTrackerTestHelper.AssertDidntFindStringInTLog("CreateFileW, Desired Access=0xc0000000, Creation Disposition=0x1:" + writeFile.ToUpperInvariant(), "writenoread.read.1.tlog");
                FileTrackerTestHelper.AssertFoundStringInTLog("CreateFileW, Desired Access=0xc0000000, Creation Disposition=0x1:" + writeFile.ToUpperInvariant(), "writenoread.write.1.tlog");
            }
            else
            {
                Assert.True(false, "The output file was never assigned or written to");
            }
        }
예제 #32
0
        public void FileTrackerFindStrInIncludeDuplicates()
        {
            Console.WriteLine("Test: FileTrackerFindStrInIncludeDuplicates");

            File.Delete("findstr.read.1.tlog");
            FileTrackerTestHelper.WriteAll("test.in", "foo");

            string codeFile = null;
            string outputFile = Path.Combine(Path.GetTempPath(), "readtwice.exe");
            File.Delete(outputFile);

            try
            {
                string inputPath = Path.GetFullPath("test.in");
                codeFile = FileUtilities.GetTemporaryFile();
                string codeContent = @"using System.IO; class X { static void Main() { File.ReadAllText(@""" + inputPath + @"""); File.ReadAllText(@""" + inputPath + @"""); }}";
                File.WriteAllText(codeFile, codeContent);
                Csc csc = new Csc();
                csc.BuildEngine = new MockEngine();
                csc.Sources = new TaskItem[] { new TaskItem(codeFile) };
                csc.OutputAssembly = new TaskItem(outputFile);
                csc.Execute();

                string trackerPath = FileTracker.GetTrackerPath(ExecutableType.ManagedIL);
                string fileTrackerPath = FileTracker.GetFileTrackerPath(ExecutableType.ManagedIL);
                string commandArgs = "/d \"" + fileTrackerPath + "\" /u /c \"" + outputFile + "\"";

                int exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs);
                Console.WriteLine("");
                Assert.Equal(0, exit);
            }
            finally
            {
                File.Delete(codeFile);
                File.Delete(outputFile);
            }

            FileTrackerTestHelper.AssertFoundStringInTLog(Path.GetFullPath("test.in").ToUpperInvariant(), "readtwice.read.1.tlog", 2);
        }
예제 #33
0
        public void FileTrackerExtendedDirectoryTracking()
        {
            Console.WriteLine("Test: FileTrackerExtendedDirectoryTracking");

            File.Delete("directoryattributes.read.1.tlog");
            File.Delete("directoryattributes.write.1.tlog");

            string codeFile = null;
            string outputFile = Path.Combine(Path.GetTempPath(), "directoryattributes.exe");
            string codeContent = @"
using System.IO;
using System.Runtime.InteropServices;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            File.GetAttributes(Directory.GetCurrentDirectory());
            GetFileAttributes(Directory.GetCurrentDirectory()); 
        }

        [DllImport(""Kernel32.dll"", SetLastError = true, CharSet = CharSet.Unicode)]
        private extern static uint GetFileAttributes(string FileName); 
    }
}";

            File.Delete(outputFile);

            try
            {
                codeFile = FileUtilities.GetTemporaryFile();
                File.WriteAllText(codeFile, codeContent);
                Csc csc = new Csc();
                csc.BuildEngine = new MockEngine();
                csc.Sources = new ITaskItem[] { new TaskItem(codeFile) };
                csc.OutputAssembly = new TaskItem(outputFile);
                csc.Execute();

                string trackerPath = FileTracker.GetTrackerPath(ExecutableType.ManagedIL);
                string fileTrackerPath = FileTracker.GetFileTrackerPath(ExecutableType.ManagedIL);
                string commandArgs = "/d \"" + fileTrackerPath + "\" /o /u /e /c \"" + outputFile + "\"";

                int exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs);
                Console.WriteLine("");
                Assert.Equal(0, exit);

                // Should track directories when '/e' is passed
                FileTrackerTestHelper.AssertFoundStringInTLog("GetFileAttributesExW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");
                FileTrackerTestHelper.AssertFoundStringInTLog("GetFileAttributesW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");

                File.Delete("directoryattributes.read.1.tlog");
                File.Delete("directoryattributes.write.1.tlog");

                commandArgs = "/d \"" + fileTrackerPath + "\" /o /u /a /c \"" + outputFile + "\"";

                exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs);
                Console.WriteLine("");
                Assert.Equal(0, exit);

                // With '/a', should *not* track GetFileAttributes on directories, even though we do so on files. 
                FileTrackerTestHelper.AssertDidntFindStringInTLog("GetFileAttributesExW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");
                FileTrackerTestHelper.AssertDidntFindStringInTLog("GetFileAttributesW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");

                File.Delete("directoryattributes.read.1.tlog");
                File.Delete("directoryattributes.write.1.tlog");

                commandArgs = "/d \"" + fileTrackerPath + "\" /o /u /c \"" + outputFile + "\"";

                exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs);
                Console.WriteLine("");
                Assert.Equal(0, exit);

                // With neither '/a' nor '/e', should not do any directory tracking whatsoever
                FileTrackerTestHelper.AssertDidntFindStringInTLog("GetFileAttributesExW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");
                FileTrackerTestHelper.AssertDidntFindStringInTLog("GetFileAttributesW:" + FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");

                File.Delete("directoryattributes.read.1.tlog");
                File.Delete("directoryattributes.write.1.tlog");

                commandArgs = "/d \"" + fileTrackerPath + "\" /u /e /c \"" + outputFile + "\"";

                exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs);
                Console.WriteLine("");
                Assert.Equal(0, exit);

                // Should track directories when '/e' is passed
                FileTrackerTestHelper.AssertFoundStringInTLog(FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");

                File.Delete("directoryattributes.read.1.tlog");
                File.Delete("directoryattributes.write.1.tlog");

                commandArgs = "/d \"" + fileTrackerPath + "\" /u /a /c \"" + outputFile + "\"";

                exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs);
                Console.WriteLine("");
                Assert.Equal(0, exit);

                // With '/a', should *not* track GetFileAttributes on directories, even though we do so on files. 
                FileTrackerTestHelper.AssertDidntFindStringInTLog(FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");

                File.Delete("directoryattributes.read.1.tlog");
                File.Delete("directoryattributes.write.1.tlog");

                commandArgs = "/d \"" + fileTrackerPath + "\" /u /c \"" + outputFile + "\"";

                exit = FileTrackerTestHelper.RunCommand(trackerPath, commandArgs);
                Console.WriteLine("");
                Assert.Equal(0, exit);

                // With neither '/a' nor '/e', should not do any directory tracking whatsoever
                FileTrackerTestHelper.AssertDidntFindStringInTLog(FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()).ToUpperInvariant(), "directoryattributes.read.1.tlog");
            }
            finally
            {
                File.Delete(codeFile);
                File.Delete(outputFile);
            }
        }
예제 #34
0
        // Ignore: Needs investigation
        public void LaunchMultipleOfSameTool_ToolLaunchesOthers()
        {
            string testDir = Path.Combine(Path.GetTempPath(), "LaunchMultipleOfSameTool_ToolLaunchesOthers");

            try
            {
                if (FileUtilities.DirectoryExistsNoThrow(testDir))
                {
                    FileUtilities.DeleteDirectoryNoThrow(testDir, true);
                }

                Directory.CreateDirectory(testDir);

                // File to run findstr against. 
                string tempFilePath = Path.Combine(testDir, "bar.txt");
                File.WriteAllText(tempFilePath, "");

                // Sample app that runs findstr.
                string codeFile = null;
                string outputFile = Path.Combine(testDir, "FindstrLauncher.exe");
                string codeContent = @"
using System;
using System.Diagnostics;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 1)
            {
                for (int i = 0; i < Int32.Parse(args[0]); i++)
                {
                    Process p = Process.Start(""findstr"", ""/i foo "" + args[1]);
                    p.WaitForExit();
                }
            }
        }
    }
}";

                File.Delete(outputFile);

                codeFile = Path.Combine(testDir, "Program.cs");
                File.WriteAllText(codeFile, codeContent);
                Csc csc = new Csc();
                csc.BuildEngine = new MockEngine();
                csc.Sources = new ITaskItem[] { new TaskItem(codeFile) };
                csc.OutputAssembly = new TaskItem(outputFile);
                csc.Platform = "x86";
                bool compileSucceeded = csc.Execute();

                Assert.True(compileSucceeded);

                // Item1: appname
                // Item2: command line
                // Item3: number of times to launch
                IList<Tuple<string, string, int>> toolsToLaunch = new List<Tuple<string, string, int>>();
                toolsToLaunch.Add(new Tuple<string, string, int>(outputFile, outputFile + " 3 " + tempFilePath, 3));

                // Item1: FileTracker context name
                // Item2: Tuple <string, string, int> as described above
                IList<Tuple<string, IList<Tuple<string, string, int>>>> contextSpecifications = new List<Tuple<string, IList<Tuple<string, string, int>>>>();
                contextSpecifications.Add(new Tuple<string, IList<Tuple<string, string, int>>>("ProcessLaunchTest", toolsToLaunch));
                contextSpecifications.Add(new Tuple<string, IList<Tuple<string, string, int>>>("ProcessLaunchTest2", toolsToLaunch));

                // Item1: tlog pattern
                // Item2: # times it's expected to appear
                IList<Tuple<string, int>> tlogPatterns = new List<Tuple<string, int>>();
                tlogPatterns.Add(new Tuple<string, int>("ProcessLaunchTest-FindstrLauncher-findstr*tlog", 3));
                tlogPatterns.Add(new Tuple<string, int>("ProcessLaunchTest-FindstrLauncher.*-findstr*tlog", 6));
                tlogPatterns.Add(new Tuple<string, int>("ProcessLaunchTest2-FindstrLauncher-findstr*tlog", 3));
                tlogPatterns.Add(new Tuple<string, int>("ProcessLaunchTest2-FindstrLauncher.*-findstr*tlog", 6));

                LaunchDuplicateToolsAndVerifyTlogExistsForEach(testDir, contextSpecifications, tlogPatterns, createTestDirectory: false);
            }
            finally
            {
                if (FileUtilities.DirectoryExistsNoThrow(testDir))
                {
                    FileUtilities.DeleteDirectoryNoThrow(testDir, true);
                }
            }
        }
예제 #35
0
        public void ExecuteCscBuildTaskWithServer()
        {
            var csc = new Csc();
            var srcFile = _tempDirectory.CreateFile(s_helloWorldSrcCs[0].Key).WriteAllText(s_helloWorldSrcCs[0].Value).Path;
            var exeFile = Path.Combine(_tempDirectory.Path, "hello.exe");

            var engine = new MockEngine();
            csc.BuildEngine = engine;
            csc.Sources = new[] { new Build.Utilities.TaskItem(srcFile) };
            csc.NoLogo = true;
            csc.OutputAssembly = new Build.Utilities.TaskItem(exeFile);
            csc.ToolPath = "";
            csc.ToolExe = "";
            csc.UseSharedCompilation = true;

            csc.Execute();

            Assert.Equal(0, csc.ExitCode);
            Assert.Equal(string.Empty, engine.Warnings);
            Assert.Equal(string.Empty, engine.Errors);

            Assert.True(File.Exists(exeFile));

            var result = ProcessUtilities.Run(exeFile, "");
            Assert.Equal(0, result.ExitCode);
            Assert.Equal("Hello, world.", result.Output.Trim());
        }