test/integration/goDebug.ts: check for incorrect output event noDebug

Since there may be unrelated output events, the noDebug tests would
skip any output event that did not match the desired output. This
change checks for both the correct and the incorrect output value
("Hello, World!\n" and "Goodbye, World.\n") and checks that it
receives the correct one of the two, for better error messages and to
avoid requiring the test to time out.

Updates golang/vscode-go#1439

Change-Id: Idc9dac00df3406db757ba25ae9ea9a565f77954b
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/312749
Trust: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/test/integration/goDebug.test.ts b/test/integration/goDebug.test.ts
index d79e976..db42b10 100644
--- a/test/integration/goDebug.test.ts
+++ b/test/integration/goDebug.test.ts
@@ -706,7 +706,7 @@
 				name: 'Launch',
 				type: 'go',
 				request: 'launch',
-				mode: 'auto',
+				mode: 'debug',
 				program: PROGRAM,
 				cwd: WD
 			};
@@ -726,7 +726,7 @@
 				name: 'Launch',
 				type: 'go',
 				request: 'launch',
-				mode: 'auto',
+				mode: 'debug',
 				program: PROGRAM
 			};
 			const debugConfig = await initializeDebugConfig(config);
@@ -745,7 +745,7 @@
 				name: 'Launch',
 				type: 'go',
 				request: 'launch',
-				mode: 'auto',
+				mode: 'debug',
 				program: PROGRAM,
 				cwd: WD
 			};
@@ -765,7 +765,7 @@
 				name: 'Launch',
 				type: 'go',
 				request: 'launch',
-				mode: 'auto',
+				mode: 'debug',
 				program: PROGRAM
 			};
 			const debugConfig = await initializeDebugConfig(config);
@@ -775,6 +775,21 @@
 			await assertLocalVariableValue('strdat', '"Goodbye, World."');
 		});
 
+		async function waitForHelloGoodbyeOutput(dc: DebugClient, wantHello: boolean) {
+			let found = false;
+			while (!found) {
+				const event = await dc.waitForEvent('output');
+				if (event.body.output === 'Hello, World!\n' || event.body.output === 'Goodbye, World.\n') {
+					if (wantHello) {
+						assert.strictEqual(event.body.output, 'Hello, World!\n');
+					} else {
+						assert.strictEqual(event.body.output, 'Goodbye, World.\n');
+					}
+					found = true;
+				}
+			}
+		}
+
 		test('should run program with cwd set (noDebug)', async () => {
 			const WD = path.join(DATA_ROOT, 'cwdTest');
 			const PROGRAM = path.join(WD, 'cwdTest');
@@ -783,18 +798,14 @@
 				name: 'Launch',
 				type: 'go',
 				request: 'launch',
-				mode: 'auto',
+				mode: 'debug',
 				program: PROGRAM,
 				cwd: WD,
 				noDebug: true
 			};
 			const debugConfig = await initializeDebugConfig(config);
 			dc.launch(debugConfig);
-			let found = false;
-			while (!found) {
-				const event = await dc.waitForEvent('output');
-				found = event.body.output === 'Hello, World!\n';
-			}
+			await waitForHelloGoodbyeOutput(dc, true);
 		});
 
 		test('should run program without cwd set (noDebug)', async () => {
@@ -805,17 +816,13 @@
 				name: 'Launch',
 				type: 'go',
 				request: 'launch',
-				mode: 'auto',
+				mode: 'debug',
 				program: PROGRAM,
 				noDebug: true
 			};
 			const debugConfig = await initializeDebugConfig(config);
 			dc.launch(debugConfig);
-			let found = false;
-			while (!found) {
-				const event = await dc.waitForEvent('output');
-				found = event.body.output === 'Goodbye, World.\n';
-			}
+			await waitForHelloGoodbyeOutput(dc, false);
 		});
 
 		test('should run file program with cwd set (noDebug)', async () => {
@@ -826,20 +833,15 @@
 				name: 'Launch',
 				type: 'go',
 				request: 'launch',
-				mode: 'auto',
+				mode: 'debug',
 				program: PROGRAM,
 				cwd: WD,
 				noDebug: true
 			};
 			const debugConfig = await initializeDebugConfig(config);
 			dc.launch(debugConfig);
-			let found = false;
-			while (!found) {
-				const event = await dc.waitForEvent('output');
-				found = event.body.output === 'Hello, World!\n';
-			}
+			await waitForHelloGoodbyeOutput(dc, true);
 		});
-
 		test('should run file program without cwd set (noDebug)', async () => {
 			const WD = path.join(DATA_ROOT, 'cwdTest');
 			const PROGRAM = path.join(WD, 'cwdTest', 'main.go');
@@ -848,17 +850,13 @@
 				name: 'Launch',
 				type: 'go',
 				request: 'launch',
-				mode: 'auto',
+				mode: 'debug',
 				program: PROGRAM,
 				noDebug: true
 			};
 			const debugConfig = await initializeDebugConfig(config);
 			dc.launch(debugConfig);
-			let found = false;
-			while (!found) {
-				const event = await dc.waitForEvent('output');
-				found = event.body.output === 'Goodbye, World.\n';
-			}
+			await waitForHelloGoodbyeOutput(dc, false);
 		});
 	});