test/goDebug.test.ts: log dlv dap output to console

When there is a failure with the debug tests, it is very difficult
to determine the cause without more information being logged. This
change logs all output from dlv dap to the console during testing.

Change-Id: I74347858ceaf9ba3c20aa8aff6da03d5eb2b4fcf
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/303009
Trust: Suzy Mueller <suzmue@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/goDebugFactory.ts b/src/goDebugFactory.ts
index 5ebdef0..2f6f82e 100644
--- a/src/goDebugFactory.ts
+++ b/src/goDebugFactory.ts
@@ -193,7 +193,8 @@
 	return { program, dirname, programIsDirectory };
 }
 
-function appendToDebugConsole(msg: string) {
+// appendToDebugConsole is declared as an exported const rather than a function, so it can be stubbbed in testing.
+export const appendToDebugConsole = (msg: string) => {
 	// TODO(hyangah): use color distinguishable from the color used from print.
 	vscode.debug.activeDebugConsole.append(msg);
-}
+};
diff --git a/test/integration/goDebug.test.ts b/test/integration/goDebug.test.ts
index d10a312..0157c71 100644
--- a/test/integration/goDebug.test.ts
+++ b/test/integration/goDebug.test.ts
@@ -10,6 +10,7 @@
 import { tmpdir } from 'os';
 import * as path from 'path';
 import * as sinon from 'sinon';
+import * as factory from '../../src/goDebugFactory';
 import { DebugConfiguration } from 'vscode';
 import { DebugClient } from 'vscode-debugadapter-testsupport';
 import { ILocation } from 'vscode-debugadapter-testsupport/lib/debugClient';
@@ -315,6 +316,11 @@
 
 			// Launching delve may take longer than the default timeout of 5000.
 			dc.defaultTimeout = 20_000;
+
+			// Change the output to be printed to the console.
+			sinon.stub(factory, 'appendToDebugConsole').callsFake((msg: string) => {
+				console.log(msg);
+			});
 			return;
 		}
 
@@ -325,7 +331,10 @@
 		await dc.start();
 	});
 
-	teardown(async () => await dc.stop());
+	teardown(async () => {
+		await dc.stop();
+		sinon.restore();
+	});
 
 	/**
 	 * This function sets up a server that returns helloworld on serverPort.
@@ -1142,7 +1151,6 @@
 					.then(() => {
 						return dc.configurationDoneRequest();
 					}),
-
 				dc.launch(debugConfig),
 
 				dc.assertStoppedLocation('breakpoint', location)
@@ -1672,6 +1680,11 @@
 	});
 
 	async function initializeDebugConfig(config: DebugConfiguration) {
+		if (isDlvDap) {
+			config['logOutput'] = 'dap';
+			config['showLog'] = true;
+		}
+
 		const debugConfig = await debugConfigProvider.resolveDebugConfiguration(undefined, config);
 		if (isDlvDap) {
 			const { port } = await startDapServer(debugConfig);