diff --git a/src/integration-tests/attachRemote.spec.ts b/src/integration-tests/attachRemote.spec.ts index 99493fc8..81517642 100644 --- a/src/integration-tests/attachRemote.spec.ts +++ b/src/integration-tests/attachRemote.spec.ts @@ -15,8 +15,12 @@ import { TargetAttachArguments, } from '../GDBTargetDebugSession'; import { CdtDebugClient } from './debugClient'; -import { standardBeforeEach, testProgramsDir, gdbServerPath } from './utils'; -import { gdbPath, openGdbConsole, gdbAsync, gdbNonStop } from './utils'; +import { + standardBeforeEach, + testProgramsDir, + gdbServerPath, + fillDefaults, +} from './utils'; describe('attach remote', function () { let dc: CdtDebugClient; @@ -61,18 +65,13 @@ describe('attach remote', function () { it('can attach remote and hit a breakpoint', async function () { await dc.hitBreakpoint( - { - verbose: true, - gdb: gdbPath, + fillDefaults(this.test, { program: emptyProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, target: { type: 'remote', parameters: [`localhost:${port}`], } as TargetAttachArguments, - } as TargetAttachRequestArguments, + } as TargetAttachRequestArguments), { path: emptySrc, line: 3, diff --git a/src/integration-tests/breakpoints.spec.ts b/src/integration-tests/breakpoints.spec.ts index 453b0f0b..4e09723f 100644 --- a/src/integration-tests/breakpoints.spec.ts +++ b/src/integration-tests/breakpoints.spec.ts @@ -10,36 +10,27 @@ import * as path from 'path'; import { expect } from 'chai'; -import { LaunchRequestArguments } from '../GDBDebugSession'; import { CdtDebugClient } from './debugClient'; import { standardBeforeEach, - gdbPath, testProgramsDir, - openGdbConsole, - gdbAsync, - gdbNonStop, getScopes, verifyVariable, gdbVersionAtLeast, + fillDefaults, } from './utils'; import { DebugProtocol } from '@vscode/debugprotocol'; -describe('breakpoints', async () => { +describe('breakpoints', async function () { let dc: CdtDebugClient; - beforeEach(async () => { + beforeEach(async function () { dc = await standardBeforeEach(); - - await dc.launchRequest({ - verbose: true, - gdb: gdbPath, - program: path.join(testProgramsDir, 'count'), - openGdbConsole, - gdbAsync, - gdbNonStop, - logFile: '/tmp/log', - } as LaunchRequestArguments); + await dc.launchRequest( + fillDefaults(this.currentTest, { + program: path.join(testProgramsDir, 'count'), + }) + ); }); afterEach(async () => { diff --git a/src/integration-tests/diassemble.spec.ts b/src/integration-tests/diassemble.spec.ts index 1abe53b6..ed427ea6 100644 --- a/src/integration-tests/diassemble.spec.ts +++ b/src/integration-tests/diassemble.spec.ts @@ -11,16 +11,8 @@ import { expect } from 'chai'; import * as path from 'path'; import { DebugProtocol } from '@vscode/debugprotocol/lib/debugProtocol'; -import { LaunchRequestArguments } from '../GDBDebugSession'; import { CdtDebugClient } from './debugClient'; -import { - gdbPath, - openGdbConsole, - gdbAsync, - gdbNonStop, - standardBeforeEach, - testProgramsDir, -} from './utils'; +import { fillDefaults, standardBeforeEach, testProgramsDir } from './utils'; describe('Disassembly Test Suite', function () { let dc: CdtDebugClient; @@ -32,13 +24,9 @@ describe('Disassembly Test Suite', function () { dc = await standardBeforeEach(); await dc.hitBreakpoint( - { - gdb: gdbPath, + fillDefaults(this.currentTest, { program: disProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments, + }), { path: disSrc, line: 2, diff --git a/src/integration-tests/evaluate.spec.ts b/src/integration-tests/evaluate.spec.ts index 94ef1596..159512d7 100644 --- a/src/integration-tests/evaluate.spec.ts +++ b/src/integration-tests/evaluate.spec.ts @@ -13,11 +13,8 @@ import * as path from 'path'; import { CdtDebugClient } from './debugClient'; import { expectRejection, - gdbPath, + fillDefaults, getScopes, - openGdbConsole, - gdbAsync, - gdbNonStop, Scope, standardBeforeEach, testProgramsDir, @@ -37,14 +34,9 @@ describe('evaluate request', function () { } dc = await standardBeforeEach(); await dc.hitBreakpoint( - { - verbose: true, - gdb: gdbPath, + fillDefaults(this.currentTest, { program: evaluateProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, - }, + }), { path: evaluateSrc, line: 2, diff --git a/src/integration-tests/functionBreakpoints.spec.ts b/src/integration-tests/functionBreakpoints.spec.ts index 6226beea..7a020ff7 100644 --- a/src/integration-tests/functionBreakpoints.spec.ts +++ b/src/integration-tests/functionBreakpoints.spec.ts @@ -12,31 +12,24 @@ import * as path from 'path'; import { expect } from 'chai'; import { join } from 'path'; import { CdtDebugClient } from './debugClient'; -import { LaunchRequestArguments } from '../GDBDebugSession'; import { standardBeforeEach, - gdbPath, testProgramsDir, - openGdbConsole, - gdbAsync, - gdbNonStop, getScopes, + fillDefaults, } from './utils'; -describe('function breakpoints', async () => { +describe('function breakpoints', async function () { let dc: CdtDebugClient; - beforeEach(async () => { + beforeEach(async function () { dc = await standardBeforeEach(); - await dc.launchRequest({ - verbose: true, - gdb: gdbPath, - program: join(testProgramsDir, 'functions'), - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments); + await dc.launchRequest( + fillDefaults(this.currentTest, { + program: join(testProgramsDir, 'functions'), + }) + ); }); afterEach(async () => { diff --git a/src/integration-tests/launch.spec.ts b/src/integration-tests/launch.spec.ts index d3f361e5..1a3e31aa 100644 --- a/src/integration-tests/launch.spec.ts +++ b/src/integration-tests/launch.spec.ts @@ -12,8 +12,7 @@ import { expect } from 'chai'; import * as path from 'path'; import { LaunchRequestArguments } from '../GDBDebugSession'; import { CdtDebugClient } from './debugClient'; -import { standardBeforeEach, testProgramsDir } from './utils'; -import { gdbPath, openGdbConsole, gdbAsync, gdbNonStop } from './utils'; +import { fillDefaults, standardBeforeEach, testProgramsDir } from './utils'; describe('launch', function () { let dc: CdtDebugClient; @@ -37,14 +36,9 @@ describe('launch', function () { it('can launch and hit a breakpoint', async function () { await dc.hitBreakpoint( - { - verbose: true, - gdb: gdbPath, + fillDefaults(this.test, { program: emptyProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments, + } as LaunchRequestArguments), { path: emptySrc, line: 3, @@ -54,14 +48,11 @@ describe('launch', function () { it('reports an error when specifying a non-existent binary', async function () { const errorMessage = await new Promise((resolve, reject) => { - dc.launchRequest({ - verbose: true, - gdb: gdbPath, - program: '/does/not/exist', - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments) + dc.launchRequest( + fillDefaults(this.test, { + program: '/does/not/exist', + } as LaunchRequestArguments) + ) .then(reject) .catch(resolve); }); @@ -79,14 +70,9 @@ describe('launch', function () { it('works with a space in file names', async function () { await dc.hitBreakpoint( - { - verbose: true, - gdb: gdbPath, + fillDefaults(this.test, { program: emptySpaceProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments, + } as LaunchRequestArguments), { path: emptySpaceSrc, line: 3, diff --git a/src/integration-tests/launchRemote.spec.ts b/src/integration-tests/launchRemote.spec.ts index ad44e311..60672705 100644 --- a/src/integration-tests/launchRemote.spec.ts +++ b/src/integration-tests/launchRemote.spec.ts @@ -14,8 +14,7 @@ import { TargetLaunchArguments, } from '../GDBTargetDebugSession'; import { CdtDebugClient } from './debugClient'; -import { standardBeforeEach, testProgramsDir } from './utils'; -import { gdbPath, openGdbConsole, gdbAsync, gdbNonStop } from './utils'; +import { fillDefaults, standardBeforeEach, testProgramsDir } from './utils'; describe('launch remote', function () { let dc: CdtDebugClient; @@ -37,17 +36,12 @@ describe('launch remote', function () { it('can launch remote and hit a breakpoint', async function () { await dc.hitBreakpoint( - { - verbose: true, - gdb: gdbPath, + fillDefaults(this.test, { program: emptyProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, target: { type: 'remote', } as TargetLaunchArguments, - } as TargetLaunchRequestArguments, + } as TargetLaunchRequestArguments), { path: emptySrc, line: 3, diff --git a/src/integration-tests/logpoints.spec.ts b/src/integration-tests/logpoints.spec.ts index 1e0d6ce3..ef35cf1b 100644 --- a/src/integration-tests/logpoints.spec.ts +++ b/src/integration-tests/logpoints.spec.ts @@ -11,30 +11,19 @@ import { join } from 'path'; import { expect } from 'chai'; import { CdtDebugClient } from './debugClient'; -import { LaunchRequestArguments } from '../GDBDebugSession'; -import { - standardBeforeEach, - gdbPath, - testProgramsDir, - openGdbConsole, - gdbAsync, - gdbNonStop, -} from './utils'; +import { fillDefaults, standardBeforeEach, testProgramsDir } from './utils'; describe('logpoints', async () => { let dc: CdtDebugClient; - beforeEach(async () => { + beforeEach(async function () { dc = await standardBeforeEach(); - await dc.launchRequest({ - verbose: true, - gdb: gdbPath, - program: join(testProgramsDir, 'count'), - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments); + await dc.launchRequest( + fillDefaults(this.currentTest, { + program: join(testProgramsDir, 'count'), + }) + ); }); afterEach(async () => { diff --git a/src/integration-tests/mem-cdt-custom.spec.ts b/src/integration-tests/mem-cdt-custom.spec.ts index 708f9b85..51a3cb9f 100644 --- a/src/integration-tests/mem-cdt-custom.spec.ts +++ b/src/integration-tests/mem-cdt-custom.spec.ts @@ -11,14 +11,11 @@ import { expect } from 'chai'; import * as path from 'path'; import { DebugProtocol } from '@vscode/debugprotocol/lib/debugProtocol'; -import { LaunchRequestArguments, MemoryResponse } from '../GDBDebugSession'; +import { MemoryResponse } from '../GDBDebugSession'; import { CdtDebugClient } from './debugClient'; import { expectRejection, - gdbPath, - openGdbConsole, - gdbAsync, - gdbNonStop, + fillDefaults, standardBeforeEach, testProgramsDir, } from './utils'; @@ -33,13 +30,9 @@ describe('Memory Test Suite for cdt-gdb-adapter/Memory custom request', function dc = await standardBeforeEach(); await dc.hitBreakpoint( - { - gdb: gdbPath, + fillDefaults(this.currentTest, { program: memProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments, + }), { path: memSrc, line: 12, diff --git a/src/integration-tests/mem.spec.ts b/src/integration-tests/mem.spec.ts index bf2e8cb1..7ab5f177 100644 --- a/src/integration-tests/mem.spec.ts +++ b/src/integration-tests/mem.spec.ts @@ -11,18 +11,11 @@ import { expect } from 'chai'; import * as path from 'path'; import { DebugProtocol } from '@vscode/debugprotocol/lib/debugProtocol'; -import { - base64ToHex, - hexToBase64, - LaunchRequestArguments, -} from '../GDBDebugSession'; +import { base64ToHex, hexToBase64 } from '../GDBDebugSession'; import { CdtDebugClient } from './debugClient'; import { expectRejection, - gdbPath, - openGdbConsole, - gdbAsync, - gdbNonStop, + fillDefaults, standardBeforeEach, testProgramsDir, } from './utils'; @@ -37,13 +30,9 @@ describe('Memory Test Suite', function () { dc = await standardBeforeEach(); await dc.hitBreakpoint( - { - gdb: gdbPath, + fillDefaults(this.currentTest, { program: memProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments, + }), { path: memSrc, line: 12, diff --git a/src/integration-tests/multithread.spec.ts b/src/integration-tests/multithread.spec.ts index 1610ecdd..136626a9 100644 --- a/src/integration-tests/multithread.spec.ts +++ b/src/integration-tests/multithread.spec.ts @@ -10,14 +10,12 @@ import { CdtDebugClient } from './debugClient'; import { standardBeforeEach, - gdbPath, testProgramsDir, - openGdbConsole, - gdbAsync, resolveLineTagLocations, isRemoteTest, + gdbNonStop, + fillDefaults, } from './utils'; -import { LaunchRequestArguments } from '../GDBDebugSession'; import { expect } from 'chai'; import * as path from 'path'; import { fail } from 'assert'; @@ -54,17 +52,20 @@ describe('multithread', async function () { await dc.stop(); }); - const testCommon = async (nonStop: boolean) => { + it('sees all threads (all-stop)', async function () { + if (!gdbNonStop && os.platform() === 'win32' && isRemoteTest) { + // The way thread names are set in remote tests on windows is unsupported + this.skip(); + } + if (gdbNonStop && os.platform() === 'win32') { + // non-stop unsupported on Windows + this.skip(); + } + await dc.hitBreakpoint( - { - verbose: true, - gdb: gdbPath, + fillDefaults(this.test, { program: program, - openGdbConsole, - gdbAsync, - logFile: '/tmp/log', - gdbNonStop: nonStop, - } as LaunchRequestArguments, + }), { path: source, line: lineTags['LINE_MAIN_ALL_THREADS_STARTED'], @@ -92,7 +93,7 @@ describe('multithread', async function () { fail('unreachable'); } - if (nonStop) { + if (gdbNonStop) { const waitForStopped = dc.waitForEvent('stopped'); const pr = dc.pauseRequest({ threadId }); await Promise.all([pr, waitForStopped]); @@ -125,21 +126,5 @@ describe('multithread', async function () { // extracted nul terminated string expect(varnameToValue.get('name')).to.contain(name); } - }; - - it('sees all threads (all-stop)', async function () { - if (os.platform() === 'win32' && isRemoteTest) { - // The way thread names are set in remote tests on windows is unsupported - this.skip(); - } - await testCommon(false); - }); - - it('sees all threads (non-stop)', async function () { - if (os.platform() === 'win32') { - // non-stop unsupported on Windows - this.skip(); - } - await testCommon(true); }); }); diff --git a/src/integration-tests/pause.spec.ts b/src/integration-tests/pause.spec.ts index 36dbbee2..b3603d35 100644 --- a/src/integration-tests/pause.spec.ts +++ b/src/integration-tests/pause.spec.ts @@ -10,14 +10,11 @@ import { CdtDebugClient } from './debugClient'; import { standardBeforeEach, - gdbPath, testProgramsDir, - openGdbConsole, gdbAsync, - gdbNonStop, isRemoteTest, + fillDefaults, } from './utils'; -import { LaunchRequestArguments } from '../GDBDebugSession'; import * as path from 'path'; import * as os from 'os'; @@ -37,15 +34,11 @@ describe('pause', async () => { // win32 host can only pause remote + mi-async targets this.skip(); } - await dc.launchRequest({ - verbose: true, - gdb: gdbPath, - program: path.join(testProgramsDir, 'loopforever'), - openGdbConsole, - gdbAsync, - gdbNonStop, - logFile: '/tmp/log', - } as LaunchRequestArguments); + await dc.launchRequest( + fillDefaults(this.test, { + program: path.join(testProgramsDir, 'loopforever'), + }) + ); await dc.configurationDoneRequest(); const waitForStopped = dc.waitForEvent('stopped'); const threads = await dc.threadsRequest(); diff --git a/src/integration-tests/stop.spec.ts b/src/integration-tests/stop.spec.ts index 1a018812..15361473 100644 --- a/src/integration-tests/stop.spec.ts +++ b/src/integration-tests/stop.spec.ts @@ -8,15 +8,7 @@ * SPDX-License-Identifier: EPL-2.0 *********************************************************************/ import { CdtDebugClient } from './debugClient'; -import { - standardBeforeEach, - gdbPath, - testProgramsDir, - openGdbConsole, - gdbAsync, - gdbNonStop, -} from './utils'; -import { LaunchRequestArguments } from '../GDBDebugSession'; +import { fillDefaults, standardBeforeEach, testProgramsDir } from './utils'; import { expect } from 'chai'; import * as path from 'path'; @@ -31,15 +23,12 @@ describe('stop', async () => { await dc.stop(); }); - it('handles segv', async () => { - await dc.launchRequest({ - verbose: true, - gdb: gdbPath, - program: path.join(testProgramsDir, 'segv'), - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments); + it('handles segv', async function () { + await dc.launchRequest( + fillDefaults(this.test, { + program: path.join(testProgramsDir, 'segv'), + }) + ); await dc.configurationDoneRequest(); const stoppedEvent = await dc.waitForEvent('stopped'); expect(stoppedEvent.body.reason).to.eq('SIGSEGV'); diff --git a/src/integration-tests/utils.ts b/src/integration-tests/utils.ts index 23fdea52..17384016 100644 --- a/src/integration-tests/utils.ts +++ b/src/integration-tests/utils.ts @@ -16,6 +16,8 @@ import * as os from 'os'; import { DebugProtocol } from '@vscode/debugprotocol'; import { CdtDebugClient } from './debugClient'; import { compareVersions, getGdbVersion } from '../util'; +import { Runnable } from 'mocha'; +import { RequestArguments } from '../GDBDebugSession'; export interface Scope { thread: DebugProtocol.Thread; @@ -212,6 +214,24 @@ export async function standardBeforeEach( return dc; } +export function fillDefaults( + test?: Runnable, + argsIn?: RequestArguments +): RequestArguments { + if (!test) { + throw new Error( + 'A Test object is required (this.test in test body or this.currentTest in beforeEach' + ); + } + const args = argsIn !== undefined ? argsIn : ({} as RequestArguments); + args.verbose = true; + args.gdb = gdbPath; + args.openGdbConsole = openGdbConsole; + args.gdbAsync = gdbAsync; + args.gdbNonStop = gdbNonStop; + return args; +} + export const openGdbConsole: boolean = process.argv.indexOf('--run-in-terminal') !== -1; export const isRemoteTest: boolean = diff --git a/src/integration-tests/var.spec.ts b/src/integration-tests/var.spec.ts index 75c7fc81..8e706bf8 100644 --- a/src/integration-tests/var.spec.ts +++ b/src/integration-tests/var.spec.ts @@ -10,20 +10,16 @@ import { expect } from 'chai'; import * as path from 'path'; -import { LaunchRequestArguments } from '..'; import { CdtDebugClient } from './debugClient'; import { - gdbPath, getScopes, - openGdbConsole, - gdbAsync, - gdbNonStop, resolveLineTagLocations, Scope, standardBeforeEach, testProgramsDir, verifyVariable, verifyRegister, + fillDefaults, } from './utils'; import * as chai from 'chai'; import * as chaistring from 'chai-string'; @@ -51,14 +47,9 @@ describe('Variables Test Suite', function () { dc = await standardBeforeEach(); await dc.hitBreakpoint( - { - verbose: true, - gdb: gdbPath, + fillDefaults(this.currentTest, { program: varsProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments, + }), { path: varsSrc, line: lineTags['STOP HERE'], diff --git a/src/integration-tests/vars_cpp.spec.ts b/src/integration-tests/vars_cpp.spec.ts index dfd60b2f..51e4657d 100644 --- a/src/integration-tests/vars_cpp.spec.ts +++ b/src/integration-tests/vars_cpp.spec.ts @@ -10,21 +10,17 @@ import { expect } from 'chai'; import * as path from 'path'; -import { LaunchRequestArguments } from '..'; import { CdtDebugClient } from './debugClient'; import { compareVariable, - gdbPath, getScopes, - openGdbConsole, - gdbAsync, - gdbNonStop, resolveLineTagLocations, Scope, standardBeforeEach, testProgramsDir, verifyVariable, isRemoteTest, + fillDefaults, } from './utils'; describe('Variables CPP Test Suite', function () { @@ -54,14 +50,9 @@ describe('Variables CPP Test Suite', function () { beforeEach(async function () { dc = await standardBeforeEach(); await dc.hitBreakpoint( - { - verbose: true, - gdb: gdbPath, + fillDefaults(this.currentTest, { program: varsCppProgram, - openGdbConsole, - gdbAsync, - gdbNonStop, - } as LaunchRequestArguments, + }), { path: varsCppSrc, line: lineTags['STOP HERE'],