Пример #1
0
 protected override void OnStart(StartUnitTest work)
 {
     _work       = work;
     _passed     = 0;
     _freshTest  = true;
     _failed     = 0;
     _unitTestId = string.Empty;
 }
Пример #2
0
        public IObservable <IRxn> Start(string name, StartUnitTest work, StreamWriter testLog, string logDir)
        {
            var testEventStream = new Subject <IRxn>();
            //https://github.com/dotnet/sdk/issues/5514
            var dotnetHack = PathToTestArenaProcess();

            var logName = $"{name}{work.RunThisTest.Substring(0, work.RunThisTest.Length > 25 ? 25 : work.RunThisTest.Length).IsNullOrWhiteSpace(new FileInfo(work.Dll).Name)}".LogDebug("Targeting");

            bool isreadingOutputMessage = false;
            var  lastLine = false;

            OnStart(work);
            return(Rxn.Create
                   (
                       dotnetHack,
                       StartTestsCmd(work, logDir),
                       i =>
            {
                if (i == null)
                {
                    return;
                }

                foreach (var progress in OnLog(name, work, i))
                {
                    testEventStream.OnNext(progress);
                }

                if (testLog.BaseStream.CanWrite)
                {
                    testLog.WriteLine(i.LogDebug(logName));
                }
            },
                       e => testLog.WriteLine(e.LogDebug(logName))
                   )
                   .FinallyR(() =>
            {
                foreach (var e in OnEnd(work.Dll))
                {
                    testEventStream.OnNext(e);
                }

                testEventStream.OnCompleted();
            })
                   .SelectMany(_ => testEventStream)
                   );
        }
Пример #3
0
        public override IEnumerable <IRxn> OnLog(string worker, StartUnitTest work, string msg)
        {
            var cmd = msg.Split(' ', StringSplitOptions.RemoveEmptyEntries);

            _worker = worker;

            if (cmd.Length > 0)
            {
                if (_freshTest)
                {
                    yield return(new UnitTestsStarted()
                    {
                        TestId = work.Id,
                        At = DateTime.Now,
                        Tests = work.RunThisTest.IsNullOrWhiteSpace("").Split(',', StringSplitOptions.RemoveEmptyEntries),
                        Worker = _appInfo.Name,
                        WorkerId = worker
                    });

                    _freshTest = false;
                    outputBuffer.Clear();
                }

                lastLine = false;

                if (cmd[0] == "Passed" || cmd[0] == "Failed" || cmd[0] == "Skipped")
                {
                    if (_unitTestId != string.Empty)
                    {
                        yield return new UnitTestPartialLogResult
                               {
                                   LogMessage = outputBuffer.ToString(),
                                   TestId     = work.Id,
                                   UnitTestId = _unitTestId,
                                   Worker     = worker
                               }
                    }
                    ;

                    outputBuffer.Clear();

                    _unitTestId = Guid.NewGuid().ToString();

                    if (cmd[0].StartsWith('P'))
                    {
                        _passed++;
                    }
                    else if (cmd[0].StartsWith('F'))
                    {
                        _failed++;
                    }
                    else if (cmd[0].StartsWith('S'))
                    {
                        _skipped++;
                    }

                    if (cmd.Length > 0)
                    {
                        yield return new UnitTestPartialResult(work.Id, cmd[0], cmd[1], cmd.Length > 2 ? ToDuration(cmd[2]) : "0", worker)
                               {
                                   UnitTestId = _unitTestId
                               }
                    }
                    ;

                    yield break;
                }

                if (isreadingOutputMessage)
                {
                    outputBuffer.AppendLine(msg);
                }

                if (cmd[0] == "Standard" || cmd[0] == "Error")
                {
                    isreadingOutputMessage = true;
                }
            }
        }
Пример #4
0
 protected virtual string FilterIfSingleTestOnly(StartUnitTest work)
 {
     return(work.RunThisTest.IsNullOrWhitespace() ? "" : $" --filter Name={work.RunThisTest.Replace(",", "|Name=")}");
 }
Пример #5
0
 protected override string StartTestsCmd(StartUnitTest work, string logDir)
 {
     return($"test{FilterIfSingleTestOnly(work)} {work.Dll.EnsureRooted()} --results-directory {logDir.EnsureRooted()} --collect:\"XPlat Code Coverage\" --no-build --logger \"console;verbosity=detailed;\" --logger \"trx;LogFileName={work.Id}.trx\"");
 }
Пример #6
0
 protected override string FilterIfSingleTestOnly(StartUnitTest work)
 {
     return(work.RunThisTest.IsNullOrWhitespace() ? "" : $" /Tests:{work.RunThisTest}");
 }
Пример #7
0
 protected override string StartTestsCmd(StartUnitTest work, string logDir)
 {
     return($"{FilterIfSingleTestOnly(work)} {work.Dll.EnsureRooted()} /resultsdirectory:{logDir.EnsureRooted()} /logger:\"console;verbosity=detailed\" /logger:\"trx;LogFileName={work.Id}.trx\"");
 }
Пример #8
0
 protected abstract string StartTestsCmd(StartUnitTest work, string logDir);
Пример #9
0
 public abstract IEnumerable <IRxn> OnLog(string worker, StartUnitTest work, string msg);
Пример #10
0
 protected abstract void OnStart(StartUnitTest work);