public async Task InitializeAsync() { var initializationFileName = UseDefaultInitializationFile ? "CSharpInteractive.rsp" : null; await Host.ResetAsync(InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName, CultureInfo.InvariantCulture, DefaultPlatform)); // assert and remove logo: var output = SplitLines(await ReadOutputToEnd()); var errorOutput = await ReadErrorOutputToEnd(); AssertEx.AssertEqualToleratingWhitespaceDifferences("", errorOutput); var expectedOutput = new List <string>(); expectedOutput.Add(string.Format(CSharpScriptingResources.LogoLine1, CommonCompiler.GetProductVersion(typeof(CSharpReplServiceProvider)))); if (UseDefaultInitializationFile) { expectedOutput.Add(string.Format(InteractiveHostResources.Loading_context_from_0, initializationFileName)); } expectedOutput.Add(InteractiveHostResources.Type_Sharphelp_for_more_information); AssertEx.Equal(expectedOutput, output); // remove logo: ClearOutput(); }
public async Task Bitness() { await Host.ExecuteAsync(@"System.IntPtr.Size"); AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd()); AssertEx.AssertEqualToleratingWhitespaceDifferences("8\r\n", await ReadOutputToEnd()); await Host.ResetAsync(InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Desktop32)); AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd()); AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadOutputToEnd()); await Host.ExecuteAsync(@"System.IntPtr.Size"); AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd()); AssertEx.AssertEqualToleratingWhitespaceDifferences("4\r\n", await ReadOutputToEnd()); var result = await Host.ResetAsync(InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Core)); AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd()); AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadOutputToEnd()); await Host.ExecuteAsync(@"System.IntPtr.Size"); AssertEx.AssertEqualToleratingWhitespaceDifferences("", await ReadErrorOutputToEnd()); AssertEx.AssertEqualToleratingWhitespaceDifferences("8\r\n", await ReadOutputToEnd()); }
private async Task TestKillAfterAsync(int milliseconds) { using var host = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: 1, joinOutputWritingThreadsOnDisposal: true); var options = InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Desktop64); host.InteractiveHostProcessCreated += new Action <Process>(proc => { _ = Task.Run(async() => { await Task.Delay(milliseconds).ConfigureAwait(false); try { proc.Kill(); } catch { } }); }); await host.ResetAsync(options).ConfigureAwait(false); for (int j = 0; j < 10; j++) { await host.ExecuteAsync("1+1").ConfigureAwait(false); } }
public async Task RestartHost() { ClearOutput(); await Host.ResetAsync( InteractiveHostOptions.CreateFromDirectory( TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Desktop64 ) ); }
private async Task <ExecutionResult> ResetAsyncWorker(bool initialize = true) { try { var options = new InteractiveHostOptions( initializationFile: initialize ? _responseFilePath : null, culture: CultureInfo.CurrentUICulture); var result = await _interactiveHost.ResetAsync(options).ConfigureAwait(false); if (result.Success) { UpdateResolvers(result); } return(new ExecutionResult(result.Success)); } catch (Exception e) when(FatalError.Report(e)) { throw ExceptionUtilities.Unreachable; } }
/// <summary> /// Invoked by <see cref="InteractiveHost"/> when a new process is being started. /// </summary> private void ProcessStarting(InteractiveHostOptions options) { if (!Dispatcher.CheckAccess()) { Dispatcher.BeginInvoke(new Action(() => ProcessStarting(options))); return; } // Freeze all existing classifications and then clear the list of // submission buffers we have. FreezeClassifications(); _submissionBuffers.Clear(); // We always start out empty _workspace.ClearSolution(); _currentSubmissionProjectId = null; _previousSubmissionProjectId = null; var metadataService = _workspace.CurrentSolution.Services.MetadataService; ImmutableArray <string> referencePaths; // reset configuration: if (File.Exists(_responseFilePath)) { // The base directory for relative paths is the directory that contains the .rsp file. // Note that .rsp files included by this .rsp file will share the base directory (Dev10 behavior of csc/vbc). var rspArguments = this.CommandLineParser.Parse(new[] { "@" + _responseFilePath }, Path.GetDirectoryName(_responseFilePath), null /* TODO: pass a valid value*/); referencePaths = rspArguments.ReferencePaths; // the base directory for references specified in the .rsp file is the .rsp file directory: var rspMetadataReferenceResolver = new GacFileResolver( referencePaths, baseDirectory: rspArguments.BaseDirectory, architectures: GacFileResolver.Default.Architectures, // TODO (tomat) preferredCulture: System.Globalization.CultureInfo.CurrentCulture); // TODO (tomat) var metadataProvider = metadataService.GetProvider(); // ignore unresolved references, they will be reported in the interactive window: var rspReferences = rspArguments.ResolveMetadataReferences(new AssemblyReferenceResolver(rspMetadataReferenceResolver, metadataProvider)) .Where(r => !(r is UnresolvedMetadataReference)); var interactiveHelpersRef = metadataService.GetReference(typeof(Script).Assembly.Location, MetadataReferenceProperties.Assembly); var interactiveHostObjectRef = metadataService.GetReference(typeof(InteractiveHostObject).Assembly.Location, MetadataReferenceProperties.Assembly); _references = ImmutableHashSet.Create <MetadataReference>( interactiveHelpersRef, interactiveHostObjectRef) .Union(rspReferences); // we need to create projects for these: _rspSourceFiles = rspArguments.SourceFiles; } else { var mscorlibRef = metadataService.GetReference(typeof(object).Assembly.Location, MetadataReferenceProperties.Assembly); _references = ImmutableHashSet.Create <MetadataReference>(mscorlibRef); _rspSourceFiles = ImmutableArray.Create <CommandLineSourceFile>(); referencePaths = ScriptOptions.Default.SearchPaths; } // reset search paths, working directory: _metadataReferenceResolver = new GacFileResolver( referencePaths, baseDirectory: _initialWorkingDirectory, architectures: GacFileResolver.Default.Architectures, // TODO (tomat) preferredCulture: System.Globalization.CultureInfo.CurrentCulture); // TODO (tomat) _sourceSearchPaths = InteractiveHost.Service.DefaultSourceSearchPaths; // create the first submission project in the workspace after reset: if (_currentSubmissionBuffer != null) { AddSubmission(_currentTextView, _currentSubmissionBuffer); } }