Esempio n. 1
0
        public async Task PreprocessorTestAsync()
        {
            var preprocessorLocalFile = Path.GetTempFileName();

            TestHelper.InitializePackageTaskFactory();
            var projectMock = TestHelper.MakeProjectWithProfile(
                new Dictionary <string, string>()
            {
                { RadMacros.PreprocessorExecutable, "kuu" },
                { RadMacros.PreprocessorArguments, "--away" },
                { RadMacros.PreprocessorWorkingDirectory, "/home/old" },
                { RadMacros.PreprocessorOutputPath, "preprocessed_source.build.tmp" },
                { RadMacros.PreprocessorLocalPath, preprocessorLocalFile }
            },
                projectRoot: @"C:\Users\CFF\Preprocess",
                profile: new Options.ProfileOptions());// build: new Options.BuildProfileOptions(runPreprocessor: true)));
            var channel = new MockCommunicationChannel();
            var server  = StartBuildServer(projectMock, channel.Object);

            var timestamp = DateTime.Now;

            channel.ThenRespond <FetchMetadata, MetadataFetched>(new MetadataFetched {
                Status = FetchStatus.Successful, Timestamp = timestamp
            }, (command) =>
            {
                Assert.Equal("/home/old", command.FilePath[0]);
                Assert.Equal("preprocessed_source.build.tmp", command.FilePath[1]);
            });
            channel.ThenRespond <Execute, ExecutionCompleted>(new ExecutionCompleted
            {
                Status = ExecutionStatus.Completed, ExitCode = 0
            },
                                                              (command) =>
            {
                Assert.Equal("kuu", command.Executable);
                Assert.Equal("--away", command.Arguments);
                Assert.Equal("/home/old", command.WorkingDirectory);
            });
            channel.ThenRespond <FetchResultRange, ResultRangeFetched>(new ResultRangeFetched
            {
                Timestamp = timestamp.AddSeconds(1), Status = FetchStatus.Successful, Data = Encoding.UTF8.GetBytes("#define H")
            }, (_) => { });

            var message = await FetchResultOnClientAsync(server);

            Assert.False(message.Skipped);
            Assert.Equal("", message.ServerError);
            Assert.Equal(0, message.ExitCode);
            Assert.Empty(message.ErrorMessages);

            Assert.Equal("#define H", File.ReadAllText(preprocessorLocalFile));
            File.Delete(preprocessorLocalFile);
        }
Esempio n. 2
0
        public async Task BuildErrorTestAsync()
        {
            TestHelper.InitializePackageTaskFactory();
            var projectMock = TestHelper.MakeProjectWithProfile(new Dictionary <string, string>()
            {
                { RadMacros.BuildExecutable, "err" }
            });
            var channel        = new MockCommunicationChannel();
            var errorProcessor = new BuildErrorProcessor(new Mock <IProjectSourceManager>().Object);
            var server         = StartBuildServer(projectMock, channel.Object, errorProcessor: errorProcessor);

            channel.ThenRespond <Execute, ExecutionCompleted>(new ExecutionCompleted
            {
                Status   = ExecutionStatus.Completed,
                ExitCode = 1,
                Stdout   = "",
                Stderr   = PackageTests.BuildTools.Errors.ParserTests.ScriptStderr
            }, (_) => { });

            var message = await FetchResultOnClientAsync(server);

            Assert.False(message.Skipped);
            Assert.Equal("", message.ServerError);
            Assert.Equal(1, message.ExitCode);
            Assert.Equal(PackageTests.BuildTools.Errors.ParserTests.ScriptExpectedMessages, message.ErrorMessages);
        }
Esempio n. 3
0
        public async Task SuccessfulBuildTestAsync()
        {
            TestHelper.InitializePackageTaskFactory();
            var projectMock = TestHelper.MakeProjectWithProfile(new Dictionary <string, string>()
            {
                { RadMacros.BuildExecutable, "nemu" },
                { RadMacros.BuildArguments, "--sleep 10" },
                { RadMacros.BuildWorkingDirectory, "/old/home" }
            }, projectRoot: @"C:\Users\CFF\Repos\H");
            var channel        = new MockCommunicationChannel();
            var deployManager  = new Mock <IFileSynchronizationManager>();
            var errorProcessor = new Mock <IBuildErrorProcessor>(MockBehavior.Strict);

            errorProcessor
            .Setup((e) => e.ExtractMessagesAsync(new string[] { "stderr" }, It.IsAny <string>()))
            .Returns(Task.FromResult <IEnumerable <Message> >(Array.Empty <Message>()));
            var server = StartBuildServer(projectMock, channel.Object, deployManager.Object, errorProcessor.Object);

            channel.ThenRespond <Execute, ExecutionCompleted>(new ExecutionCompleted
            {
                Status   = ExecutionStatus.Completed,
                ExitCode = 0,
                Stdout   = "day of flight",
                Stderr   = "stderr"
            },
                                                              (command) =>
            {
                Assert.Equal("nemu", command.Executable);
                Assert.Equal("--sleep 10", command.Arguments);
                Assert.Equal("/old/home", command.WorkingDirectory);
            });

            var message = await FetchResultOnClientAsync(server);

            deployManager.Verify((d) => d.SynchronizeRemoteAsync(It.IsAny <IMacroEvaluator>()), Times.Once);

            Assert.False(message.Skipped);
            Assert.Equal("", message.ServerError);
            Assert.Equal(0, message.ExitCode);
            Assert.Empty(message.ErrorMessages);
        }
Esempio n. 4
0
        public async Task SuccessfulRunTestAsync()
        {
            TestHelper.InitializePackageTaskFactory();

            /* Create a test project */

            var projectMock = new Mock <IProject>();
            var options     = new ProjectOptions();

            options.SetProfiles(new Dictionary <string, ProfileOptions> {
                { "Default", new ProfileOptions() }
            }, activeProfile: "Default");
            projectMock.Setup((p) => p.Options).Returns(options);
            projectMock.Setup(p => p.RunWhenLoaded(It.IsAny <Action <ProjectOptions> >())).Callback((Action <ProjectOptions> a) => a(options));
            var breakLineTagger = new Mock <BreakLineGlyphTaggerProvider>();

            projectMock.Setup((p) => p.GetExportByMetadataAndType(It.IsAny <Predicate <IAppliesToMetadataView> >(), It.IsAny <Predicate <IViewTaggerProvider> >()))
            .Returns(breakLineTagger.Object);
            var project = projectMock.Object;

            project.Options.Profile.MenuCommands.DebugAction = "Debug";
            project.Options.Profile.General.LocalWorkDir     = "local/dir";
            project.Options.Profile.General.RemoteWorkDir    = "/periphery/votw";
            project.Options.Profile.Actions.Add(new ActionProfileOptions {
                Name = "Debug"
            });
            project.Options.DebuggerOptions.Watches.Add(new Watch("a", VariableType.Hex, false));
            project.Options.DebuggerOptions.Watches.Add(new Watch("c", VariableType.Hex, false));
            project.Options.DebuggerOptions.Watches.Add(new Watch("tide", VariableType.Hex, false));

            var readDebugDataStep = new ReadDebugDataStep {
                BinaryOutput = false, OutputOffset = 1
            };

            readDebugDataStep.OutputFile.CheckTimestamp = true;
            readDebugDataStep.OutputFile.Path           = "output-path";

            project.Options.Profile.Actions[0].Steps.Add(new ExecuteStep
            {
                Executable = "ohmu", Arguments = "-break-line $(RadBreakLine) -source $(RadActiveSourceFile) -source-line $(RadActiveSourceFileLine) -watch $(RadWatches)"
            });
            project.Options.Profile.Actions[0].Steps.Add(readDebugDataStep);

            var codeEditor = new Mock <IActiveCodeEditor>();

            codeEditor.Setup(e => e.GetCurrentLine()).Returns(13);
            var breakpointTracker = new Mock <IBreakpointTracker>();

            breakpointTracker.Setup(t => t.MoveToNextBreakTarget(false)).Returns((@"C:\MEHVE\JATO.s", new[] { 666u }));

            var serviceProvider = new Mock <SVsServiceProvider>();

            serviceProvider.Setup(p => p.GetService(typeof(SVsStatusbar))).Returns(new Mock <IVsStatusbar>().Object);

            var channel        = new MockCommunicationChannel(DebugServer.IPC.ServerPlatform.Linux);
            var sourceManager  = new Mock <IProjectSourceManager>();
            var actionLauncher = new ActionLauncher(project, new Mock <IActionLogger>().Object, channel, sourceManager.Object,
                                                    codeEditor.Object, breakpointTracker.Object, serviceProvider.Object);
            var debuggerIntegration = new DebuggerIntegration(project, actionLauncher, codeEditor.Object, breakpointTracker.Object);

            /* Set up server responses */

            channel.ThenRespond(new MetadataFetched {
                Status = FetchStatus.FileNotFound
            }, (FetchMetadata timestampFetch) =>
                                Assert.Equal(new[] { "/periphery/votw/output-path" }, timestampFetch.FilePath));
            channel.ThenRespond(new ExecutionCompleted {
                Status = ExecutionStatus.Completed, ExitCode = 0
            }, (Execute execute) =>
            {
                Assert.Equal("ohmu", execute.Executable);
                Assert.Equal(@"-break-line 666 -source JATO.s -source-line 13 -watch a:c:tide", execute.Arguments);
            });
            channel.ThenRespond(new MetadataFetched {
                Status = FetchStatus.Successful, Timestamp = DateTime.Now
            });

            /* Start debugging */

            var        tcs        = new TaskCompletionSource <ExecutionCompletedEventArgs>();
            BreakState breakState = null;

            debuggerIntegration.ExecutionCompleted += (s, e) => tcs.SetResult(e);
            debuggerIntegration.BreakEntered       += (s, e) => breakState = e;

            var engine = debuggerIntegration.RegisterEngine();

            engine.Execute(false);

            var execCompletedEvent = await tcs.Task;

            Assert.NotNull(execCompletedEvent);
            Assert.Equal(@"C:\MEHVE\JATO.s", execCompletedEvent.File);
            Assert.Equal(666u, execCompletedEvent.Lines[0]);

            sourceManager.Verify(s => s.SaveProjectState(), Times.Once);

            Assert.NotNull(breakState);
            Assert.Equal(3, breakState.Data.Watches.Count);
            Assert.Equal("a", breakState.Data.Watches[0]);
            Assert.Equal("c", breakState.Data.Watches[1]);
            Assert.Equal("tide", breakState.Data.Watches[2]);

            breakLineTagger.Verify(t => t.OnExecutionCompleted(execCompletedEvent));
        }