|
| 1 | +/********************************************************************* |
| 2 | + * Copyright (c) 2023 Kichwa Coders Canada Inc. and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made |
| 5 | + * available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + *********************************************************************/ |
| 10 | + |
| 11 | +import * as path from 'path'; |
| 12 | +import * as tmp from 'tmp'; |
| 13 | +import * as fs from 'fs'; |
| 14 | +import { |
| 15 | + LaunchRequestArguments, |
| 16 | + AttachRequestArguments, |
| 17 | +} from '../GDBDebugSession'; |
| 18 | +import { |
| 19 | + debugServerPort, |
| 20 | + defaultAdapter, |
| 21 | + fillDefaults, |
| 22 | + standardBeforeEach, |
| 23 | + testProgramsDir, |
| 24 | +} from './utils'; |
| 25 | + |
| 26 | +describe('config', function () { |
| 27 | + const emptyProgram = path.join(testProgramsDir, 'empty'); |
| 28 | + const emptySrc = path.join(testProgramsDir, 'empty.c'); |
| 29 | + |
| 30 | + async function verifyLaunchWorks( |
| 31 | + test: Mocha.Context, |
| 32 | + commandLine: string[], |
| 33 | + requestArgs: LaunchRequestArguments |
| 34 | + ) { |
| 35 | + if (debugServerPort) { |
| 36 | + // This test requires launching the adapter to work |
| 37 | + test.skip(); |
| 38 | + } |
| 39 | + |
| 40 | + const dc = await standardBeforeEach(defaultAdapter, commandLine); |
| 41 | + |
| 42 | + try { |
| 43 | + await dc.hitBreakpoint(fillDefaults(test.test, requestArgs), { |
| 44 | + path: emptySrc, |
| 45 | + line: 3, |
| 46 | + }); |
| 47 | + } finally { |
| 48 | + await dc.stop(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + it('can specify program via --config=', async function () { |
| 53 | + const config = { program: emptyProgram }; |
| 54 | + await verifyLaunchWorks( |
| 55 | + this, |
| 56 | + [`--config=${JSON.stringify(config)}`], |
| 57 | + {} as LaunchRequestArguments |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + it('program via --config= can be overridden', async function () { |
| 62 | + const config = { program: '/program/that/does/not/exist' }; |
| 63 | + await verifyLaunchWorks(this, [`--config=${JSON.stringify(config)}`], { |
| 64 | + program: emptyProgram, |
| 65 | + } as LaunchRequestArguments); |
| 66 | + }); |
| 67 | + |
| 68 | + it('can specify program via --config-frozen=', async function () { |
| 69 | + const config = { program: emptyProgram }; |
| 70 | + await verifyLaunchWorks( |
| 71 | + this, |
| 72 | + [`--config-frozen=${JSON.stringify(config)}`], |
| 73 | + {} as LaunchRequestArguments |
| 74 | + ); |
| 75 | + }); |
| 76 | + |
| 77 | + it('program via --config-frozen= can not be overridden', async function () { |
| 78 | + const config = { program: emptyProgram }; |
| 79 | + await verifyLaunchWorks( |
| 80 | + this, |
| 81 | + [`--config-frozen=${JSON.stringify(config)}`], |
| 82 | + { |
| 83 | + program: '/program/that/does/not/exist', |
| 84 | + } as LaunchRequestArguments |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + it('can specify program via --config= using response file', async function () { |
| 89 | + const config = { program: emptyProgram }; |
| 90 | + const json = JSON.stringify(config); |
| 91 | + const jsonFile = tmp.fileSync(); |
| 92 | + fs.writeFileSync(jsonFile.fd, json); |
| 93 | + fs.closeSync(jsonFile.fd); |
| 94 | + |
| 95 | + await verifyLaunchWorks( |
| 96 | + this, |
| 97 | + [`--config=@${jsonFile.name}`], |
| 98 | + {} as LaunchRequestArguments |
| 99 | + ); |
| 100 | + }); |
| 101 | + |
| 102 | + it('can specify program via --config-frozen= using response file', async function () { |
| 103 | + const config = { program: emptyProgram }; |
| 104 | + const json = JSON.stringify(config); |
| 105 | + const jsonFile = tmp.fileSync(); |
| 106 | + fs.writeFileSync(jsonFile.fd, json); |
| 107 | + fs.closeSync(jsonFile.fd); |
| 108 | + |
| 109 | + await verifyLaunchWorks( |
| 110 | + this, |
| 111 | + [`--config-frozen=@${jsonFile.name}`], |
| 112 | + {} as LaunchRequestArguments |
| 113 | + ); |
| 114 | + }); |
| 115 | + |
| 116 | + // This test most closely models the original design goal |
| 117 | + // for the change that added --config and --config-frozen |
| 118 | + // as discussed in #227 and #228 |
| 119 | + // In summary we force a launch request for the given program, |
| 120 | + // but the user does not specify the program and specifies |
| 121 | + // an attach request |
| 122 | + it('config frozen forces specific launch type', async function () { |
| 123 | + if (debugServerPort) { |
| 124 | + // This test requires launching the adapter to work |
| 125 | + this.skip(); |
| 126 | + } |
| 127 | + |
| 128 | + const config = { request: 'launch', program: emptyProgram }; |
| 129 | + |
| 130 | + // Launch the adapter with the frozen config |
| 131 | + const dc = await standardBeforeEach(defaultAdapter, [ |
| 132 | + `--config-frozen=${JSON.stringify(config)}`, |
| 133 | + ]); |
| 134 | + |
| 135 | + try { |
| 136 | + await Promise.all([ |
| 137 | + // Do an attach request omitting the program that we want |
| 138 | + // the adapter to force into a launch request |
| 139 | + dc.attachRequest( |
| 140 | + fillDefaults(this.test, {} as AttachRequestArguments) |
| 141 | + ), |
| 142 | + |
| 143 | + // The rest of this code is to ensure we launcher properly by verifying |
| 144 | + // we can run to a breakpoint |
| 145 | + dc.waitForEvent('initialized').then((_event) => { |
| 146 | + return dc |
| 147 | + .setBreakpointsRequest({ |
| 148 | + lines: [3], |
| 149 | + breakpoints: [{ line: 3 }], |
| 150 | + source: { path: emptySrc }, |
| 151 | + }) |
| 152 | + .then((_response) => { |
| 153 | + return dc.configurationDoneRequest(); |
| 154 | + }); |
| 155 | + }), |
| 156 | + dc.assertStoppedLocation('breakpoint', { |
| 157 | + path: emptySrc, |
| 158 | + line: 3, |
| 159 | + }), |
| 160 | + ]); |
| 161 | + } finally { |
| 162 | + await dc.stop(); |
| 163 | + } |
| 164 | + }); |
| 165 | +}); |
0 commit comments