Main() public static method

public static Main ( string args ) : void
args string
return void
        public void ValidTrxReturnsOK()
        {
            int expexted = 0;
            int actual   = MainClass.Main(new string[] { Path.Combine("trx", "sample.trx"), mTargetDir });

            Assert.AreEqual(expexted, actual);
        }
Exemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();
            MainClass systems = new MainClass();

            systems.Main();
        }
        public void MissingTrxReturnsError()
        {
            int expected = 1;
            int actual   = MainClass.Main(new string[] { "non-existing-trx-file.trx", mTargetDir });

            Assert.AreEqual(expected, actual, "Main did not return the correct error code on a missing TRX file.");
        }
        public void MissingArgumentsReturnError()
        {
            int expected = 1;
            int actual   = MainClass.Main(new string[0]);

            Assert.AreEqual(expected, actual, "Main did not return the correct error code when no arguments were passed.");
        }
Exemplo n.º 5
0
        protected string TestSolution(string input)
        {
            // Save the standard input and output for restoring later.
            var stdIn  = Console.In;
            var stdOut = Console.Out;

            // Redirect the output writing to a StringBuilder.
            var output           = new StringBuilder();
            var redirectedOutput = new StringWriter(output);

            Console.SetOut(redirectedOutput);

            // Redirect the input reading from the string.
            var redirectedInput = new StringReader(input);

            Console.SetIn(redirectedInput);

            // Call our program.
            MainClass.Main();

            // Restore input and output.
            Console.SetIn(stdIn);
            Console.SetOut(stdOut);

            // Return output
            return(output.ToString());
        }
Exemplo n.º 6
0
        public void MainRun()
        {
            MainClass mc = new MainClass();

            string[] args = new string[] { "hello.exe" };
            mc.Main(args);
        }
        public void InvalidTrxReturnsError()
        {
            int expexted = 1;

            int actual = MainClass.Main(new string[] { Path.Combine("trx", "InvalidFile.trx"), mTargetDir });

            Assert.AreEqual(expexted, actual);
        }
Exemplo n.º 8
0
 public void Kurze_Datei_letzte_Zeile_keine_16_Byte_lang()
 {
     using (var consoleOutput = new ConsoleOutput()) {
         MainClass.Main(new[] { "testdata\\kurze-datei.txt" });
         var ouput = consoleOutput.GetOuputLines();
         Assert.That(ouput[0], Is.EqualTo("0000: ef bb bf 31 32 33 34 35 -- 36 37 38 39 30 31 32 33   ???1234567890123"));
         Assert.That(ouput[1], Is.EqualTo("0010: 34 35 36 0d 0a 31 32 33 -- 34 35 36 0d 0a            456..123456.."));
     }
 }
Exemplo n.º 9
0
 public void Datei_wird_ausgegeben()
 {
     using (var consoleOutput = new ConsoleOutput()) {
         MainClass.Main(new[] { "testdata\\hexdump.pdb" });
         var ouput = consoleOutput.GetOuputLines();
         Assert.That(ouput[0], Is.EqualTo("0000: 4d 69 63 72 6f 73 6f 66 -- 74 20 43 2f 43 2b 2b 20   Microsoft C/C++ "));
         Assert.That(ouput[1], Is.EqualTo("0010: 4d 53 46 20 37 2e 30 30 -- 0d 0a 1a 44 53 00 00 00   MSF 7.00...DS..."));
         Assert.That(ouput[2], Is.EqualTo("0020: 00 02 00 00 02 00 00 00 -- 1b 00 00 00 80 00 00 00   ............?..."));
     }
 }
Exemplo n.º 10
0
        public async Task start()
        {
            File.WriteAllText("configuration.json", JSON, Encoding.UTF8);

            Task main = Task.Run(() => MainClass.Main(new string[0]));

            await Task.Delay(200);

            MainClass.stop();

            await main;
        }
Exemplo n.º 11
0
        public void IgnoreTest()
        {
            Assert.Fail("Expected this test case does not be executed.");
            MainClass.Main(new string[] { "" });
            IMotor dummy = new Mock <IMotor>().Object;

            dummy.Off();
            Assert.Throws <InvalidOperationException>(() =>
            {
                throw new InvalidOperationException();
            });
        }
Exemplo n.º 12
0
 public static int Main(string[] args)
 {
     using (MainClass mc = new MainClass())
     {
         try
         {
             return(mc.Main(args));
         }
         catch (Exception e)
         {
             Console.Error.WriteLine(e);
             return(-1);
         }
     }
 }
Exemplo n.º 13
0
        public void ExitsWithErrorWhenArgumentIsNotPresent()
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append("Usage: StyleCop.Baboon.exe [stylecop-settings-path] [path-to-analyze] [ignored-paths]");
            stringBuilder.Append(Environment.NewLine);
            var expectedMessage = stringBuilder.ToString();

            this.RedirectOutput();
            var result  = MainClass.Main(new string[] { "." });
            var message = this.ReadGeneratedOutput();

            Assert.AreEqual(1, result);
            Assert.AreEqual(expectedMessage, message);
        }
Exemplo n.º 14
0
        public void ExitsWithErrorWhenStyleCopSettingsSpecifiedPathDoesNotExist()
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("Given settings file does not exist. Exiting...");
            stringBuilder.Append(Environment.NewLine);
            var expectedMessage = stringBuilder.ToString();

            this.RedirectOutput();
            var result  = MainClass.Main(new string[] { "/foo/StyleCop.Settings", ".", "./obj" });
            var message = this.ReadGeneratedOutput();

            Assert.AreEqual(2, result);
            Assert.AreEqual(expectedMessage, message);
        }
Exemplo n.º 15
0
        void DoFullCirle(string file1, string file2)
        {
            var file1bak = file1 + ".bak";
            var sig      = file1 + ".sig";
            var delta    = file1 + ".delta";
            var revdelta = file1 + ".revdelta";

            File.Copy(file1, file1bak);
            Assert.AreEqual(0, MainClass.Main("sig", file1, sig));
            Assert.AreEqual(0, MainClass.Main("delta", file2, sig, delta));
            Assert.AreEqual(0, MainClass.Main("reversedelta", file1, delta, revdelta));
            Assert.AreEqual(0, MainClass.Main("patch", file1, delta));
            Assert.IsTrue(FilesAreSame(file1, file2));
            Assert.AreEqual(0, MainClass.Main("patch", file1, revdelta));
            Assert.IsTrue(FilesAreSame(file1, file1bak));
        }
Exemplo n.º 16
0
        public void ExitsWithErrorWhenSpecifiedPathToAnalyzeDoesNotExist()
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("Given path to analyze does not exist. Exiting...");
            stringBuilder.Append(Environment.NewLine);
            var expectedMessage = stringBuilder.ToString();

            this.RedirectOutput();
            var dir = Directory.GetCurrentDirectory();
            var styleCopSettingsPath = string.Format("{0}{1}", dir, "/../../../Settings.StyleCop");
            var result  = MainClass.Main(new string[] { styleCopSettingsPath, "/foo/bar", "./obj" });
            var message = this.ReadGeneratedOutput();

            Assert.AreEqual(3, result);
            Assert.AreEqual(expectedMessage, message);
        }
Exemplo n.º 17
0
        static void Main()
        {
            var scanner = new Scanner( @"Rules\Main.txt" );
            var parser = new Parser( scanner );

            parser.Parse();

            var mainClass = new MainClass();

            try
            {
                Console.WriteLine( mainClass.Main( new object[] { "Id", "Name" } ) );
            }
            catch (Exception e)
            {
                Console.WriteLine( e );
            }
            var code = new Generator().Generate( null, parser.ruleClassStatement, "test.rule" ).ToString();

            using (var stream = new StreamWriter( "../../GeneratedClass.cs" ))
            {
                stream.WriteLine( code );
            }
        }
Exemplo n.º 18
0
 static int Main(string[] args)
 {
     return(MainClass.Main(args));
 }
Exemplo n.º 19
0
        public int RunTest(string extraArguments, params string[] extraInputs)
        {
            // open the stack trace for this call
            StackTrace stackTrace = new StackTrace();
            string     testClass  = null;
            string     testName   = null;

            // save the name of the current method (RunTest)
            string currentMethodName = MethodInfo.GetCurrentMethod().Name;

            // loop from the previous frame up until we get a method name that is not the
            // same as the current method name
            for (int ndx = 1; ndx < stackTrace.FrameCount; ++ndx)
            {
                // get the frame
                StackFrame stackFrame = stackTrace.GetFrame(ndx);

                // we have different entry points with the same name -- we're interested
                // in the first one that ISN'T the same name as our method
                MethodBase methodBase = stackFrame.GetMethod();
                if (methodBase.Name != currentMethodName)
                {
                    // the calling method's name is the test name - we use this as-is for the output file name
                    // and we use any portion before an underscore as the input file
                    testName = methodBase.Name;
                    // get the method's class - we use this as the subfolder under input/output/expected
                    testClass = methodBase.DeclaringType.Name;
                    break;
                }
            }
            // we definitely should be able to find a function on the stack frame that
            // has a different name than this function, but just in case...
            Debug.Assert(testName != null && testClass != null, "Couldn't locate calling stack frame");

            // the output file is just the full test name
            string outputFile = testName;

            // the input file is the portion of the test name before the underscore (if any)
            string inputFile = testName.Split('_')[0];

            // we want to know if the analyze flag is specified in the arguments provided to us
            bool analyzeSpecified = false;

            // check if the test is for Razor-specific scenarios
            bool razorOutputEnabled = false;

            // create a list we will append all our arguments to
            LinkedList <string> args = new LinkedList <string>();

            if (!string.IsNullOrEmpty(extraArguments))
            {
                // split on spaces
                string[] options = extraArguments.Split(' ');
                // add each one to the args list
                foreach (string option in options)
                {
                    // ignore empty strings
                    if (option.Length > 0)
                    {
                        args.AddLast(option);
                        if (string.Compare(option, "-xml", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // the next option should be an xml file name, so we'll add an option
                            // that is the test name, the .xml suffix, and scope it to the input path.
                            // set the inputPath variable to this path so we know we are going to use it
                            // as the "input"

                            /*string inputPath = BuildFullPath(
                             *  m_inputFolder,
                             *  testClass,
                             *  inputFile,
                             *  ".xml",
                             *  true
                             *  );
                             * args.AddLast(inputPath);
                             * outputFiles = ReadXmlForOutputFiles(inputPath, testClass);*/
                            throw new NotImplementedException("NYI");
                        }
                        // the -r option can have a subpart, eg: -res:Strings, so only test to see if
                        // the first two characters of the current option are "-res"
                        else if (option.StartsWith("-res", StringComparison.OrdinalIgnoreCase))
                        {
                            // the next option is a resource file name, so we'll need to scope it to the input path
                            // FIRST we'll try to see if there's an existing compiled .RESOURCES file with the same
                            // name as the current test. eg: if test name is "foo_h", look for foo.resources
                            string resourcePath = BuildFullPath(
                                m_inputFolder,
                                testClass,
                                inputFile,
                                ".resources",
                                false
                                );
                            if (!File.Exists(resourcePath))
                            {
                                // if there's not .RESOURCES file, look for a .RESX file with the same
                                // name as the current test. eg: if test name is "foo_h", look for foo.resx
                                resourcePath = BuildFullPath(
                                    m_inputFolder,
                                    testClass,
                                    inputFile,
                                    ".resx",
                                    false
                                    );
                                if (!File.Exists(resourcePath))
                                {
                                    // doesn't exist!
                                    Assert.Fail(
                                        "Expected resource file does not exist for test '{0}' in folder {1}",
                                        inputFile,
                                        Path.Combine(m_inputFolder, testClass)
                                        );
                                }
                            }
                            args.AddLast(resourcePath);
                        }
                        else if (option.StartsWith("-analyze", StringComparison.OrdinalIgnoreCase))
                        {
                            // yes, we specified the analyze flag
                            analyzeSpecified = true;
                        }
                        else if (option.StartsWith("-razor-out", StringComparison.InvariantCultureIgnoreCase))
                        {
                            razorOutputEnabled = true;
                        }
                    }
                }
            }

            // compute the path to the output file
            string outputPath = GetCssPath(
                m_outputFolder,
                testClass,
                outputFile,
                false
                );

            // if it exists already, delete it
            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }

            // if we haven't already added the analyze flag, add it now
            if (!analyzeSpecified)
            {
                args.AddLast("-analyze");
            }

            if (razorOutputEnabled)
            {
                args.AddLast("-razor");
            }

            // add the output parameter
            args.AddLast("-out");
            args.AddLast(outputPath);

            Trace.WriteLine("INPUT FILE(S):");

            // get the input path
            string inputPath = GetCssPath(
                m_inputFolder,
                testClass,
                inputFile,
                true
                );

            // always input the input file
            args.AddLast(inputPath);
            TraceFileContents(inputPath);

            // if there are any extra input files, add them now
            if (extraInputs != null && extraInputs.Length > 0)
            {
                foreach (string extraInput in extraInputs)
                {
                    if (extraInput.Length > 0)
                    {
                        // get the full path
                        inputPath = GetCssPath(
                            m_inputFolder,
                            testClass,
                            extraInput,
                            true
                            );
                        // add it to the list
                        args.AddLast(inputPath);
                        TraceFileContents(inputPath);
                    }
                }
            }

            Trace.WriteLine(string.Empty);

            // create an array of strings the appropriate size
            string[] mainArguments = new string[args.Count];
            // copy the arguments to the array
            args.CopyTo(mainArguments, 0);

            StringBuilder sb = new StringBuilder();

            foreach (string arg in mainArguments)
            {
                sb.Append(' ');
                sb.Append(arg);
            }
            Trace.WriteLine(string.Empty);
            Trace.WriteLine("COMMAND LINE ARGUMENTS:");
            Trace.WriteLine(sb.ToString());

            // call the CSSCRUNCH main function
            Trace.WriteLine(string.Empty);
            Trace.WriteLine("CSSCRUNCH Debug:");
            int retValue = MainClass.Main(mainArguments);

            // after the run, the output file BETTER exist...
            if (File.Exists(outputPath))
            {
                // compute the path to the expected file
                string expectedPath = GetCssPath(
                    m_expectedFolder,
                    testClass,
                    outputFile,
                    true
                    );

                Trace.WriteLine(string.Empty);
                Trace.WriteLine("odd \"" + expectedPath + "\" \"" + outputPath + "\"");

                Trace.WriteLine(string.Empty);
                Trace.WriteLine("EXPECTED OUTPUT FILE:");
                // trace output contents
                TraceFileContents(expectedPath);

                Trace.WriteLine(string.Empty);
                Trace.WriteLine("ACTUAL OUTPUT FILE:");
                // trace output contents
                TraceFileContents(outputPath);

                // fail the test if the files do not match
                AssertCompareTextFiles(outputPath, expectedPath);
            }
            else
            {
                // no output file....
                Assert.Fail("Output file ({0}) does not exist.", outputPath);
            }

            return(retValue);
        }
Exemplo n.º 20
0
 public void ServiceStart()
 {
     MainClass.Main(new string[0]);
 }
Exemplo n.º 21
0
 private void run(params string[] args)
 {
     MainClass.Main(args);
 }
Exemplo n.º 22
0
        public void RunTest(bool inputExpected, string extraArguments, params string[] extraInputs)
        {
            // open the stack trace for this call
            StackTrace stackTrace = new StackTrace();
            string     testClass  = null;
            string     testName   = null;

            // save the name of the current method (RunTest)
            string currentMethodName = MethodInfo.GetCurrentMethod().Name;

            // loop from the previous frame up until we get a method name that is not the
            // same as the current method name
            for (int ndx = 1; ndx < stackTrace.FrameCount; ++ndx)
            {
                // get the frame
                StackFrame stackFrame = stackTrace.GetFrame(ndx);

                // we have different entry points with the same name -- we're interested
                // in the first one that ISN'T the same name as our method
                MethodBase methodBase = stackFrame.GetMethod();
                if (methodBase.Name != currentMethodName)
                {
                    // the calling method's name is the test name - we use this as-is for the output file name
                    // and we use any portion before an underscore as the input file
                    testName = methodBase.Name;
                    // get the method's class - we use this as the subfolder under input/output/expected
                    testClass = methodBase.DeclaringType.Name;
                    break;
                }
            }
            // we definitely should be able to find a function on the stack frame that
            // has a different name than this function, but just in case...
            Debug.Assert(testName != null && testClass != null, "Couldn't locate calling stack frame");

            // the output file is just the full test name
            string        outputFile     = testName;
            string        outputMapFile  = null;
            List <string> outputFiles    = null;
            List <string> outputMapFiles = null;

            // the input file is the portion of the test name before the underscore (if any)
            string inputFile  = testName.Split('_')[0];
            string inputPath  = null;
            int    inputCount = 0;

            // create a list we will append all our arguments to
            bool includeAnalysis     = true;
            bool specifiesRename     = false;
            LinkedList <string> args = new LinkedList <string>();

            if (!string.IsNullOrEmpty(extraArguments))
            {
                // split on spaces
                string[] options = extraArguments.Split(' ');

                // add each one to the args list
                for (int ndx = 0; ndx < options.Length; ++ndx)
                {
                    string option = options[ndx];

                    // ignore empty strings
                    if (option.Length > 0)
                    {
                        args.AddLast(option);
                        if (string.Compare(option, "-analyze", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // don't include it -- we already added it
                            includeAnalysis = false;
                        }
                        else if (string.Compare(option, "-xml", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // the next option should be an xml file name, so we'll add an option
                            // that is the test name, the .xml suffix, and scope it to the input path.
                            // set the inputPath variable to this path so we know we are going to use it
                            // as the "input"
                            inputPath = BuildFullPath(
                                InputFolder,
                                testClass,
                                inputFile,
                                ".xml",
                                true
                                );
                            args.AddLast(inputPath);
                            ++inputCount;

                            XmlOutputData outputData = ReadXmlForOutputFiles(inputPath, testClass);
                            outputFiles    = outputData.OutputFiles;
                            outputMapFiles = outputData.OutputMapFiles;

                            // generate the expected file names from the output file names, plus any test qualifiers
                        }
                        else if (string.Compare(option, "-rename", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // rename with no param parts (a colon and other stuff) means the next
                            // option should be an xml file name, so we'll add an option
                            // that is the file scoped to the input path.
                            string nextFile = options[++ndx];

                            string renamePath = BuildFullPath(
                                InputFolder,
                                testClass,
                                Path.GetFileNameWithoutExtension(nextFile),
                                Path.GetExtension(nextFile),
                                true);

                            // add that scoped path to the arguments
                            args.AddLast(renamePath);
                        }
                        // the -r option can have a subpart, eg: -res:Strings, so only test to see if
                        // the first two characters of the current option are "-res"
                        else if (option.StartsWith("-res", StringComparison.OrdinalIgnoreCase))
                        {
                            // the next option is a resource file name, so we'll need to scope it to the input path
                            // FIRST we'll try to see if there's an existing compiled .RESOURCES file with the same
                            // name as the current test. eg: if test name is "foo_h", look for foo.resources
                            string resourcePath = BuildFullPath(
                                InputFolder,
                                testClass,
                                inputFile,
                                ".resources",
                                false
                                );
                            if (!File.Exists(resourcePath))
                            {
                                // if there's not .RESOURCES file, look for a .RESX file with the same
                                // name as the current test. eg: if test name is "foo_h", look for foo.resx
                                resourcePath = BuildFullPath(
                                    InputFolder,
                                    testClass,
                                    inputFile,
                                    ".resx",
                                    false
                                    );
                                if (!File.Exists(resourcePath))
                                {
                                    // doesn't exist!
                                    Assert.Fail(
                                        "Expected resource file does not exist for test '{0}' in folder {1}",
                                        inputFile,
                                        Path.Combine(InputFolder, testClass)
                                        );
                                }
                            }
                            args.AddLast(resourcePath);
                        }
                        else if (option.StartsWith("-rename:", StringComparison.OrdinalIgnoreCase) &&
                                 option.IndexOf('=') < 0 && option.IndexOf("prop", StringComparison.OrdinalIgnoreCase) < 0)
                        {
                            specifiesRename = true;
                        }
                        else if (option.StartsWith("-map", StringComparison.OrdinalIgnoreCase))
                        {
                            outputMapFile = GetJsPath(
                                m_outputFolder,
                                testClass,
                                outputFile,
                                false
                                ) + ".map";

                            if (File.Exists(outputMapFile))
                            {
                                File.Delete(outputMapFile);
                            }

                            args.AddLast(outputMapFile);
                        }
                    }
                }
            }

            // if we haven't already specified analyze option
            if (includeAnalysis)
            {
                // add the -a option
                args.AddLast("-analyze");
            }
            // if we haven't already specified a renaming option, we will
            // use -rename:none so we don't have to always figure out what the hypercrunch
            // should be
            if (!specifiesRename)
            {
                args.AddLast("-rename:none");
            }

            string outputPath = null;

            // if we haven't already set an input path, then we want to calculate the input/output
            // paths automatically from the test name (normal case)
            if (inputPath == null)
            {
                // compute the path to the output file
                outputPath = GetJsPath(
                    m_outputFolder,
                    testClass,
                    outputFile,
                    false
                    );

                // if it exists already, delete it
                if (File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }

                // add the output parameter to the end
                args.AddLast("-out");
                args.AddLast(outputPath);

                Trace.WriteLine("INPUT FILE(S):");

                // calculate the input path
                inputPath = GetJsPath(
                    InputFolder,
                    testClass,
                    inputFile,
                    false
                    );

                // always add the input file to the command line
                args.AddLast(inputPath);
                if (File.Exists(inputPath))
                {
                    // but don't trace its contents unless it actually exists
                    ++inputCount;
                    TraceFileContents(inputPath);
                }
                else
                {
                    Trace.WriteLine("[input file does not exist]");
                }

                // if there are any extra input files, add them now
                if (extraInputs != null && extraInputs.Length > 0)
                {
                    foreach (string extraInput in extraInputs)
                    {
                        if (extraInput.Length > 0)
                        {
                            // get the full path
                            inputPath = GetJsPath(
                                InputFolder,
                                testClass,
                                extraInput,
                                true
                                );

                            // add it to the list
                            args.AddLast(inputPath);

                            // output the file contents
                            Trace.WriteLine(string.Empty);
                            TraceFileContents(inputPath);
                            ++inputCount;
                        }
                    }
                }
            }
            else
            {
                Trace.WriteLine("INPUT FILE:");
                TraceFileContents(inputPath);
            }

            // create an array of strings the appropriate size
            string[] mainArguments = new string[args.Count];
            // copy the arguments to the array
            args.CopyTo(mainArguments, 0);

            // show command-line args
            Trace.WriteLine(string.Empty);
            Trace.WriteLine("COMMAND-LINE SWITCHES:");
            foreach (string arg in mainArguments)
            {
                if (arg.IndexOf(' ') >= 0)
                {
                    // at least one space -- enclose the argument in quotes
                    Trace.Write('"');
                    Trace.Write(arg);
                    Trace.Write('"');
                }
                else
                {
                    // no spaces; don't need quotes
                    Trace.Write(arg);
                }
                Trace.Write(' ');
            }
            Trace.WriteLine(string.Empty);

            // call the NUglify main function
            Trace.WriteLine(string.Empty);
            Trace.WriteLine("AJAXMIN Debug Spew:");

            // call Main directly
            int retValue = MainClass.Main(mainArguments);

            Trace.Write("RETURN CODE: ");
            Trace.WriteLine(retValue);

            // after the run, if we had inputs and one output file...
            if (inputCount > 0 && !string.IsNullOrEmpty(outputPath))
            {
                // compute the path to the expected file
                string expectedPath = GetJsPath(
                    m_expectedFolder,
                    testClass,
                    outputFile,
                    false
                    );

                Trace.WriteLine(string.Empty);
                Trace.WriteLine("odd \"" + expectedPath + "\" \"" + outputPath + "\"");

                Trace.WriteLine(string.Empty);
                Trace.WriteLine("EXPECTED OUTPUT FILE:");
                if (File.Exists(expectedPath))
                {
                    // trace output contents
                    TraceFileContents(expectedPath);
                }
                else
                {
                    // no expected file means we expect the output to be empty
                    Trace.WriteLine("File doesn't exist -- expect output file to be empty");
                }

                // the output file BETTER exist (even if it's just empty)...
                if (File.Exists(outputPath))
                {
                    Trace.WriteLine(string.Empty);
                    Trace.WriteLine("ACTUAL OUTPUT FILE:");
                    // trace output contents
                    TraceFileContents(outputPath);

                    // fail the test if the files do not match
                    AssertCompareTextFiles(outputPath, expectedPath);
                    //Assert.IsTrue(retValue == 0, "Run didn't succeed. Return code: {0}", retValue);
                }
                else if (File.Exists(expectedPath))
                {
                    // no output file, but we did expect an output! That is a failure
                    Assert.Fail("Output file does not exist, but one was expected!");
                }
                else
                {
                    // input file(s) and output file, but can't find output
                    Assert.IsTrue(
                        retValue != 0,
                        "Run shouldn't succeed if no output is generated. Return code: {0}; output file: {1}",
                        retValue,
                        outputPath
                        );
                }

                if (outputMapFile != null)
                {
                    string expectedMapFile = this.BuildFullPath(
                        m_expectedFolder,
                        testClass,
                        Path.GetFileName(outputMapFile),
                        ".map",
                        true
                        );

                    this.CompareSymbolMapFiles(outputMapFile, expectedMapFile);
                }
            }
            else if (inputCount > 0)
            {
                if (outputFiles != null && outputFiles.Count > 0)
                {
                    // get the test suffix, if any
                    var testSuffix    = string.Empty;
                    var ndxUnderscore = testName.IndexOf('_');
                    if (ndxUnderscore > 0)
                    {
                        // we have one. Use it as a suffix for the expected file
                        testSuffix = testName.Substring(ndxUnderscore);
                    }

                    // for each one...
                    for (int ndx = 0; ndx < outputFiles.Count; ++ndx)
                    {
                        outputPath = outputFiles[ndx];

                        // compute the expected file path from the filename of the output path
                        // with any test extension added
                        string expectedPath = GetJsPath(
                            m_expectedFolder,
                            testClass,
                            Path.GetFileNameWithoutExtension(outputPath) + testSuffix + Path.GetExtension(outputPath),
                            false
                            );

                        // trace the expected file contents
                        Trace.WriteLine(string.Empty);
                        Trace.WriteLine(string.Format("EXPECTED OUTPUT FILE {0}:", ndx + 1));
                        if (File.Exists(expectedPath))
                        {
                            // trace output contents
                            TraceFileContents(expectedPath);
                        }
                        else
                        {
                            // no expected file means we expect the output to be empty
                            Trace.WriteLine("File doesn't exist -- expect output file to be empty");
                        }

                        // trace the output file contents
                        Trace.WriteLine(string.Empty);
                        Trace.WriteLine(string.Format("ACTUAL OUTPUT FILE {0}:", ndx + 1));
                        // trace output contents
                        if (File.Exists(outputPath))
                        {
                            TraceFileContents(outputPath);
                        }
                        else
                        {
                            Trace.WriteLine("Output file doesn't exist");
                        }

                        // fail the entire test if the files do not match
                        AssertCompareTextFiles(outputPath, expectedPath);
                    }
                }
                else
                {
                    // input file(s), but no output file
                    Assert.Fail("No output files");
                }

                if (outputMapFiles != null)
                {
                    for (int ndx = 0; ndx < outputMapFiles.Count; ++ndx)
                    {
                        outputMapFile = outputMapFiles[ndx];

                        string expectedMapFile = this.BuildFullPath(
                            m_expectedFolder,
                            testClass,
                            Path.GetFileNameWithoutExtension(outputMapFile),
                            ".xml",
                            true
                            );

                        this.CompareSymbolMapFiles(outputMapFile, expectedMapFile);
                    }
                }
            }
            else
            {
                // no input file(s)
                Trace.WriteLine("No input file(s).");

                // if we expected there to be input files, then we failed
                Assert.IsFalse(inputExpected, "Expected input files to exist");
                // and if we didn't expect the input files to exist, we better have failed
                Assert.IsTrue(retValue != 0, "Run shouldn't succeed if no input file(s). Return code: {0}", retValue);
            }
        }
Exemplo n.º 23
0
 public void ConsoleStart()
 {
     Console.SetIn(new StringReader("a"));
     MainClass.Main(new[] { "--console" });
 }