예제 #1
0
        public void Runner(object o)
        {
            ScriptPath path = (ScriptPath)o;

            if (!Single)
            {
                ForwardOutput("# " + path.ToString(), false, true, Client.OutputReceived);
            }
            try  {
                int    exit = 1;
                string exe  = Compile(path, Client.TapWasUpdated);
                if (exe != null)
                {
                    exit = Run(exe);
                }
                TAPApp.VLog(2, "Exit code from {0}: {1}", path, exit);
            }
            catch (Exception e) {
                TAPApp.ELog("Exception running {0}: {1}", path, e.ToString());
            }
            finally {
                TAPApp.DLog(3, "{0} done.", path);
                TAPParser.End();
                Running = false;
                Done.Set();
            }
        }
예제 #2
0
 public override void ErrorReceived(string s, bool force)
 {
     if (s != null && (force || TAPApp.Verbose > 0))
     {
         TAPApp.ELog(s);
     }
 }
예제 #3
0
        string Compile(ScriptPath spath, bool tapwasupdated)
        {
            string path = spath.Path;

            if (!File.Exists(path))
            {
                throw new FileNotFoundException("source file not found", path);
            }
            string outpath = TapFromSource(spath);
            string pdbpath = PdbFromTap(outpath);

            string[] sa = GetSubjectAssemblies(); // this includes tap.exe copied with CopyMe
            TAPApp.VLog(3, "subject assemblies:" + string.Join(",", sa.ToArray()));
            if (!tapwasupdated && !TAPApp.IsOutdated(outpath, path) && !TAPApp.IsOutdated(pdbpath, path) &&
                !IsOutdated(outpath, sa))
            {
                TAPApp.VLog(2, outpath + " is up to date");
                return(outpath);
            }
            TAPApp.VLog(3, "building {0}", outpath);
            using (CodeDomProvider prov = new CSharpCodeProvider(new Dictionary <string, string> {
                { "CompilerVersion", "v3.5" }
            })) {                                       // maybe make configurable in a <system.codedom><compilers>...
                var cp = new CompilerParameters();
                cp.GenerateExecutable      = true;
                cp.IncludeDebugInformation = true;
                cp.OutputAssembly          = outpath;
                //cp.CompilerOptions+=String.Concat("/d:DEBUG /lib:\"",GetMyImagePath(),"\"");
#if __MonoCS__
                cp.CompilerOptions += "/d:DEBUG /nowarn:169";
#else
                cp.CompilerOptions += string.Concat("/d:DEBUG /pdb:", pdbpath);
#endif
                cp.ReferencedAssemblies.Add("System.dll");
                cp.ReferencedAssemblies.Add("System.Core.dll");

                cp.ReferencedAssemblies.AddRange(sa);
                cp.ReferencedAssemblies.AddRange(TAPApp.Refs.ToArray());
                CompilerResults cr     = prov.CompileAssemblyFromFile(cp, new [] { path });
                bool            errors = cr.Errors.Count > 0;
                if (errors)
                {
                    TAPApp.ELog("Errors building");
                }
                if (errors || TAPApp.Verbose > 1)
                {
                    foreach (string i in cr.Output)
                    {
                        TAPApp.Log(i);
                    }
                }
                if (!errors)
                {
                    return(cr.PathToAssembly);
                }
                return(null);
            }
        }
예제 #4
0
        static bool IsOutdated(string obj, string[] src)
        {
            string first = src.FirstOrDefault(x => TAPApp.IsOutdated(obj, x));

            if (first != null)
            {
                TAPApp.VLog(2, "{0} is newer than {1}", first, obj);
                return(true);
            }
            return(false);
        }
예제 #5
0
 public override void OutputReceived(string s, bool force)
 {
     if (s != null)
     {
         TAPApp.DLog(4, "received {0}.", s);
         if (force || TAPApp.Verbose > 0)
         {
             TAPApp.Log(s);
         }
     }
 }
예제 #6
0
파일: taskmgr.cs 프로젝트: am11/TAP.Net
        void AddTask(ScriptPath sp, bool single)
        {
            TAPApp.DLog(3, "Add task {0}", sp);
            var task = new Task(TaskDone, Client, sp, single);

            if (Tasks.Count == 0)
            {
                task.Head = true;
            }
            task.Run();
            Tasks.Enqueue(task);
        }
예제 #7
0
 public void ParseLine(string line)
 {
     if (Counters.FirstLine)
     {
         Counters.FirstLine = false;
         string[] p = Match(PlanRE, line);
         if (p != null)
         {
             Plan(int.Parse(p[0]));
             return;
         }
     }
     string[] m = Match(ResultRE, line);
     if (m != null)
     {
         bool ok   = m[0] == "ok";
         bool todo = m[3] == "TODO";
         if (todo)
         {
             ++Counters.NTodo;
         }
         if (ok)
         {
             ++Counters.NOk;
             if (todo)
             {
                 ++Counters.NTodoSucc;
             }
         }
         else
         {
             if (todo)
             {
                 ++Counters.NOk;
             }
             else
             {
                 ++Counters.NNotOk;
             }
         }
         int expectedidx = Counters.NOk + Counters.NNotOk;
         int idx         = int.Parse(m[1]);
         if (idx != expectedidx)
         {
             TAPApp.Log("# tapparser: unexpected index number {0}; expected {1}.", idx, expectedidx);
         }
         if (m[3] == "SKIP")
         {
             ++Counters.NSkipped;
         }
     }
 }
예제 #8
0
 internal IEnumerable <ScriptPath> Expand(ICollection <string> paths)
 {
     if (paths.Count == 0)
     {
         return(Directory.GetFiles("t", "*.cs", SearchOption.AllDirectories).Select(x => new ScriptPath(x, "t")));
     }
     else
     {
         return(from i in paths.Select(x => TAPApp.FixPathSep(x))
                from j in Directory.Exists(i)?GetScriptsInPath(i):GetByWildcard(i)
                select j);
     }
 }
예제 #9
0
        bool CopyMe(string targetpath)
        {
            string me = GetMyImagePath();
            string to = Path.Combine(targetpath, Path.GetFileName(me));

            if (TAPApp.IsOutdated(to, me))
            {
                TAPApp.VLog(2, "copy from {0} to {1}", me, to);
                File.Copy(me, to, true);
                // this can be removed once all the bugs are fixed :-)
                string pdb   = TAPApp.PdbFromExe(me);
                string pdbto = TAPApp.PdbFromExe(to);
                File.Copy(pdb, pdbto, true);
                return(true);
            }
            return(false);
        }
예제 #10
0
파일: taskmgr.cs 프로젝트: am11/TAP.Net
 void ReapHead()
 {
     TAPApp.DLog(3, "ReapHead {0} tasks active", Tasks.Count);
     while (Tasks.Count != 0)
     {
         var task = Tasks.Peek();
         task.Head = true;
         if (task.Running)
         {
             break;
         }
         TAPApp.DLog(3, "finish task {0}", task.ScriptPath);
         task.WriteBuffered();
         task.TaskComplete();
         Tasks.Dequeue();
     }
 }
예제 #11
0
 static public void ShowTotals(List <string> paths)
 {
     if (Total.NScripts == 0)
     {
         string instr = "";
         if (paths.Count != 0)
         {
             instr = string.Join(", ", paths.ToArray());
         }
         TAPApp.Log("not ok 1 - No matching test scripts. Paths: {0}.", instr);
         Exit = 1;
     }
     else if (Total.NScripts > 1)
     {
         TAPApp.Log("# result after {0} scripts:", Total.NScripts);
         UpdateExit(Total.Show());
         TAPApp.DLog(2, "exit is {0}", Exit);
     }
 }
예제 #12
0
            public int Show()
            {
                int    all     = NOk + NNotOk;
                int    exit    = 1;
                string scripts = NScripts == 1?"script":"scripts";

                if (!FirstLine && !Mismatch && NNotOk == 0 && NRunFailed == 0)
                {
                    TAPApp.Log("# all OK. ({0} {1})", NOk, TestTests(NOk));
                    if (NTodoSucc != 0)
                    {
                        TAPApp.Log("#   {0} todo {1} succeeded unexpectedly.", NTodoSucc, TestTests(NTodoSucc));
                    }
                    exit = 0;
                }
                else
                {
                    string pfix = "FAILED.";
                    if (FirstLine)
                    {
                        TAPApp.Log("# {0} No output.", pfix);
                    }
                    if (NRunFailed != 0)
                    {
                        int nrunok = NScripts - NRunFailed;
                        TAPApp.Log("# {0} {1}/{2} {3} run ({4:D0}%)", pfix, nrunok, NScripts, scripts, (int)(((double)nrunok / NScripts) * 100));
                        pfix = "  ";
                    }
                    if (NNotOk != 0)
                    {
                        TAPApp.Log("# {0} {1}/{2} {3} passed ({4:D0}%)", pfix, NOk, all, TestTests(NOk), (int)(((double)NOk / all) * 100));
                        pfix = "  ";
                    }
                    if (Mismatch)
                    {
                        TAPApp.Log("# {0} Number of planned tests did not match number of tests.", pfix);
                        pfix = "  ";
                        TAPApp.Log("# {0} planned: {1} run: {2}", pfix, NPlanned, all);
                    }
                }
                TAPApp.Log("# Wall clock time: {0}", End - Start);
                return(exit);
            }
예제 #13
0
파일: taskmgr.cs 프로젝트: am11/TAP.Net
        public void Run(ScriptPath[] srcs)
        {
            int maxtasks = TAPApp.MaxTasks;

            TAPApp.VLog(3, "Max. {0} {1}.", maxtasks, maxtasks == 1?"task":"parallel tasks");
            int  k      = 0;
            bool single = srcs.Length == 1;

            do
            {
                bool waiting = k != srcs.Length;
                int  running = CountRunningTasks();
                if (!waiting && running == 0)
                {
                    TAPParser.EndTotal();
                }
                ReapHead();
                if (waiting)
                {
                    running = CountRunningTasks();
                    while (running < maxtasks)
                    {
                        if (k != srcs.Length)
                        {
                            AddTask(srcs[k], single);
                            ++k;
                            ++running;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                if (Tasks.Count == 0)
                {
                    break;
                }
                TaskDone.WaitOne();
            } while(true);
            TAPApp.DLog(3, "TaskMgr done.");
        }
예제 #14
0
        static void ReadArgs(string[] args)
        {
            if (args.Length != 0 && args[0] == "-le")
            {
                Environment.Exit(0);
            }
            foreach (var i in args)
            {
                Match m = Regex.Match(i, @"^[/-](\w+)(?::(.+))?");
                if (m.Success)
                {
                    string key    = m.Groups[1].ToString().ToLower();
                    string val    = m.Groups[2].ToString();
                    bool   hasval = !string.IsNullOrEmpty(val);
                    switch (key)
                    {
                    case "r":
                    case "reference":
                        if (hasval)
                        {
                            Refs.Add(val);
                        }
                        break;

                    case "t":
                    case "template":
                        WriteTemplate(val);
                        Environment.Exit(0);
                        break;

                    case "s":
                    case "subject":
                        Subject = hasval?val:".";
                        break;

                    case "f":
                    case "format":
                        val = val.ToLowerInvariant();
                        if (hasval && SupportedFormats.Contains(val))
                        {
                            Format = val;
                        }
                        else
                        {
                            Log("unrecognized format.");
                            Environment.Exit(1);
                        }
                        break;

                    case "e":
                    case "elapsed":
                        Elapsed = true;
                        break;

                    case "p":
                    case "parallel":
                        if (hasval)
                        {
                            MaxTasks = int.Parse(val);
                        }
                        else
                        {
                            MaxTasks = Environment.ProcessorCount;
                        }
                        break;

                    case "u":
                    case "unordered":
                        Unordered = true;
                        break;

                    case "j":
                    case "horizontalthresh":
                        if (hasval)
                        {
                            HorizontalThreshold = int.Parse(val);
                        }
                        break;

                    case "z":
                    case "zero":
                        Zero = true;
                        break;

                    case "v":
                    case "verbose":
                        Verbose = hasval?int.Parse(val):2;
                        break;

                    case "d":
                    case "debugverbose":
                        DebugVerbose = hasval?int.Parse(val):0;
                        break;

                    case "h":
                    case "help":
                        OutputHelp();
                        Environment.Exit(1);
                        break;
                    }
                }
                else
                {
                    Paths.Add(i);
                }
            }
            Subject = TAPApp.FixPathSep(Subject);
        }
예제 #15
0
 static string PdbFromTap(string tap)
 {
     return(TAPApp.PdbFromExe(tap));
 }
예제 #16
0
 static public void EndTotal()
 {
     Total.End = DateTime.UtcNow;
     TAPApp.DLog(3, "Stopped the clock.");
 }
예제 #17
0
 public void TaskComplete()
 {
     TAPApp.VLog(3, "TaskComplete");
     TAPParser.UpdateTotals();
     TAPParser.ShowSubtotals();
 }