Exemplo n.º 1
0
        public static void Check_BeforeAfterInsertionBatched()
        {
            Paths paths = new Paths(sampleRoot, resultRoot, sampleRoot + Path.DirectorySeparatorChar + "Programs" + Path.DirectorySeparatorChar + "Simple.pgm", new Multipass.IndexNames());
            TestUnit unit = new TestUnit(new Multipass(paths));
            unit.Init(new[] { "*.pgm", "*.cpy" });
            unit.Parse();

            var e = updateLine(TextChangeType.LineInserted, 2, "END PROGRAM Simple.");
            e = updateLine(TextChangeType.LineUpdated, 1, "PROGRAM-ID. Simpler.", e);

            // clear document
            unit.Compiler.CompilationResultsForProgram.UpdateTextLines(e);
            unit.Parse();

            var names = unit.Comparator.paths.Resultnames as Multipass.IndexNames;
            names.index = 2;
            Console.WriteLine("Compare with result file: "+unit.Comparator.paths.Result);
            unit.Compare();//with Simple.2.txt
        }
Exemplo n.º 2
0
        public static void Check_BeforeAfterInsertion()
        {
            Paths paths = new Paths(sampleRoot, resultRoot, sampleRoot + Path.DirectorySeparatorChar + "Programs" + Path.DirectorySeparatorChar + "Simple.pgm", new Multipass.IndexNames());
            TestUnit unit = new TestUnit(new Multipass(paths));
            unit.Init(new[] { "*.pgm", "*.cpy" });
            unit.Parse();
            var names = unit.Comparator.paths.Resultnames as Multipass.IndexNames;
            names.index = 0;
            unit.Compare();//with Simple.0.txt

            // explicitely close program by adding END PROGRAM line
            var e2 = updateLine(TextChangeType.LineInserted, 2, "END PROGRAM Simple.");
            var e = updateLine(TextChangeType.LineUpdated, 1, "  PROGRAM-ID. Simple.");
            e.TextChanges.Add(e2.TextChanges[0]);
            unit.Compiler.CompilationResultsForProgram.UpdateTextLines(e);
            unit.Parse();
            names.index++;
            Console.WriteLine("Compare with result file: "+unit.Comparator.paths.Result);
            unit.Compare();//with Simple.1.txt

            // change program name ; now first and last line have differing program id
            e = updateLine(TextChangeType.LineUpdated, 1, "PROGRAM-ID. Simpler.");
            unit.Compiler.CompilationResultsForProgram.UpdateTextLines(e);
            unit.Parse();
            names.index++;
            Console.WriteLine("Compare with result file: "+unit.Comparator.paths.Result);
            unit.Compare();//with Simple.2.txt

            // clear document
            e = updateLine(TextChangeType.DocumentCleared, /* the following parameters are not used when DocumentCleared*/ 0, null);
            unit.Compiler.CompilationResultsForProgram.UpdateTextLines(e);
            unit.Parse();
            names.index++;
            Console.WriteLine("Compare with result file: "+unit.Comparator.paths.Result);
            unit.Compare();//with Simple.3.txt
        }
Exemplo n.º 3
0
        public void Test(bool debug = false, bool json = false)
        {
            var errors = new StringBuilder();
            foreach (var samplePath in samples) {
                IList<FilesComparator> comparators = GetComparators(_sampleRoot, _resultsRoot, samplePath, debug);
                if (comparators.Count < 1) {
                    Console.WriteLine(" /!\\ ERROR: Missing result file \"" + samplePath + "\"");
                    errors.AppendLine("Missing result file \"" + samplePath + "\"");
                    continue;
                }
                foreach (var comparator in comparators) {
                    Console.WriteLine(comparator.paths.Result + " checked with " + comparator.GetType().Name);
                    var unit = new TestUnit(comparator, debug);
                    unit.Init(extensions);
                    unit.Parse();
                    if (unit.Observer.HasErrors)
                    {
                        Console.WriteLine(" /!\\ EXCEPTION\n" + unit.Observer.DumpErrors());
                        errors.AppendLine(unit.Observer.DumpErrors());
                    }
                    else
                    {
                        if (json)
                        {
                            string filename = comparator.paths.Result;
                            //string name = Path.GetFileName(filename);
                            string extension = Path.GetExtension(filename);
                            filename = filename.Substring(0, filename.Length - extension.Length);
                            string[] lines = {unit.ToJSON()};
                            System.IO.File.WriteAllLines(filename + ".json", lines);
                        }

                        try
                        {
                            unit.Compare();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(" /!\\ MISMATCH\n" + ex);
                            errors.Append("E");
                        }
                    }
                }
            }
            if (errors.Length > 0) throw new Exception(errors.ToString());
        }