コード例 #1
0
        public void TestProcessContainer()
        {
            var proc = TapProcessContainer.StartFromArgs("package list", TimeSpan.FromSeconds(100));

            proc.WaitForEnd();

            Assert.AreEqual(0, proc.TapProcess.ExitCode);
        }
コード例 #2
0
        public void SimpleVerdictStepTest()
        {
            var      setVerdict = new OpenTap.Engine.UnitTests.TestTestSteps.VerdictStep();
            TestPlan plan       = new TestPlan();

            plan.Steps.Add(setVerdict);
            plan.Save("verdictPlan.TapPlan");
            var proc = TapProcessContainer.StartFromArgs("run verdictPlan.TapPlan");

            proc.WaitForEnd();
            Assert.AreEqual(0, proc.TapProcess.ExitCode);
        }
コード例 #3
0
        public void RunParseTest()
        {
            var      setVerdict = new OpenTap.Engine.UnitTests.TestTestSteps.VerdictStep();
            TestPlan plan       = new TestPlan();

            plan.Steps.Add(setVerdict);
            plan.ExternalParameters.Add(setVerdict, TypeData.GetTypeData(setVerdict).GetMember("VerdictOutput"), "verdict");
            plan.ExternalParameters.Get("verdict").Value = "Not Set";
            plan.Save("verdictPlan.TapPlan");
            var fileName = CreateCsvTestFile(new string[] { "verdict" }, new object[] { "pass" });
            {
                string[] passingThings = new[] { "verdict=\"pass\"", "verdict=\"Not Set\"", "verdict=\"not set\"", fileName };
                passingThings.AsParallel().ForAll(v =>
                {
                    var args = string.Format("run verdictPlan.TapPlan -e {0}", v);
                    Log.CreateSource("RunParseTest").Debug("Running tap {0}", args);
                    var proc = TapProcessContainer.StartFromArgs(string.Format("run verdictPlan.TapPlan -e {0}", v), TimeSpan.FromMinutes(5));
                    proc.WaitForEnd();
                    Assert.AreEqual(0, proc.TapProcess.ExitCode);
                });
            }
            {
                string[] passingThings = new[] { "fail", "Error" };
                passingThings.AsParallel().ForAll(v =>
                {
                    var args = string.Format("run verdictPlan.TapPlan -e verdict=\"{0}\"", v);
                    Log.CreateSource("RunParseTest").Debug("Running tap {0}", args);
                    var proc = TapProcessContainer.StartFromArgs(args, TimeSpan.FromSeconds(120));
                    proc.WaitForEnd();
                    if (v == "Error")
                    {
                        Assert.AreEqual((int)ExitStatus.RuntimeError, proc.TapProcess.ExitCode);
                    }
                    else
                    {
                        Assert.AreEqual((int)ExitStatus.TestPlanFail, proc.TapProcess.ExitCode);
                    }
                });
            }
        }
コード例 #4
0
        public static TapProcessContainer StartFromArgs(string args, TimeSpan timeOutAfter)
        {
            Process proc = new Process();

            var container = new TapProcessContainer {
                TapProcess = proc
            };


            var file  = Path.GetDirectoryName(typeof(PluginManager).Assembly.Location);
            var files = new[] { Path.Combine(file, "tap.exe"), Path.Combine(file, "tap"), Path.Combine(file, "tap.dll") };

            global::OpenTap.Log.CreateSource("test").Debug($"location: {file}");
            var program = files.First(File.Exists);

            if (program.Contains(".dll"))
            {
                program = "dotnet";
                args    = $"\"{file}/tap.dll\" " + args;
            }

            proc.StartInfo = new ProcessStartInfo(program, args)
            {
                UseShellExecute        = true,
                RedirectStandardOutput = true,
                RedirectStandardInput  = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true,
            };
            proc.StartInfo.UseShellExecute = false;

            container.go();
            TapThread.Start(() =>
            {
                TapThread.Sleep(timeOutAfter);
                proc.Kill();
            });
            return(container);
        }