예제 #1
0
        public static void Execute(string[] paths)
        {
            bool   isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
            string NewLine   = (isWindows ? Environment.NewLine : "");
            VM     vm        = new VM(false);

            foreach (string path in paths)
            {
                Preprocessor prep;
                RPGLex       lexer;
                Statement[]  Statements;
                Reader       reader;

                prep = new Preprocessor();
                prep.ReadFile(path);

                lexer = new RPGLex();
                lexer.Lex(String.Join(NewLine, prep.GetLines()));

                Statements = Statement.ParseDocument(lexer.GetTokens());

                reader = new Reader();
                reader.ReadStatements(Statements);

                try {
                    vm.AddModule(reader.GetModule());
                } catch (Exception e) {
                    Console.WriteLine("Failed to add module: " + path);
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                }
            }

            try {
                vm.Run();
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
예제 #2
0
        public static void RunTests(string testsStarting = "")
        {
            ConsoleColor originalColor = Console.ForegroundColor;

            string       SourcePath;
            bool         isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
            string       NewLine   = (isWindows ? Environment.NewLine : "");
            Preprocessor prep;
            RPGLex       lexer;

            Statement[] Statements;
            Reader      reader;
            VM          vm;

            int       run = 0, passed = 0, failed = 0;
            Exception lastError = null;

            dynamic result;

            foreach (string files in TestCases.Keys)
            {
                if (testsStarting == "" || files.StartsWith(testsStarting))
                {
                    result    = null;
                    lastError = null;

                    vm = new VM(true);
                    run++;

                    foreach (string file in files.Split(','))
                    {
                        Console.Write("Testing " + file.PadRight(35) + " ... ");
                        SourcePath = Path.Combine(Environment.CurrentDirectory, "RPGCode", file);

                        prep = new Preprocessor();
                        prep.ReadFile(SourcePath);

                        lexer = new RPGLex();
                        lexer.Lex(String.Join(NewLine, prep.GetLines()));

                        Statements = Statement.ParseDocument(lexer.GetTokens());

                        reader = new Reader();
                        reader.ReadStatements(Statements);

                        try {
                            vm.AddModule(reader.GetModule());
                        } catch (Exception e) {
                            lastError = e;
                        }
                    }

                    if (lastError == null)
                    {
                        try
                        {
                            result = vm.Run();
                        }
                        catch (Exception e)
                        {
                            lastError = e;
                            result    = null;
                        }
                    }

                    if (result != null && result == TestCases[files])
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("successful.");
                        Console.ForegroundColor = originalColor;

                        passed++;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("failed.");
                        Console.ForegroundColor = originalColor;
                        Console.WriteLine();
                        if (lastError != null)
                        {
                            Console.WriteLine(lastError.Message);
                            Console.WriteLine(lastError.StackTrace);
                            Console.WriteLine();
                        }

                        Console.WriteLine("\tExpected: '" + Convert.ToString(TestCases[files]) + "'");
                        Console.WriteLine("\tReturned: '" + Convert.ToString(result) + "'");
                        Console.WriteLine();
                        vm.PrintModules();

                        lastError = null;
                        failed++;
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(run.ToString() + " ran, " + passed.ToString() + " passed, " + failed.ToString() + " failed");
        }