Skip to content

Commit d5bc34a

Browse files
committedMar 19, 2025·
Fix broken cse-machine tests
1 parent bc990b4 commit d5bc34a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed
 

‎eslint.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default tseslint.config(
3232
'import/order': 'warn',
3333
'@typescript-eslint/no-base-to-string': 'off', // TODO: Remove
3434
'prefer-const': 'off', // TODO: Remove
35+
'no-constant-condition': ['warn', { checkLoops: false }],
3536
'no-var': 'off', // TODO: Remove
3637
'@typescript-eslint/ban-ts-comment': 'warn',
3738
'@typescript-eslint/ban-types': 'off',

‎src/runner/__tests__/execMethod.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import runners, { type RunnerTypes } from '../sourceRunner'
22
import { Chapter, type ExecutionMethod, Variant } from '../../types'
33
import type { Runner } from '../types'
4-
import { DEFAULT_SOURCE_OPTIONS, runCodeInSource } from '..'
4+
import { runCodeInSource } from '..'
55
import { mockContext } from '../../utils/testing/mocks'
66
import { getChapterName, objectKeys, objectValues } from '../../utils/misc'
77
import { asMockedFunc } from '../../utils/testing/misc'
@@ -90,7 +90,7 @@ const sourceCases: FullTestCase[] = [
9090
{
9191
contextMethod: 'native',
9292
variant: Variant.NATIVE,
93-
expectedRunner: 'native',
93+
expectedRunner: 'fulljs',
9494
expectedPrelude: false
9595
}
9696
]
@@ -155,11 +155,12 @@ async function testCase({
155155
// Check if the prelude is null before execution
156156
// because the prelude gets set to null if it wasn't before
157157
const shouldPrelude = expectedPrelude && context.prelude !== null
158-
const options = { ...DEFAULT_SOURCE_OPTIONS }
159-
160-
if (optionMethod !== undefined) {
161-
options.executionMethod = optionMethod
162-
}
158+
const options =
159+
optionMethod === undefined
160+
? undefined
161+
: {
162+
executionMethod: optionMethod
163+
}
163164

164165
await runCodeInSource(code, context, options)
165166

@@ -287,6 +288,15 @@ describe('Ensure that the correct runner is used for the given evaluation contex
287288
expectedRunner: 'native'
288289
}))
289290

291+
// testCases('runner correctly respects optionMethod', objectKeys(runners).map(runner => ({
292+
// code: '"enable verbose"; 0;',
293+
// optionMethod: runner,
294+
// chapter: Chapter.SOURCE_4,
295+
// variant: Variant.DEFAULT,
296+
// expectedPrelude: true,
297+
// expectedRunner: runner
298+
// })))
299+
290300
test('if optionMethod is specified, debubger statements are ignored', () =>
291301
testCase({
292302
code: 'debugger; 0;',

‎src/utils/ast/helpers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ export function getSourceVariableDeclaration(decl: es.VariableDeclaration) {
8383
'Variable Declarations in Source should be declared using an Identifier!'
8484
)
8585

86+
assert(!!declaration.init, 'Variable declarations in Source must be initialized!')
87+
8688
return {
8789
id: declaration.id,
88-
init: declaration.init!,
90+
init: declaration.init,
8991
loc: declaration.loc
9092
}
9193
}

0 commit comments

Comments
 (0)
Please sign in to comment.