-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #492 from jvalue/parse-only
Add `--parse-only` flag
- Loading branch information
Showing
5 changed files
with
194 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import * as fs from 'node:fs'; | ||
import * as path from 'path'; | ||
import * as process from 'process'; | ||
|
||
import { | ||
clearBlockExecutorRegistry, | ||
clearConstraintExecutorRegistry, | ||
} from '@jvalue/jayvee-execution/test'; | ||
import { | ||
RunOptions, | ||
interpretModel, | ||
interpretString, | ||
} from '@jvalue/jayvee-interpreter-lib'; | ||
|
||
import { runAction } from './run-action'; | ||
|
||
jest.mock('@jvalue/jayvee-interpreter-lib', () => { | ||
const original: object = jest.requireActual('@jvalue/jayvee-interpreter-lib'); | ||
return { | ||
...original, | ||
interpretModel: jest.fn(), | ||
interpretString: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('Parse Only', () => { | ||
const pathToValidModel = path.resolve(__dirname, '../../../example/cars.jv'); | ||
const pathToInvalidModel = path.resolve( | ||
__dirname, | ||
'../test/assets/broken-model.jv', | ||
); | ||
|
||
const defaultOptions: RunOptions = { | ||
env: new Map<string, string>(), | ||
debug: false, | ||
debugGranularity: 'minimal', | ||
debugTarget: undefined, | ||
}; | ||
|
||
afterEach(() => { | ||
// Assert that model is not executed | ||
expect(interpretString).not.toBeCalled(); | ||
expect(interpretModel).not.toBeCalled(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.spyOn(process, 'exit').mockImplementation(() => { | ||
throw new Error(); | ||
}); | ||
|
||
// Reset jayvee specific stuff | ||
clearBlockExecutorRegistry(); | ||
clearConstraintExecutorRegistry(); | ||
}); | ||
|
||
it('should exit with 0 on a valid option', async () => { | ||
await expect( | ||
runAction(pathToValidModel, { | ||
...defaultOptions, | ||
parseOnly: true, | ||
}), | ||
).rejects.toBeDefined(); | ||
|
||
expect(process.exit).toBeCalledTimes(1); | ||
expect(process.exit).toHaveBeenCalledWith(0); | ||
}); | ||
|
||
it('should exit with 1 on error', async () => { | ||
expect(fs.existsSync(pathToInvalidModel)).toBe(true); | ||
|
||
await expect( | ||
runAction(pathToInvalidModel, { | ||
...defaultOptions, | ||
parseOnly: true, | ||
}), | ||
).rejects.toBeDefined(); | ||
|
||
expect(process.exit).toBeCalledTimes(1); | ||
expect(process.exit).toHaveBeenCalledWith(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-FileCopyrightText: 2024 Friedrich-Alexander-Universitat Erlangen-Nurnberg | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
pipeline CarsPipeline { | ||
// Try using a CoolCarsExtractor although we only have normal cars. | ||
// This fill result in an error during parsing. | ||
CoolCarsExtractor -> CarsTextFileInterpreter; | ||
|
||
CarsTextFileInterpreter | ||
-> CarsCSVInterpreter | ||
-> NameHeaderWriter | ||
-> CarsTableInterpreter | ||
-> CarsLoader; | ||
|
||
block CarsExtractor oftype HttpExtractor { | ||
url: "https://gist.githubusercontent.com/noamross/e5d3e859aa0c794be10b/raw/b999fb4425b54c63cab088c0ce2c0d6ce961a563/cars.csv"; | ||
} | ||
|
||
block CarsTextFileInterpreter oftype TextFileInterpreter { } | ||
|
||
block CarsCSVInterpreter oftype CSVInterpreter { | ||
enclosing: '"'; | ||
} | ||
|
||
block NameHeaderWriter oftype CellWriter { | ||
at: cell A1; | ||
write: ["name"]; | ||
} | ||
|
||
block CarsTableInterpreter oftype TableInterpreter { | ||
header: true; | ||
columns: [ | ||
"name" oftype text, | ||
"mpg" oftype decimal, | ||
"cyl" oftype integer, | ||
"disp" oftype decimal, | ||
"hp" oftype integer, | ||
"drat" oftype decimal, | ||
"wt" oftype decimal, | ||
"qsec" oftype decimal, | ||
"vs" oftype integer, | ||
"am" oftype integer, | ||
"gear" oftype integer, | ||
"carb" oftype integer | ||
]; | ||
} | ||
|
||
block CarsLoader oftype SQLiteLoader { | ||
table: "Cars"; | ||
file: "./cars.sqlite"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters