Exemple #1
0
        public void TestWorkspace()
        {
            var engine   = Init("Workspace.Chemistry");
            var snippets = engine.Snippets as Snippets;

            var wsMagic  = new WorkspaceMagic(snippets.Workspace);
            var pkgMagic = new PackageMagic(snippets.GlobalReferences);

            var channel = new MockChannel();
            var result  = new string[0];

            // Check the workspace, it should be in error state:
            var response = wsMagic.Execute("reload", channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);

            response = wsMagic.Execute("", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);

            // Try compiling a snippet that depends on a workspace that depends on the chemistry package:
            response = engine.ExecuteMundane(SNIPPETS.DependsOnChemistryWorkspace, channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);

            // Add dependencies:
            response = pkgMagic.Execute("microsoft.quantum.chemistry", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            response = pkgMagic.Execute("microsoft.quantum.research", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);

            // Reload workspace:
            response = wsMagic.Execute("reload", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);

            response = wsMagic.Execute("", channel);
            result   = response.Output as string[];
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            Assert.AreEqual(3, result.Length);

            // Now compilation must work:
            AssertCompile(engine, SNIPPETS.DependsOnChemistryWorkspace, "DependsOnChemistryWorkspace");

            // Check an invalid command
            response = wsMagic.Execute("foo", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);

            // Check that everything still works:
            response = wsMagic.Execute("", channel);
            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
        }
Exemple #2
0
        private async Task AssertTrace(string name, ExecutionPath expectedPath, int expectedDepth)
        {
            var engine       = Init("Workspace.ExecutionPathTracer");
            var snippets     = engine.Snippets as Snippets;
            var configSource = new ConfigurationSource(skipLoading: true);

            var wsMagic    = new WorkspaceMagic(snippets.Workspace);
            var pkgMagic   = new PackageMagic(snippets.GlobalReferences);
            var traceMagic = new TraceMagic(engine.SymbolsResolver, configSource);

            var channel = new MockChannel();

            // Add dependencies:
            var response = await pkgMagic.Execute("mock.standard", channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);

            // Reload workspace:
            response = await wsMagic.Execute("reload", channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);

            response = await traceMagic.Execute(name, channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);

            var message = channel.iopubMessages.ElementAtOrDefault(0);

            Assert.IsNotNull(message);
            Assert.AreEqual("render_execution_path", message.Header.MessageType);

            var content = message.Content as ExecutionPathVisualizerContent;

            Assert.IsNotNull(content);

            Assert.AreEqual(expectedDepth, content.RenderDepth);

            var path = content.ExecutionPath.ToObject <ExecutionPath>();

            Assert.IsNotNull(path);
            Assert.AreEqual(expectedPath.ToJson(), path.ToJson());
        }