Esempio n. 1
0
 public void Execute(TestData data)
 {
     Root root = new Root();
     var import = new CilImport(root);
     import.ImportAssembly(Assembly.Load("mscorlib"));
     import.ImportAssembly(Assembly.Load("CoreLibrary"));
     root.Append(CompileText(data.Name, data.Code));
     root.SemanticAnalysis();
     if (root.MessageManager.MessageCount > 0)
     {
         Directory.SetCurrentDirectory("..");
         Console.WriteLine(CompileMessageBuilder.Build(root.MessageManager));
         Directory.SetCurrentDirectory("output");
     }
     Assert.That(root.MessageManager, Is.EquivalentTo(data.Message).Using<CompileMessage>(new CompileMessageEqualityComparer()));
     if (root.MessageManager.ErrorCount > 0)
     {
         Assert.That(data.ErrorCount, Is.Not.EqualTo(0), "Compile error");
         return;
     }
     if (data.NoExecute)
     {
         return;
     }
     var trans = SyntaxTranslator.ToStructure(root, import, data.Name);
     trans.Save();
     //var cd = Directory.GetCurrentDirectory();
     //using (var process = MakeProcess(@"peverify.exe", data.Name + ".exe" + " /nologo /unique", cd))
     //{
     //    process.Start();
     //    if (!process.WaitForExit(500))
     //    {
     //        process.Kill();
     //        Assert.Fail("Peverify.exe timeout execution");
     //    }
     //    Console.WriteLine(process.StandardOutput.ReadToEnd());
     //}
     using (var process = MakeProcess(data.Name + ".exe"))
     {
         process.Start();
         process.StandardInput.WriteLine(data.Input);
         if (!process.WaitForExit(data.TimeOut ?? 500))
         {
             process.Kill();
             Assert.Fail(data.Name + ".exe" + " timeout execution");
         }
         var error = process.StandardError.ReadToEnd();
         if (!string.IsNullOrWhiteSpace(error))
         {
             Assert.Fail(error);
         }
         if (data.Output != null)
         {
             var output = TestData.CodeNormalize(process.StandardOutput.ReadToEnd(), true);
             Assert.That(output, Is.EqualTo(data.Output));
         }
     }
 }
Esempio n. 2
0
 public static void Main(string[] args)
 {
     string fileName = args[0];
     var root = new Root();
     var import = new CilImport(root);
     import.ImportAssembly(Assembly.Load("mscorlib"));
     import.ImportAssembly(Assembly.Load("CoreLibrary"));
     root.Append(CompileFile(fileName));
     root.SemanticAnalysis();
     Console.WriteLine(CompileMessageBuilder.Build(root.MessageManager));
     if (root.MessageManager.ErrorCount > 0)
     {
         return;
     }
     var trans = SyntaxTranslator.ToStructure(root, import, fileName.Replace(".dr", ""));
     trans.Save();
 }