Skip to content

Commit

Permalink
Tests: make result.json files optional
Browse files Browse the repository at this point in the history
  • Loading branch information
rrthomas committed Jul 22, 2024
1 parent a940efe commit d5cc9e3
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 25 deletions.
1 change: 0 additions & 1 deletion rosettacode/Accumulator factory.result.json

This file was deleted.

1 change: 0 additions & 1 deletion rosettacode/Ackermann function.result.json

This file was deleted.

1 change: 0 additions & 1 deletion rosettacode/Anagrams.result.json

This file was deleted.

1 change: 0 additions & 1 deletion rosettacode/FizzBuzz.result.json

This file was deleted.

1 change: 0 additions & 1 deletion rosettacode/Generator-Exponential.result.json

This file was deleted.

1 change: 0 additions & 1 deletion rosettacode/Hailstone sequence.result.json

This file was deleted.

1 change: 0 additions & 1 deletion rosettacode/Hello world-Text.result.json

This file was deleted.

1 change: 0 additions & 1 deletion rosettacode/Loops-Continue.result.json

This file was deleted.

24 changes: 14 additions & 10 deletions src/testutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ async function doCliTest(
t: ExecutionContext,
syntax: string,
inputBasename: string,
resultJsonFilename: string,
realSourceBasename?: string,
extraArgs?: string[],
expectedStdout?: string,
expectedStderr?: string,
useRepl?: boolean,
target: string = 'ark',
) {
const inputFile = `${inputBasename}.${syntax}`
const resultJsonFilename = `${inputBasename}.result.json`
const actualSourceBasename = realSourceBasename ?? inputBasename
const inputFile = `${actualSourceBasename}.${syntax}`
const args = [`--syntax=${syntax}`, `--target=${target}`]
let tempFile: tmp.FileResult
if (!useRepl) {
Expand All @@ -111,8 +113,12 @@ async function doCliTest(
)
if (!useRepl) {
const result: unknown = JSON.parse(fs.readFileSync(tempFile!.name, {encoding: 'utf-8'}))
const expected: unknown = JSON.parse(fs.readFileSync(resultJsonFilename, {encoding: 'utf-8'}))
t.deepEqual(result, expected)
const expected: unknown = fs.existsSync(resultJsonFilename)
? JSON.parse(fs.readFileSync(resultJsonFilename, {encoding: 'utf-8'}))
: undefined
if (expected !== undefined) {
t.deepEqual(result, expected)
}
}
if (syntax === 'json') {
const source = fs.readFileSync(inputFile, {encoding: 'utf-8'})
Expand Down Expand Up @@ -194,13 +200,12 @@ const reformattingCliTest = test.macro(async (
expectedReformattedStderr?: string,
syntaxErrorExpected?: boolean,
) => {
const resultFile = `${inputBasename}.result.json`
for (const target of arkTargets) {
await doCliTest(
t,
'ursa',
inputBasename,
resultFile,
undefined,
extraArgs,
expectedStdout,
expectedStderr,
Expand All @@ -212,8 +217,8 @@ const reformattingCliTest = test.macro(async (
await doCliTest(
t,
'ursa',
inputBasename,
makeReformattedSource(t, `${inputBasename}.ursa`),
resultFile,
extraArgs,
expectedStdout,
expectedReformattedStderr ?? expectedStderr,
Expand All @@ -233,7 +238,6 @@ const reformattingCliDirTest = test.macro(async (
expectedReformattedStderr?: string,
syntaxErrorExpected?: boolean,
) => {
const resultFile = `${inputBasename}.result.json`
for (const target of arkTargets) {
await doDirTest(
t,
Expand All @@ -243,7 +247,7 @@ const reformattingCliDirTest = test.macro(async (
t,
'ursa',
inputBasename,
resultFile,
undefined,
[tmpDirPath, ...extraArgs ?? []],
expectedStdout,
expectedStderr,
Expand All @@ -261,8 +265,8 @@ const reformattingCliDirTest = test.macro(async (
doCliTest(
t,
'ursa',
inputBasename,
makeReformattedSource(t, `${inputBasename}.ursa`),
resultFile,
[tmpDirPath, ...extraArgs ?? []],
expectedStdout,
expectedReformattedStderr ?? expectedStderr,
Expand Down
1 change: 0 additions & 1 deletion test/advent-of-code-2023-day-25.result.json

This file was deleted.

1 change: 0 additions & 1 deletion test/else-if.result.json

This file was deleted.

1 change: 0 additions & 1 deletion test/generator.result.json

This file was deleted.

1 change: 0 additions & 1 deletion test/print.result.json

This file was deleted.

1 change: 0 additions & 1 deletion test/syms.result.json

This file was deleted.

1 change: 0 additions & 1 deletion test/two-sequential-loops.result.json

This file was deleted.

1 change: 0 additions & 1 deletion test/yield.result.json

This file was deleted.

0 comments on commit d5cc9e3

Please sign in to comment.