コード例 #1
0
        private static RunResult RunWebRequest(Package package, string requestId)
        {
            var runResult = new RunResult(succeeded: true, requestId: requestId);

            runResult.AddFeature(new WebServer(package));
            return(runResult);
        }
コード例 #2
0
        private static async Task <RunResult> RunConsoleAsync(
            Package package,
            IEnumerable <SerializableDiagnostic> diagnostics,
            Budget budget,
            string requestId,
            bool includeInstrumentation,
            string commandLineArgs)
        {
            var dotnet = new Dotnet(package.Directory);

            var commandName       = $@"""{package.EntryPointAssemblyPath.FullName}""";
            var commandLineResult = await dotnet.Execute(
                commandName.AppendArgs(commandLineArgs),
                budget);

            budget.RecordEntry(UserCodeCompleted);

            var output = InstrumentedOutputExtractor.ExtractOutput(commandLineResult.Output);

            if (commandLineResult.ExitCode == 124)
            {
                throw new BudgetExceededException(budget);
            }

            string exceptionMessage = null;

            if (commandLineResult.Error.Count > 0)
            {
                exceptionMessage = string.Join(Environment.NewLine, commandLineResult.Error);
            }

            var runResult = new RunResult(
                succeeded: true,
                output: output.StdOut,
                exception: exceptionMessage,
                diagnostics: diagnostics,
                requestId: requestId);

            if (includeInstrumentation)
            {
                runResult.AddFeature(output.ProgramStatesArray);
                runResult.AddFeature(output.ProgramDescriptor);
            }

            return(runResult);
        }
コード例 #3
0
        public void Features_can_add_array_properties_to_serialized_RunResult_by_implementing_IAugmentRunResult()
        {
            var result = new RunResult(true);

            result.AddFeature(new TestFeature <string[]>("array", new[] { "one", "two", "three" }));

            var json = result.ToJson().FromJsonTo <JObject>();

            var array = json.Property("array").Value.ToObject <string[]>();

            array.Should().Equal("one", "two", "three");
        }
コード例 #4
0
        public void Features_can_add_int_properties_to_serialized_RunResult_by_implementing_IAugmentRunResult()
        {
            var result = new RunResult(true);

            result.AddFeature(new TestFeature <int>("int", 123));

            var json = result.ToJson().FromJsonTo <dynamic>();

            var scalar = (int)json.@int;

            scalar.Should().Be(123);
        }
コード例 #5
0
        public void Features_can_add_string_properties_to_serialized_RunResult_by_implementing_IAugmentRunResult()
        {
            var result = new RunResult(true);

            result.AddFeature(new TestFeature <string>("string", "here i am!"));

            var json = result.ToJson().FromJsonTo <dynamic>();

            var scalar = (string)json.@string;

            scalar.Should().Be("here i am!");
        }
コード例 #6
0
        public void Disposable_RunResult_features_are_disposed_when_RunResult_is_disposed()
        {
            var wasDisposed = false;

            var result = new RunResult(true);

            result.AddFeature(new DisposableFeature(Disposable.Create(() => wasDisposed = true)));

            result.Dispose();

            wasDisposed.Should().BeTrue();
        }
コード例 #7
0
        public void Features_can_add_object_properties_to_serialized_RunResult_by_implementing_IAugmentRunResult()
        {
            var result = new RunResult(true);

            result.AddFeature(new TestFeature <TestClass>("object", new TestClass("a", 1)));

            var json = result.ToJson();

            var obj = json.FromJsonTo <JObject>().Property("object").Value.ToObject <TestClass>();

            obj.StringProperty.Should().Be("a");
            obj.IntProperty.Should().Be(1);
        }
コード例 #8
0
        public async Task <RunResult> Run(WorkspaceRequest request, Budget budget = null)
        {
            var workspace = request.Workspace;

            budget = budget ?? new TimeBudget(TimeSpan.FromSeconds(defaultBudgetInSeconds));

            using (Log.OnEnterAndExit())
                using (await locks.GetOrAdd(workspace.WorkspaceType, s => new AsyncLock()).LockAsync())
                {
                    var package = await _packageFinder.Find <Package>(workspace.WorkspaceType);

                    var result = await CompileWorker(request.Workspace, request.ActiveBufferId, budget);

                    if (result.ProjectDiagnostics.ContainsError())
                    {
                        var errorMessagesToDisplayInOutput = result.DiagnosticsWithinBuffers.Any()
                                                             ? result.DiagnosticsWithinBuffers.GetCompileErrorMessages()
                                                             : result.ProjectDiagnostics.GetCompileErrorMessages();

                        var runResult = new RunResult(
                            false,
                            errorMessagesToDisplayInOutput,
                            diagnostics: result.DiagnosticsWithinBuffers,
                            requestId: request.RequestId);

                        runResult.AddFeature(new ProjectDiagnostics(result.ProjectDiagnostics));

                        return(runResult);
                    }

                    await EmitCompilationAsync(result.Compilation, package);

                    if (package.IsWebProject)
                    {
                        return(RunWebRequest(package, request.RequestId));
                    }

                    if (package.IsUnitTestProject)
                    {
                        return(await RunUnitTestsAsync(package, result.DiagnosticsWithinBuffers, budget, request.RequestId));
                    }

                    return(await RunConsoleAsync(
                               package,
                               result.DiagnosticsWithinBuffers,
                               budget,
                               request.RequestId,
                               workspace.IncludeInstrumentation,
                               request.RunArgs));
                }
        }
コード例 #9
0
        private static async Task <RunResult> RunUnitTestsAsync(
            Package package,
            IEnumerable <SerializableDiagnostic> diagnostics,
            Budget budget,
            string requestId)
        {
            var dotnet = new Dotnet(package.Directory);

            var commandLineResult = await dotnet.VSTest(
                $@"--logger:trx ""{package.EntryPointAssemblyPath}""",
                budget);

            budget.RecordEntry(UserCodeCompleted);

            if (commandLineResult.ExitCode == 124)
            {
                throw new BudgetExceededException(budget);
            }

            var trex = new FileInfo(
                Path.Combine(
                    Paths.DotnetToolsPath,
                    "t-rex".ExecutableName()));

            if (!trex.Exists)
            {
                throw new InvalidOperationException($"t-rex not found in at location {trex}");
            }

            var tRexResult = await CommandLine.Execute(
                trex,
                "",
                workingDir : package.Directory,
                budget : budget);

            var result = new RunResult(
                commandLineResult.ExitCode == 0,
                tRexResult.Output,
                diagnostics: diagnostics,
                requestId: requestId);

            result.AddFeature(new UnitTestRun(new[]
            {
                new UnitTestResult()
            }));

            return(result);
        }