Example #1
0
        public override bool Execute()
        {
            if (TestAssemblies.Length == 0)
                throw new ArgumentException("At least one test assembly is required");

            var logString = new StringBuilder();
            TextWriter msbuildLogWriter = new StringWriter(logString);
            var output = new PlainTextOutput(msbuildLogWriter);

            WriteHeaderInto(output);

            var config = NBehaveConfiguration.New
                .DontIsolateInAppDomain()
                .SetScenarioFiles(ScenarioFiles)
                .SetDryRun(DryRun)
                .SetAssemblies(TestAssemblies)
                .SetEventListener(EventListeners.CreateEventListenerUsing(msbuildLogWriter, TextOutputFile, XmlOutputFile));
            var runner = RunnerFactory.CreateTextRunner(config);

            FeatureResults = runner.Run();

            if (DryRun)
                return true;

            var message = logString.ToString();
            Log.LogMessage(message);

            if (FailBuild && FailBuildBasedOn(FeatureResults))
                return false;

            return true;
        }
Example #2
0
        protected override void ExecuteTask()
        {
            if (TestAssemblies.FileNames.Count == 0)
                throw new BuildException("At least one test assembly is required");

            var nantLogWriter = new LogWriter(this, Level.Info, CultureInfo.InvariantCulture);
            var output = new PlainTextOutput(nantLogWriter);

            WriteHeaderInto(output);

            var listener = EventListeners.CreateEventListenerUsing(nantLogWriter,
                                                                              TextOutputFile,
                                                                              XmlOutputFile);

            var runner = NBehaveConfiguration
                .New
                .SetDryRun(DryRun)
                .SetScenarioFiles(ScenarioFiles.FileNames.Cast<string>().ToList())
                .SetAssemblies(TestAssemblies.FileNames.Cast<string>().ToList())
                .SetEventListener(listener)
                .Build();

            var results = runner.Run();

            if (DryRun)
                return;

            if (FailBuild)
                FailBuildBasedOn(results);
        }
Example #3
0
 private void WriteHeaderInto(PlainTextOutput output)
 {
     output.WriteHeader();
     output.WriteSeparator();
     output.WriteRuntimeEnvironment();
     output.WriteSeparator();
 }
        public static int Main(string[] args)
        {
            var t0 = DateTime.Now;
            var output = new PlainTextOutput(System.Console.Out);
            var options = CommandLineParser<ConsoleOptions>.Parse(args);

            if (!options.Nologo)
                WriteHeader(output);

            if (options.Help)
            {
                options.ShowHelp();
                return 0;
            }

            if (!options.IsValid())
            {
                WriteInvalidArguments(options);
                return ReturnCode.InvalidArguments;
            }

            if (options.WaitForDebugger)
            {
                WaitForDebuggerToAttach();
                if (!Debugger.IsAttached)
                {
                    output.WriteLine("fatal error: timeout while waiting for debugger to attach");
                    return ReturnCode.AttachDebuggerTimeout;
                }
            }

            var assemblies = options.Parameters.ToArray().Select(assembly => assembly).Cast<string>().ToList();
            var config = NBehaveConfiguration.New
                .SetScenarioFiles((options.ScenarioFiles).Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                .SetDryRun(options.DryRun)
                .SetAssemblies(assemblies)
                .UseTagsFilter(options.Tags.Select(_=>_.Split(',')))
                .SetEventListener(CreateEventListener(options));

            FeatureResults featureResults = null;

            try
            {
                featureResults = Run(config);
            }
            catch (FileNotFoundException fileNotFoundException)
            {
                System.Console.WriteLine(string.Format("File not found: {0}", fileNotFoundException.FileName));
                return ReturnCode.FileNotFound;
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }

            PrintTimeTaken(t0);

            if (options.DryRun)
            {
                return 0;
            }

            if (options.Pause)
            {
                System.Console.WriteLine("Press any key to exit");
                System.Console.ReadKey();
            }
            return (featureResults == null) ? -1 : featureResults.NumberOfFailingScenarios;
        }