link test

This commit is contained in:
Aaron Munger 2023-10-13 15:22:51 -07:00 committed by Aaron Munger
parent 8e8811a5c1
commit 315f158d20
3 changed files with 40 additions and 3 deletions

View file

@ -7,7 +7,7 @@ import type { ActivationFunction, OutputItem, RendererContext } from 'vscode-not
import { createOutputContent, appendOutput, scrollableClass } from './textHelper';
import { HtmlRenderingHook, IDisposable, IRichRenderContext, JavaScriptRenderingHook, OutputWithAppend, RenderOptions } from './rendererTypes';
import { ttPolicy } from './htmlHelper';
import { cleanStackTrace } from './stackTraceHelper';
import { formatStackTrace } from './stackTraceHelper';
function clearContainer(container: HTMLElement) {
while (container.firstChild) {
@ -173,7 +173,7 @@ function renderError(
if (err.stack) {
outputElement.classList.add('traceback');
const stackTrace = cleanStackTrace(err.stack);
const stackTrace = formatStackTrace(err.stack);
const outputScrolling = scrollingEnabled(outputInfo, ctx.settings);
const content = createOutputContent(outputInfo.id, stackTrace ?? '', { linesLimit: ctx.settings.lineLimit, scrollable: outputScrolling, trustHtml });

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export function cleanStackTrace(stack: string) {
export function formatStackTrace(stack: string) {
let cleaned: string;
// Ansi colors are described here:
// https://en.wikipedia.org/wiki/ANSI_escape_code under the SGR section

View file

@ -0,0 +1,37 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { formatStackTrace } from '../stackTraceHelper';
import * as assert from 'assert';
suite('StackTraceHelper', () => {
test('Non Ipython stack trace is left alone', () => {
const stack = 'DivideError: integer division error\n' +
'Stacktrace:\n' +
'[1] divide_by_zero(x:: Int64)\n' +
'@Main c:\\src\\test\\3\\otherlanguages\\julia.ipynb: 3\n' +
'[2] top - level scope\n' +
'@c:\\src\\test\\3\\otherlanguages\\julia.ipynb: 1; ';
assert.equal(formatStackTrace(stack), stack);
});
test('IPython cell references are linkified', () => {
const stack =
'---------------------------------------------------------------------------\n' +
'Exception Traceback(most recent call last)\n' +
'Cell In[3], line 2\n' +
' 1 import myLib\n' +
'----> 2 myLib.throwEx()\n' +
'\n' +
'File C:\\venvs\\myLib.py:2, in throwEx()\n' +
' 1 def throwEx():\n' +
'----> 2 raise Exception\n';
const formatted = formatStackTrace(stack);
assert.ok(formatted.indexOf);
});
});