Skip to content

Commit

Permalink
Casting Bug Test
Browse files Browse the repository at this point in the history
Add test to catch error when casting a variable to another type
  • Loading branch information
WyoTwT committed Dec 6, 2023
1 parent cd740cd commit 2cec653
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/integration-tests/var.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { expect } from 'chai';
import * as path from 'path';
import { CdtDebugClient } from './debugClient';
import {
expectRejection,
getScopes,
resolveLineTagLocations,
Scope,
Expand Down Expand Up @@ -555,4 +556,43 @@ describe('Variables Test Suite', function () {
'[\n "104 \'h\'",\n "101 \'e\'",\n "108 \'l\'",\n "108 \'l\'",\n "111 \'o\'",\n "0 \'\\\\000\'"\n]'
);
});

it('catch error from casting of struct to a character array', async function () {
// skip ahead to array initialization
const br = await dc.setBreakpointsRequest({
source: { path: varsSrc },
breakpoints: [{ line: lineTags['char string setup'] }],
});
expect(br.success).to.equal(true);
await dc.continue({ threadId: scope.thread.id }, 'breakpoint', {
line: lineTags['char string setup'],
path: varsSrc,
});
// step the program and see that the values were passed to the program and evaluated.
await dc.next(
{ threadId: scope.thread.id },
{ path: varsSrc, line: lineTags['char string setup'] + 1 }
);
scope = await getScopes(dc);
expect(
scope.scopes.body.scopes.length,
'Unexpected number of scopes returned'
).to.equal(2);
// Setup the new variable to be evaluated.
const res2 = await dc.evaluateRequest({
context: 'repl',
expression: '(char[])k',
frameId: scope.frame.id,
});
expect(res2.body.result).eq('[6]');
// Call handleVariableRequestObject() on above using returned variablesReference.
const error = await expectRejection(
dc.variablesRequest({
variablesReference: res2.body.variablesReference,
})
);
expect(error.message).contains(
'-var-create: unable to create variable object'
);
});
});

0 comments on commit 2cec653

Please sign in to comment.