Exemple #1
0
 public void WriteReport(ReportSource message, ReportType type, string seconds = "", Exception e = null)
 {
     if (logAct != null)
     {
         logAct(message, type, e, seconds);
     }
 }
        /**
         *      this method will be called from jumper lib.
         */
        public void AddLog(ReportSource reportSource, ReportType type, Exception e, string seconds)
        {
            if (Application.isEditor)
            {
                using (var sw = new System.IO.StreamWriter("miyamasu.log", true)) {
                    var str = type + ":" + reportSource.className + "/" + reportSource.methodName + " @" + reportSource.lineNumber;

                    // 時間がセットされていれば記載
                    if (!string.IsNullOrEmpty(seconds))
                    {
                        str += " in " + seconds + " sec";
                    }

                    sw.WriteLine(str);

                    // errorを次の行から追記
                    if (e != null)
                    {
                        sw.WriteLine("  " + e);
                    }
                }
            }

            var icon = "pass";

            switch (type)
            {
            case ReportType.AssertionFailed: {
                icon = "fail";
                break;
            }

            case ReportType.FailedByTimeout: {
                icon = "timeout";
                break;
            }

            case ReportType.Error: {
                icon = "error";
                break;
            }

            case ReportType.Passed: {
                icon = "pass";
                break;
            }

            default: {
                icon = "error";
                break;
            }
            }

            var messageBlock = reportSource.className + " / " + reportSource.methodName;

            if (!string.IsNullOrEmpty(reportSource.lineNumber))
            {
                messageBlock += " line:" + reportSource.lineNumber;
            }

            var error = string.Empty;

            if (e != null)
            {
                var id = Guid.NewGuid().ToString();
                error = @" button='true' src='" + Base64Encode(e.ToString()) + @"' id='" + id + @"'";
            }
            logList.Add(@"
				<bg"                 + error + @">
					<textbg>
						<contenttext>"                         + messageBlock + @"</contenttext>
					</textbg>
					<iconbg><"                     + icon + @"/></iconbg>
				</bg><br>"                );

            var coroutines = new List <IEnumerator>();

            // send result to slack.
            switch (type)
            {
            case ReportType.AssertionFailed:
            case ReportType.FailedByTimeout:
            case ReportType.Error: {
                coroutines.Add(new SlackIntegration._SendLog("device:" + SystemInfo.deviceName + " failed " + reportSource.Description() + "\n" + e.ToString(), 0));
                break;
            }

            case ReportType.Passed: {
                coroutines.Add(new SlackIntegration._SendLog("device:" + SystemInfo.deviceName + " passed " + reportSource.Description(), 0));
                break;
            }

            default: {
                // do nothing.
                break;
            }
            }

            // count up.
            switch (type)
            {
            case ReportType.Error:
            case ReportType.FailedByTimeout:
            case ReportType.AssertionFailed: {
                failed++;
                break;
            }

            case ReportType.Passed: {
                passed++;
                break;
            }
            }

            if (testEnumerators.Count == 0)
            {
                var reportEndCor = new SlackIntegration._SendLog("all " + testCount + " tests finished. passed:" + passed + " failed:" + failed, 0);
                coroutines.Add(reportEndCor);
            }

            if (coroutines.Any())
            {
                StartCoroutine(RunLogCoroutines(coroutines));
            }

            // restart test.
            switch (type)
            {
            case ReportType.AssertionFailed:
            case ReportType.FailedByTimeout:
            case ReportType.Error: {
                StartCoroutine(RunTestCoroutines());
                break;
            }

            default: {
                // do nothing.
                break;
            }
            }
        }