Пример #1
0
        private static bool?RunOneTest(TestCase test)
        {
            if (!File.Exists(test.InputFile) || !File.Exists(test.OutputFile))
            {
                Console.WriteLine("skipping (expected outcome not recorded).");
                return(null);
            }
            else
            {
                try
                {
                    using (Stream zcode = test.GetZCode())
                    {
                        ReplayIO io = new ReplayIO(test.InputFile);
                        ZMachine zm = new ZMachine(zcode, io);

                        zm.PredictableRandom       = true;
                        zm.ReadingCommandsFromFile = true;

                        string output         = RunAndCollectOutput(zm, io);
                        string expectedOutput = File.ReadAllText(test.OutputFile);

                        if (OutputDiffers(expectedOutput, output))
                        {
                            Console.WriteLine("failed!");
                            File.WriteAllText(test.FailureFile, output);
                            return(false);
                        }
                        else
                        {
                            Console.WriteLine("passed.");
                            return(true);
                        }
                    }
                }
                finally
                {
                    test.CleanUp();
                }
            }
        }
Пример #2
0
        private static bool? RunOneTest(TestCase test)
        {
            if (!File.Exists(test.InputFile) || !File.Exists(test.OutputFile))
            {
                Console.WriteLine("skipping (expected outcome not recorded).");
                return null;
            }
            else
            {
                try
                {
                    using (Stream zcode = test.GetZCode())
                    {
                        ReplayIO io = new ReplayIO(test.InputFile);
                        ZMachine zm = new ZMachine(zcode, io);

                        zm.PredictableRandom = true;
                        zm.ReadingCommandsFromFile = true;

                        string output = RunAndCollectOutput(zm, io);
                        string expectedOutput = File.ReadAllText(test.OutputFile);

                        if (OutputDiffers(expectedOutput, output))
                        {
                            Console.WriteLine("failed!");
                            File.WriteAllText(test.FailureFile, output);
                            return false;
                        }
                        else
                        {
                            Console.WriteLine("passed.");
                            return true;
                        }
                    }
                }
                finally
                {
                    test.CleanUp();
                }
            }
        }
Пример #3
0
        private static void RunAllTests()
        {
            List<string> names = new List<string>(testCases.Keys);
            names.Sort();

            if (names.Count == 0)
            {
                Console.WriteLine("No tests to run.");
            }
            else
            {
                int failures = 0;

                foreach (string name in names)
                {
                    TestCase test = testCases[name];

                    Console.Write("{0} - ", name);

                    if (!File.Exists(test.InputFile) || !File.Exists(test.OutputFile))
                    {
                        Console.WriteLine("skipping (expected outcome not recorded).");
                    }
                    else
                    {
                        try
                        {
                            using (Stream zcode = test.GetZCode())
                            {
                                ReplayIO io = new ReplayIO(test.InputFile);
                                ZMachine zm = new ZMachine(zcode, io);

                                zm.PredictableRandom = true;
                                zm.ReadingCommandsFromFile = true;

                                string output = RunAndCollectOutput(zm, io);
                                string expectedOutput = File.ReadAllText(test.OutputFile);

                                if (OutputDiffers(expectedOutput, output))
                                {
                                    Console.WriteLine("failed!");
                                    failures++;
                                    File.WriteAllText(test.FailureFile, output);
                                }
                                else
                                {
                                    Console.WriteLine("passed.");
                                }
                            }
                        }
                        finally
                        {
                            test.CleanUp();
                        }
                    }
                }

                if (failures > 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("{0} test{1} failed. The actual output is saved with the suffix \".failed-output.txt\".",
                        failures,
                        failures == 1 ? "" : "s");
                }
            }
        }