private Source GetSource(DsTestWriter testWriter, string specRelativePath) { string writerRoot = testWriter.RootPath != null?Path.Combine(TestRoot, testWriter.RootPath) : TestRoot; var pathTable = FrontEndContext.PathTable; // We do round trip in path conversion to get canonical representation. var sourceFullPath = AbsolutePath.Create(pathTable, Path.Combine(writerRoot, specRelativePath)).ToString(pathTable); var source = new Source(sourceFullPath); return(source); }
private List <Tuple <Source, SourceBreakpoint[]> > ComputeSourceBreakpoints(DsTestWriter testWriter) { var list = new List <Tuple <Source, SourceBreakpoint[]> >(); var files = testWriter.GetAllFiles(); foreach (var file in files) { var breakpoints = file.Item2 .Split(new[] { Environment.NewLine }, StringSplitOptions.None) .Select((str, idx) => s_breakpointRegex.Match(str).Success ? new SourceBreakpoint(idx + 1, column: null, condition: null) : null) .Where(b => b != null) .ToArray(); if (breakpoints.Length > 0) { list.Add(Tuple.Create(GetSource(testWriter, file.Item1), breakpoints)); } } return(list); }
/// <summary> /// Adds the prelude module to <see cref="DsTestWriter"/> necessary for V2 evaluations. /// </summary> internal new static void AddPrelude(DsTestWriter testWriter) { testWriter.ConfigWriter.AddBuildSpec(R("Sdk.Prelude", "prelude.dsc"), File.ReadAllText(R("Libs", "lib.core.d.ts"))); testWriter.ConfigWriter.AddBuildSpec(R("Sdk.Prelude", "package.config.dsc"), CreatePackageConfig(FrontEndHost.PreludeModuleName)); }
protected TestResult Debug(Func <ISource, Task> debuggerTest, DsTestWriter testWriter, string specRelativePath, string[] expressions, string qualifier = null, int evalTaskTimeoutMillis = EvalTaskTimeoutMillis) { var sourceBreakPoints = ComputeSourceBreakpoints(testWriter); var mainSource = GetSource(testWriter, specRelativePath); var evalTask = Task .Run(() => { var ans = Evaluate(testWriter, specRelativePath, expressions, qualifier: qualifier, parseOnly: false, isDebugged: true); if (ans.ErrorCount > 0) { Output?.WriteLine("Errors during evaluation:\r\n" + string.Join(Environment.NewLine, ans.Diagnostics)); } Debugger.ShutDown(); return(ans); }); var debuggerTestTask = Task .Run(async() => { Debugger.SendRequest(new InitializeCommand("DScript", true, true, "path")); await Debugger.ReceiveEvent <IInitializedEvent>(); foreach (var sourceBreakPoint in sourceBreakPoints) { Debugger.SendRequest(new SetBreakpointsCommand(sourceBreakPoint.Item1, sourceBreakPoint.Item2)); } Debugger.SendRequest(new AttachCommand()); await debuggerTest(mainSource); }) .ContinueWith(prevTask => { // if failed --> shut down debugger (to ensure liveness), rethrow exception if (prevTask.IsFaulted) { Debugger.ShutDown(); throw prevTask.Exception.InnerException; } // if didn't fail AND evaluation has stopped threads --> shut down debugger, throw EvaluationBlockedUponTestCompletionException if (!prevTask.IsFaulted && Debugger.State.GetStoppedThreadsClone().Any()) { Debugger.ShutDown(); string message = "DScript evaluation has stopped threads upon debugger test completion."; if (prevTask.IsFaulted) { message += " Failure: " + prevTask.Exception; } throw new EvaluationBlockedUponTestCompletionException(message); } // if didn't fail AND evaluation doesn't complete within 'evalTaskTimeoutMillis' --> throw EvaluationBlockedUponTestCompletionException if (!prevTask.IsFaulted && !evalTask.Wait(evalTaskTimeoutMillis)) { Debugger.ShutDown(); throw new EvaluationBlockedUponTestCompletionException("DScript evaluation timed out after debugger test completed."); } }); Task.WhenAll(evalTask, debuggerTestTask).Wait(); return(evalTask.Result); }