From 01a07561e8ffbd22e82a8bad4c1f9de24516ec7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Mon, 11 Sep 2023 08:22:41 +0200 Subject: [PATCH 1/6] Added validateDocument tests, missing test-logger PR features --- libs/execution/test/index.ts | 1 + libs/interpreter-lib/src/parsing-util.spec.ts | 111 ++++++++++++++++++ .../invalid-wrong-loader-type.jv | 14 +++ .../validateDocument/valid-document.jv | 14 +++ 4 files changed, 140 insertions(+) create mode 100644 libs/interpreter-lib/src/parsing-util.spec.ts create mode 100644 libs/interpreter-lib/test/assets/parsing-util/validateDocument/invalid-wrong-loader-type.jv create mode 100644 libs/interpreter-lib/test/assets/parsing-util/validateDocument/valid-document.jv diff --git a/libs/execution/test/index.ts b/libs/execution/test/index.ts index 6b29ad45a..28b73965e 100644 --- a/libs/execution/test/index.ts +++ b/libs/execution/test/index.ts @@ -4,3 +4,4 @@ export * from './block-executor-mock'; export * from './utils'; +export * from './test-logger'; diff --git a/libs/interpreter-lib/src/parsing-util.spec.ts b/libs/interpreter-lib/src/parsing-util.spec.ts new file mode 100644 index 000000000..0e5da465d --- /dev/null +++ b/libs/interpreter-lib/src/parsing-util.spec.ts @@ -0,0 +1,111 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +import { TestLogger } from '@jvalue/jayvee-execution/test'; +import { + JayveeServices, + createJayveeServices, + useExtension, +} from '@jvalue/jayvee-language-server'; +import { + ParseHelperOptions, + TestLangExtension, + expectNoParserAndLexerErrors, + parseHelper, + readJvTestAssetHelper, +} from '@jvalue/jayvee-language-server/test'; +import { AstNode, LangiumDocument } from 'langium'; +import { NodeFileSystem } from 'langium/node'; + +import { validateDocument } from './parsing-util'; + +describe('Validation of parsing-util', () => { + let parse: ( + input: string, + options?: ParseHelperOptions, + ) => Promise>; + + let exitSpy: jest.SpyInstance; + + // let locator: AstNodeLocator; + let services: JayveeServices; + + const logger = new TestLogger(true, undefined); + + const readJvTestAsset = readJvTestAssetHelper( + __dirname, + '../test/assets/parsing-util/', + ); + + beforeAll(() => { + // Mock Process.exit + exitSpy = jest + .spyOn(process, 'exit') + // eslint-disable-next-line @typescript-eslint/no-unused-vars + .mockImplementation((code?: number) => undefined as never); + + // Register test extension + useExtension(new TestLangExtension()); + // Create language services + services = createJayveeServices(NodeFileSystem).Jayvee; + // locator = services.workspace.AstNodeLocator; + // Parse function for Jayvee (without validation) + parse = parseHelper(services); + }); + + /*afterEach(() => { + logger.clearLogs(); + });*/ + + describe('Validation of validateDocument', () => { + async function parseAndValidateDocument(input: string) { + const document = await parse(input); + expectNoParserAndLexerErrors(document); + + return validateDocument(document, services, logger); + } + + it('should diagnose no error on valid document', async () => { + const text = readJvTestAsset('validateDocument/valid-document.jv'); + + await parseAndValidateDocument(text); + + expect(exitSpy).toHaveBeenCalledTimes(0); + /*expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + }); + + it('should diagnose error on wrong loader type', async () => { + const text = readJvTestAsset( + 'validateDocument/invalid-wrong-loader-type.jv', + ); + + await parseAndValidateDocument(text); + + expect(exitSpy).toHaveBeenCalledTimes(1); + expect(exitSpy).toHaveBeenCalledWith(1); + /*expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(2);*/ + }); + + it('should diagnose no error on nonErr diagnostics', async () => { + const text = readJvTestAsset( + 'validateDocument/invalid-wrong-loader-type.jv', + ); + + await parseAndValidateDocument(text); + + expect(exitSpy).toHaveBeenCalledTimes(1); + expect(exitSpy).toHaveBeenCalledWith(1); + /*expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(1);*/ + }); + }); +}); diff --git a/libs/interpreter-lib/test/assets/parsing-util/validateDocument/invalid-wrong-loader-type.jv b/libs/interpreter-lib/test/assets/parsing-util/validateDocument/invalid-wrong-loader-type.jv new file mode 100644 index 000000000..037e75012 --- /dev/null +++ b/libs/interpreter-lib/test/assets/parsing-util/validateDocument/invalid-wrong-loader-type.jv @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +pipeline TestPipeline { + + block TestExtractor oftype TestFileExtractor { + } + + block TestLoader oftype TestTableLoader { + } + + TestExtractor -> TestLoader; +} diff --git a/libs/interpreter-lib/test/assets/parsing-util/validateDocument/valid-document.jv b/libs/interpreter-lib/test/assets/parsing-util/validateDocument/valid-document.jv new file mode 100644 index 000000000..70f3794d1 --- /dev/null +++ b/libs/interpreter-lib/test/assets/parsing-util/validateDocument/valid-document.jv @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +pipeline TestPipeline { + + block TestExtractor oftype TestFileExtractor { + } + + block TestLoader oftype TestFileLoader { + } + + TestExtractor -> TestLoader; +} From 79e4e668779037bc57561cc6b9fca1ccca9d9f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Mon, 11 Sep 2023 09:00:21 +0200 Subject: [PATCH 2/6] Added extractDocumentFromString tests, missing test-logger PR features --- libs/interpreter-lib/src/parsing-util.spec.ts | 30 ++++++++++++++++++- .../invalid-model.jv | 15 ++++++++++ .../extractDocumentFromString/valid-model.jv | 14 +++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromString/invalid-model.jv create mode 100644 libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromString/valid-model.jv diff --git a/libs/interpreter-lib/src/parsing-util.spec.ts b/libs/interpreter-lib/src/parsing-util.spec.ts index 0e5da465d..6024290e9 100644 --- a/libs/interpreter-lib/src/parsing-util.spec.ts +++ b/libs/interpreter-lib/src/parsing-util.spec.ts @@ -18,7 +18,7 @@ import { import { AstNode, LangiumDocument } from 'langium'; import { NodeFileSystem } from 'langium/node'; -import { validateDocument } from './parsing-util'; +import { extractDocumentFromString, validateDocument } from './parsing-util'; describe('Validation of parsing-util', () => { let parse: ( @@ -108,4 +108,32 @@ describe('Validation of parsing-util', () => { expect(logger.getLogs().diagnosticLogs).toHaveLength(1);*/ }); }); + + describe('Validation of extractDocumentFromString', () => { + it('should diagnose no error on valid model string', async () => { + const text = readJvTestAsset('extractDocumentFromString/valid-model.jv'); + + await extractDocumentFromString(text, services, logger); + + expect(exitSpy).toHaveBeenCalledTimes(0); + /*expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + }); + + it('should diagnose error on invalid model string', async () => { + const text = readJvTestAsset( + 'extractDocumentFromString/invalid-model.jv', + ); + + await extractDocumentFromString(text, services, logger); + + expect(exitSpy).toHaveBeenCalledTimes(1); + /*expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(3);*/ + }); + }); }); diff --git a/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromString/invalid-model.jv b/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromString/invalid-model.jv new file mode 100644 index 000000000..7abf8d0f8 --- /dev/null +++ b/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromString/invalid-model.jv @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +pipeline TestPipeline { + + block TestExtractor oftype TestFileExtractor { + } + + block TestLoader oftype TestFileLoader { + } + sta + + TestExtractor -> TestLoader; +} diff --git a/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromString/valid-model.jv b/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromString/valid-model.jv new file mode 100644 index 000000000..70f3794d1 --- /dev/null +++ b/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromString/valid-model.jv @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +pipeline TestPipeline { + + block TestExtractor oftype TestFileExtractor { + } + + block TestLoader oftype TestFileLoader { + } + + TestExtractor -> TestLoader; +} From 8aaa6e2c99315c95761bb12a2afcbbb305ed945f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Mon, 11 Sep 2023 09:52:31 +0200 Subject: [PATCH 3/6] - Added extractDocumentFromFile tests, missing test-logger PR features - Fixed `process.exit` spy to actually quit tested function --- libs/interpreter-lib/src/parsing-util.spec.ts | 134 ++++++++++++++---- .../invalid-extension.lv | 14 ++ .../extractDocumentFromFile/valid-model.jv | 14 ++ 3 files changed, 132 insertions(+), 30 deletions(-) create mode 100644 libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromFile/invalid-extension.lv create mode 100644 libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromFile/valid-model.jv diff --git a/libs/interpreter-lib/src/parsing-util.spec.ts b/libs/interpreter-lib/src/parsing-util.spec.ts index 6024290e9..bac2162f6 100644 --- a/libs/interpreter-lib/src/parsing-util.spec.ts +++ b/libs/interpreter-lib/src/parsing-util.spec.ts @@ -2,6 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0-only +import * as path from 'path'; + import { TestLogger } from '@jvalue/jayvee-execution/test'; import { JayveeServices, @@ -18,7 +20,11 @@ import { import { AstNode, LangiumDocument } from 'langium'; import { NodeFileSystem } from 'langium/node'; -import { extractDocumentFromString, validateDocument } from './parsing-util'; +import { + extractDocumentFromFile, + extractDocumentFromString, + validateDocument, +} from './parsing-util'; describe('Validation of parsing-util', () => { let parse: ( @@ -28,7 +34,6 @@ describe('Validation of parsing-util', () => { let exitSpy: jest.SpyInstance; - // let locator: AstNodeLocator; let services: JayveeServices; const logger = new TestLogger(true, undefined); @@ -42,21 +47,22 @@ describe('Validation of parsing-util', () => { // Mock Process.exit exitSpy = jest .spyOn(process, 'exit') - // eslint-disable-next-line @typescript-eslint/no-unused-vars - .mockImplementation((code?: number) => undefined as never); + .mockImplementation((code?: number) => { + throw new Error(`process.exit: ${code ?? 0}`); + }); // Register test extension useExtension(new TestLangExtension()); // Create language services services = createJayveeServices(NodeFileSystem).Jayvee; - // locator = services.workspace.AstNodeLocator; // Parse function for Jayvee (without validation) parse = parseHelper(services); }); - /*afterEach(() => { - logger.clearLogs(); - });*/ + afterEach(() => { + // logger.clearLogs(); + jest.clearAllMocks(); + }); describe('Validation of validateDocument', () => { async function parseAndValidateDocument(input: string) { @@ -72,7 +78,7 @@ describe('Validation of parsing-util', () => { await parseAndValidateDocument(text); expect(exitSpy).toHaveBeenCalledTimes(0); - /*expect(logger.getLogs().infoLogs).toHaveLength(0); + /* expect(logger.getLogs().infoLogs).toHaveLength(0); expect(logger.getLogs().errorLogs).toHaveLength(0); expect(logger.getLogs().debugLogs).toHaveLength(0); expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ @@ -83,14 +89,16 @@ describe('Validation of parsing-util', () => { 'validateDocument/invalid-wrong-loader-type.jv', ); - await parseAndValidateDocument(text); - - expect(exitSpy).toHaveBeenCalledTimes(1); - expect(exitSpy).toHaveBeenCalledWith(1); - /*expect(logger.getLogs().infoLogs).toHaveLength(0); - expect(logger.getLogs().errorLogs).toHaveLength(0); - expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(2);*/ + try { + await parseAndValidateDocument(text); + } catch (e) { + expect(exitSpy).toHaveBeenCalledTimes(1); + expect(exitSpy).toHaveBeenCalledWith(1); + /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(2);*/ + } }); it('should diagnose no error on nonErr diagnostics', async () => { @@ -98,14 +106,16 @@ describe('Validation of parsing-util', () => { 'validateDocument/invalid-wrong-loader-type.jv', ); - await parseAndValidateDocument(text); - - expect(exitSpy).toHaveBeenCalledTimes(1); - expect(exitSpy).toHaveBeenCalledWith(1); - /*expect(logger.getLogs().infoLogs).toHaveLength(0); - expect(logger.getLogs().errorLogs).toHaveLength(0); - expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(1);*/ + try { + await parseAndValidateDocument(text); + } catch (e) { + expect(exitSpy).toHaveBeenCalledTimes(1); + expect(exitSpy).toHaveBeenCalledWith(1); + /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(1);*/ + } }); }); @@ -116,7 +126,7 @@ describe('Validation of parsing-util', () => { await extractDocumentFromString(text, services, logger); expect(exitSpy).toHaveBeenCalledTimes(0); - /*expect(logger.getLogs().infoLogs).toHaveLength(0); + /* expect(logger.getLogs().infoLogs).toHaveLength(0); expect(logger.getLogs().errorLogs).toHaveLength(0); expect(logger.getLogs().debugLogs).toHaveLength(0); expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ @@ -127,13 +137,77 @@ describe('Validation of parsing-util', () => { 'extractDocumentFromString/invalid-model.jv', ); - await extractDocumentFromString(text, services, logger); + try { + await extractDocumentFromString(text, services, logger); + } catch (e) { + expect(exitSpy).toHaveBeenCalledTimes(1); + /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(3);*/ + } + }); + }); - expect(exitSpy).toHaveBeenCalledTimes(1); - /*expect(logger.getLogs().infoLogs).toHaveLength(0); + describe('Validation of extractDocumentFromFile', () => { + it('should diagnose no error on valid model file', async () => { + await extractDocumentFromFile( + path.resolve( + __dirname, + '../test/assets/parsing-util/', + 'extractDocumentFromFile/valid-model.jv', + ), + services, + logger, + ); + + expect(exitSpy).toHaveBeenCalledTimes(0); + /* expect(logger.getLogs().infoLogs).toHaveLength(0); expect(logger.getLogs().errorLogs).toHaveLength(0); expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(3);*/ + expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + }); + + it('should diagnose error on invalid extension', async () => { + try { + await extractDocumentFromFile( + path.resolve( + __dirname, + '../test/assets/parsing-util/', + 'extractDocumentFromFile/invalid-extension.lv', + ), + services, + logger, + ); + } catch (e) { + expect(exitSpy).toHaveBeenCalledTimes(1); + /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(1); + expect(logger.getLogs().errorLogs[0]).toEqual(expect.objectContaining({message: 'Please choose a file with this extension: ".jv"'})); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + } + }); + + it('should diagnose error on missing file', async () => { + try { + await extractDocumentFromFile( + path.resolve( + __dirname, + '../test/assets/parsing-util/', + 'extractDocumentFromFile/invalid-missing-file.jv', + ), + services, + logger, + ); + } catch (e) { + expect(exitSpy).toHaveBeenCalledTimes(1); + /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs[0].message).toMatch(/File [\w\-\/]*\/libs\/interpreter-lib\/test\/assets\/parsing-util\/extractDocumentFromFile\/invalid-missing-file\.jv does not exist\./); + expect(logger.getLogs().debugLogs).toHaveLength(0); + expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + } }); }); }); diff --git a/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromFile/invalid-extension.lv b/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromFile/invalid-extension.lv new file mode 100644 index 000000000..70f3794d1 --- /dev/null +++ b/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromFile/invalid-extension.lv @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +pipeline TestPipeline { + + block TestExtractor oftype TestFileExtractor { + } + + block TestLoader oftype TestFileLoader { + } + + TestExtractor -> TestLoader; +} diff --git a/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromFile/valid-model.jv b/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromFile/valid-model.jv new file mode 100644 index 000000000..70f3794d1 --- /dev/null +++ b/libs/interpreter-lib/test/assets/parsing-util/extractDocumentFromFile/valid-model.jv @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +pipeline TestPipeline { + + block TestExtractor oftype TestFileExtractor { + } + + block TestLoader oftype TestFileLoader { + } + + TestExtractor -> TestLoader; +} From 6ec6a01db50b02731992439913caeef972fe6844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Mon, 11 Sep 2023 10:13:17 +0200 Subject: [PATCH 4/6] Improved exitSpy (until replacing it with bugfix pr fix) --- libs/interpreter-lib/src/parsing-util.spec.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/interpreter-lib/src/parsing-util.spec.ts b/libs/interpreter-lib/src/parsing-util.spec.ts index bac2162f6..577da389a 100644 --- a/libs/interpreter-lib/src/parsing-util.spec.ts +++ b/libs/interpreter-lib/src/parsing-util.spec.ts @@ -48,7 +48,10 @@ describe('Validation of parsing-util', () => { exitSpy = jest .spyOn(process, 'exit') .mockImplementation((code?: number) => { - throw new Error(`process.exit: ${code ?? 0}`); + if (code === undefined || code === 0) { + return undefined as never; + } + throw new Error(`process.exit: ${code}`); }); // Register test extension @@ -60,8 +63,8 @@ describe('Validation of parsing-util', () => { }); afterEach(() => { + exitSpy.mockClear(); // logger.clearLogs(); - jest.clearAllMocks(); }); describe('Validation of validateDocument', () => { From d69c7cecc949652901db1e4b4bd9bf8a2add9a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Mon, 11 Sep 2023 13:16:29 +0200 Subject: [PATCH 5/6] Fixed tests + removed obsolete extractDocumentFromString --- libs/interpreter-lib/src/parsing-util.spec.ts | 79 ++++++------------- .../valid-simplify-warning.jv | 19 +++++ 2 files changed, 45 insertions(+), 53 deletions(-) create mode 100644 libs/interpreter-lib/test/assets/parsing-util/validateDocument/valid-simplify-warning.jv diff --git a/libs/interpreter-lib/src/parsing-util.spec.ts b/libs/interpreter-lib/src/parsing-util.spec.ts index 577da389a..40a838e26 100644 --- a/libs/interpreter-lib/src/parsing-util.spec.ts +++ b/libs/interpreter-lib/src/parsing-util.spec.ts @@ -20,11 +20,7 @@ import { import { AstNode, LangiumDocument } from 'langium'; import { NodeFileSystem } from 'langium/node'; -import { - extractDocumentFromFile, - extractDocumentFromString, - validateDocument, -} from './parsing-util'; +import { extractDocumentFromFile, validateDocument } from './parsing-util'; describe('Validation of parsing-util', () => { let parse: ( @@ -36,7 +32,7 @@ describe('Validation of parsing-util', () => { let services: JayveeServices; - const logger = new TestLogger(true, undefined); + const logger = new TestLogger(true, undefined, false); const readJvTestAsset = readJvTestAssetHelper( __dirname, @@ -64,7 +60,7 @@ describe('Validation of parsing-util', () => { afterEach(() => { exitSpy.mockClear(); - // logger.clearLogs(); + logger.clearLogs(); }); describe('Validation of validateDocument', () => { @@ -81,10 +77,10 @@ describe('Validation of parsing-util', () => { await parseAndValidateDocument(text); expect(exitSpy).toHaveBeenCalledTimes(0); - /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().infoLogs).toHaveLength(0); expect(logger.getLogs().errorLogs).toHaveLength(0); expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + expect(logger.getLogs().diagnosticLogs).toHaveLength(0); }); it('should diagnose error on wrong loader type', async () => { @@ -97,16 +93,16 @@ describe('Validation of parsing-util', () => { } catch (e) { expect(exitSpy).toHaveBeenCalledTimes(1); expect(exitSpy).toHaveBeenCalledWith(1); - /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().infoLogs).toHaveLength(0); expect(logger.getLogs().errorLogs).toHaveLength(0); expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(2);*/ + expect(logger.getLogs().diagnosticLogs).toHaveLength(2 * 5); // 2 calls that get formated to 5 lines each } }); it('should diagnose no error on nonErr diagnostics', async () => { const text = readJvTestAsset( - 'validateDocument/invalid-wrong-loader-type.jv', + 'validateDocument/valid-simplify-warning.jv', ); try { @@ -114,40 +110,10 @@ describe('Validation of parsing-util', () => { } catch (e) { expect(exitSpy).toHaveBeenCalledTimes(1); expect(exitSpy).toHaveBeenCalledWith(1); - /* expect(logger.getLogs().infoLogs).toHaveLength(0); - expect(logger.getLogs().errorLogs).toHaveLength(0); - expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(1);*/ - } - }); - }); - - describe('Validation of extractDocumentFromString', () => { - it('should diagnose no error on valid model string', async () => { - const text = readJvTestAsset('extractDocumentFromString/valid-model.jv'); - - await extractDocumentFromString(text, services, logger); - - expect(exitSpy).toHaveBeenCalledTimes(0); - /* expect(logger.getLogs().infoLogs).toHaveLength(0); - expect(logger.getLogs().errorLogs).toHaveLength(0); - expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ - }); - - it('should diagnose error on invalid model string', async () => { - const text = readJvTestAsset( - 'extractDocumentFromString/invalid-model.jv', - ); - - try { - await extractDocumentFromString(text, services, logger); - } catch (e) { - expect(exitSpy).toHaveBeenCalledTimes(1); - /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().infoLogs).toHaveLength(0); expect(logger.getLogs().errorLogs).toHaveLength(0); expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(3);*/ + expect(logger.getLogs().diagnosticLogs).toHaveLength(1); } }); }); @@ -165,10 +131,10 @@ describe('Validation of parsing-util', () => { ); expect(exitSpy).toHaveBeenCalledTimes(0); - /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().infoLogs).toHaveLength(0); expect(logger.getLogs().errorLogs).toHaveLength(0); expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + expect(logger.getLogs().diagnosticLogs).toHaveLength(0); }); it('should diagnose error on invalid extension', async () => { @@ -184,11 +150,15 @@ describe('Validation of parsing-util', () => { ); } catch (e) { expect(exitSpy).toHaveBeenCalledTimes(1); - /* expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().infoLogs).toHaveLength(0); expect(logger.getLogs().errorLogs).toHaveLength(1); - expect(logger.getLogs().errorLogs[0]).toEqual(expect.objectContaining({message: 'Please choose a file with this extension: ".jv"'})); + expect(logger.getLogs().errorLogs[0]).toEqual( + expect.stringContaining( + 'Please choose a file with this extension: ".jv"', + ), + ); expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + expect(logger.getLogs().diagnosticLogs).toHaveLength(0); } }); @@ -205,11 +175,14 @@ describe('Validation of parsing-util', () => { ); } catch (e) { expect(exitSpy).toHaveBeenCalledTimes(1); - /* expect(logger.getLogs().infoLogs).toHaveLength(0); - expect(logger.getLogs().errorLogs).toHaveLength(0); - expect(logger.getLogs().errorLogs[0].message).toMatch(/File [\w\-\/]*\/libs\/interpreter-lib\/test\/assets\/parsing-util\/extractDocumentFromFile\/invalid-missing-file\.jv does not exist\./); + expect(logger.getLogs().infoLogs).toHaveLength(0); + expect(logger.getLogs().errorLogs).toHaveLength(1); + expect(logger.getLogs().errorLogs[0]).toMatch( + // eslint-disable-next-line no-useless-escape + /File [\w\-\/]*\/libs\/interpreter-lib\/test\/assets\/parsing-util\/extractDocumentFromFile\/invalid-missing-file\.jv does not exist\./, + ); expect(logger.getLogs().debugLogs).toHaveLength(0); - expect(logger.getLogs().diagnosticLogs).toHaveLength(0);*/ + expect(logger.getLogs().diagnosticLogs).toHaveLength(0); } }); }); diff --git a/libs/interpreter-lib/test/assets/parsing-util/validateDocument/valid-simplify-warning.jv b/libs/interpreter-lib/test/assets/parsing-util/validateDocument/valid-simplify-warning.jv new file mode 100644 index 000000000..f7116f9ae --- /dev/null +++ b/libs/interpreter-lib/test/assets/parsing-util/validateDocument/valid-simplify-warning.jv @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +pipeline TestPipeline { + + block TestExtractor oftype TestFileExtractor { + } + + block TestPropertyBlock oftype TestProperty { + textProperty: "Test"; + integerProperty: 20 + 20; + } + + block TestLoader oftype TestTableLoader { + } + + TestExtractor -> TestPropertyBlock -> TestLoader; +} From 90807c6eb7058fb894a4d757dfe6765a690f8241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Mon, 9 Oct 2023 09:41:13 +0200 Subject: [PATCH 6/6] Adjusted describe names --- libs/interpreter-lib/src/parsing-util.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/interpreter-lib/src/parsing-util.spec.ts b/libs/interpreter-lib/src/parsing-util.spec.ts index 40a838e26..f2125c9e0 100644 --- a/libs/interpreter-lib/src/parsing-util.spec.ts +++ b/libs/interpreter-lib/src/parsing-util.spec.ts @@ -63,7 +63,7 @@ describe('Validation of parsing-util', () => { logger.clearLogs(); }); - describe('Validation of validateDocument', () => { + describe('Function of validateDocument', () => { async function parseAndValidateDocument(input: string) { const document = await parse(input); expectNoParserAndLexerErrors(document); @@ -118,7 +118,7 @@ describe('Validation of parsing-util', () => { }); }); - describe('Validation of extractDocumentFromFile', () => { + describe('Function of extractDocumentFromFile', () => { it('should diagnose no error on valid model file', async () => { await extractDocumentFromFile( path.resolve(