From b71e1e9e83f1a0029b9ebda0382f56268d29d8c7 Mon Sep 17 00:00:00 2001 From: Chris Moesel Date: Fri, 6 Dec 2019 15:33:32 -0500 Subject: [PATCH] Update location format in log messages (#48) * Update location format in log messages Update location format to: ``` error: My Message File: /absolute/path/to/MyFile.fsh Line: 12 - 14 ``` Based on team discussion. * Fix tests missing \D at the end of the log message matcher --- src/app.ts | 5 +++-- src/utils/FSHLogger.ts | 8 ++++--- test/export/ExtensionExporter.test.ts | 2 +- test/export/ProfileExporter.test.ts | 2 +- .../StructureDefinitionExporter.test.ts | 22 +++++++++---------- test/import/FSHImporter.Extension.test.ts | 4 ++-- test/import/FSHImporter.Instance.test.ts | 6 ++--- test/import/FSHImporter.Profile.test.ts | 6 ++--- test/import/FSHImporter.test.ts | 4 ++-- 9 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/app.ts b/src/app.ts index 291e32909..c3904cf9e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -36,8 +36,9 @@ try { const docs: FSHDocument[] = []; for (const file of files) { if (file.endsWith('.fsh')) { - const fileContent = fs.readFileSync(path.join(input, file), 'utf8'); - const doc = importText(fileContent, file); + const filePath = path.resolve(input, file); + const fileContent = fs.readFileSync(filePath, 'utf8'); + const doc = importText(fileContent, filePath); if (doc) docs.push(doc); } } diff --git a/src/utils/FSHLogger.ts b/src/utils/FSHLogger.ts index 9677af185..3fdf547cf 100644 --- a/src/utils/FSHLogger.ts +++ b/src/utils/FSHLogger.ts @@ -4,12 +4,14 @@ const { combine, colorize, simple } = format; const withLocation = format(info => { if (info.file) { - info.message += `\nFile: ${info.file}`; + info.message += `\n File: ${info.file}`; delete info.file; } if (info.location) { - info.message += `\nFrom: (Line ${info.location.startLine}, Column ${info.location.startColumn})`; - info.message += `\nTo: (Line ${info.location.endLine}, Column ${info.location.endColumn})`; + info.message += `\n Line: ${info.location.startLine}`; + if (info.location.endLine !== info.location.startLine) { + info.message += ` - ${info.location.endLine}`; + } delete info.location; } return info; diff --git a/test/export/ExtensionExporter.test.ts b/test/export/ExtensionExporter.test.ts index 7aa4e647a..63f7cb5a0 100644 --- a/test/export/ExtensionExporter.test.ts +++ b/test/export/ExtensionExporter.test.ts @@ -60,7 +60,7 @@ describe('ExtensionExporter', () => { doc.extensions.set(extension.name, extension); exporter.export(); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Wrong\.fsh.*Line 14\D.*Column 8\D.*Line 24\D.*Column 17\D/s + /File: Wrong\.fsh.*Line: 14 - 24\D/s ); }); diff --git a/test/export/ProfileExporter.test.ts b/test/export/ProfileExporter.test.ts index 8e697e414..9bd4bc227 100644 --- a/test/export/ProfileExporter.test.ts +++ b/test/export/ProfileExporter.test.ts @@ -60,7 +60,7 @@ describe('ProfileExporter', () => { doc.profiles.set(profile.name, profile); exporter.export(); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Bogus\.fsh.*Line 2\D.*Column 9\D.*Line 4\D.*Column 23\D/s + /File: Bogus\.fsh.*Line: 2 - 4\D/s ); }); diff --git a/test/export/StructureDefinitionExporter.test.ts b/test/export/StructureDefinitionExporter.test.ts index 65c5feb09..7fd4bfed2 100644 --- a/test/export/StructureDefinitionExporter.test.ts +++ b/test/export/StructureDefinitionExporter.test.ts @@ -170,7 +170,7 @@ describe('StructureDefinitionExporter', () => { expect(structDef).toBeDefined(); expect(structDef.type).toBe('Resource'); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Foo\.fsh.*Line 3\D.*Column 8\D.*Line 4\D.*Column 22\D/s + /File: Foo\.fsh.*Line: 3 - 4\D/s ); }); @@ -218,7 +218,7 @@ describe('StructureDefinitionExporter', () => { expect(changedCard.min).toBe(1); expect(changedCard.max).toBe('1'); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Wrong\.fsh.*Line 5\D.*Column 4\D.*Line 5\D.*Column 11\D/s + /File: Wrong\.fsh.*Line: 5\D/s ); }); @@ -266,7 +266,7 @@ describe('StructureDefinitionExporter', () => { expect(changedElement.isModifier).toBe(true); expect(changedElement.mustSupport).toBeFalsy(); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Nope\.fsh.*Line 8\D.*Column 7\D.*Line 8\D.*Column 15\D/s + /File: Nope\.fsh.*Line: 8\D/s ); }); @@ -293,7 +293,7 @@ describe('StructureDefinitionExporter', () => { expect(changedElement.isSummary).toBe(true); expect(changedElement.mustSupport).toBe(true); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Nope\.fsh.*Line 8\D.*Column 7\D.*Line 8\D.*Column 15\D/s + /File: Nope\.fsh.*Line: 8\D/s ); }); @@ -354,7 +354,7 @@ describe('StructureDefinitionExporter', () => { expect(baseElement.binding).toBeUndefined(); expect(changedElement.binding).toBeUndefined(); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Codeless\.fsh.*Line 6\D.*Column 9\D.*Line 6\D.*Column 25\D/s + /File: Codeless\.fsh.*Line: 6\D/s ); }); @@ -379,7 +379,7 @@ describe('StructureDefinitionExporter', () => { ); expect(changedElement.binding.strength).toBe('preferred'); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Strict\.fsh.*Line 9\D.*Column 10\D.*Line 9\D.*Column 35\D/s + /File: Strict\.fsh.*Line: 9\D/s ); }); @@ -541,7 +541,7 @@ describe('StructureDefinitionExporter', () => { expect(baseValue.type).toHaveLength(11); expect(constrainedValue.type).toHaveLength(11); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Only\.fsh.*Line 10\D.*Column 12\D.*Line 10\D.*Column 22\D/s + /File: Only\.fsh.*Line: 10\D/s ); }); @@ -586,7 +586,7 @@ describe('StructureDefinitionExporter', () => { expect(baseCode.patternCodeableConcept).toBeUndefined(); expect(fixedCode.patternCodeableConcept).toBeUndefined(); // Code remains unset expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Fixed\.fsh.*Line 4\D.*Column 18\D.*Line 4\D.*Column 28\D/s + /File: Fixed\.fsh.*Line: 4\D/s ); }); @@ -649,7 +649,7 @@ describe('StructureDefinitionExporter', () => { expect(sd.elements.length).toBe(baseStructDef.elements.length); expect(barSlice).toBeUndefined(); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: NoSlice\.fsh.*Line 6\D.*Column 3\D.*Line 6\D.*Column 12\D/s + /File: NoSlice\.fsh.*Line: 6\D/s ); }); @@ -690,7 +690,7 @@ describe('StructureDefinitionExporter', () => { expect(status.short).toBe(baseStatus.short); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: InvalidValue\.fsh.*Line 6\D.*Column 3\D.*Line 6\D.*Column 12\D/s + /File: InvalidValue\.fsh.*Line: 6\D/s ); }); @@ -723,7 +723,7 @@ describe('StructureDefinitionExporter', () => { expect(sd.description).toBe(baseStructDef.description); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: InvalidValue\.fsh.*Line 6\D.*Column 3\D.*Line 6\D.*Column 12\D/s + /File: InvalidValue\.fsh.*Line: 6\D/s ); }); diff --git a/test/import/FSHImporter.Extension.test.ts b/test/import/FSHImporter.Extension.test.ts index 83daa6101..6722cc247 100644 --- a/test/import/FSHImporter.Extension.test.ts +++ b/test/import/FSHImporter.Extension.test.ts @@ -99,10 +99,10 @@ describe('FSHImporter', () => { importText(input, 'Dupe.fsh'); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 2][0].message).toMatch( - /File: Dupe\.fsh.*Line 7\D.*Column 9\D.*Line 7\D.*Column 41\D/s + /File: Dupe\.fsh.*Line: 7\D/s ); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Dupe\.fsh.*Line 8\D.*Column 9\D.*Line 8\D.*Column 58\D/s + /File: Dupe\.fsh.*Line: 8\D/s ); }); }); diff --git a/test/import/FSHImporter.Instance.test.ts b/test/import/FSHImporter.Instance.test.ts index 6ca2b829a..013492c4b 100644 --- a/test/import/FSHImporter.Instance.test.ts +++ b/test/import/FSHImporter.Instance.test.ts @@ -56,7 +56,7 @@ describe('FSHImporter', () => { const result = importText(input, 'Missing.fsh'); expect(result.instances.size).toBe(0); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Missing\.fsh.*Line 2\D.*Column 9\D.*Line 3\D.*Column 41\D/s + /File: Missing\.fsh.*Line: 2 - 3\D/s ); }); }); @@ -132,10 +132,10 @@ describe('FSHImporter', () => { importText(input, 'Dupe.fsh'); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 2][0].message).toMatch( - /File: Dupe\.fsh.*Line 5\D.*Column 9\D.*Line 5\D.*Column 40\D/s + /File: Dupe\.fsh.*Line: 5\D/s ); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Dupe\.fsh.*Line 6\D.*Column 9\D.*Line 6\D.*Column 41\D/s + /File: Dupe\.fsh.*Line: 6\D/s ); }); }); diff --git a/test/import/FSHImporter.Profile.test.ts b/test/import/FSHImporter.Profile.test.ts index 0c6d63081..9a806f406 100644 --- a/test/import/FSHImporter.Profile.test.ts +++ b/test/import/FSHImporter.Profile.test.ts @@ -156,10 +156,10 @@ describe('FSHImporter', () => { importText(input, 'Dupe.fsh'); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 2][0].message).toMatch( - /File: Dupe\.fsh.*Line 7\D.*Column 9\D.*Line 7\D.*Column 46\D/s + /File: Dupe\.fsh.*Line: 7\D/s ); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Dupe\.fsh.*Line 8\D.*Column 9\D.*Line 8\D.*Column 58\D/s + /File: Dupe\.fsh.*Line: 8\D/s ); }); }); @@ -868,7 +868,7 @@ describe('FSHImporter', () => { const profile = result.profiles.get('ObservationProfile'); expect(profile.rules).toHaveLength(0); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Obeys\.fsh.*Line 4\D.*Column 9\D.*Line 4\D.*Column 38\D/s + /File: Obeys\.fsh.*Line: 4\D/s ); }); }); diff --git a/test/import/FSHImporter.test.ts b/test/import/FSHImporter.test.ts index 5a1634831..7365b753e 100644 --- a/test/import/FSHImporter.test.ts +++ b/test/import/FSHImporter.test.ts @@ -48,7 +48,7 @@ describe('FSHImporter', () => { `; importText(input, 'Pizza.fsh'); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Pizza\.fsh.*Line 3\D.*Column 5\D.*Line 3\D.*Column 10\D/s + /File: Pizza\.fsh.*Line: 3\D/s ); }); @@ -59,7 +59,7 @@ describe('FSHImporter', () => { `; importText(input, 'Space.fsh'); expect(mockWriter.mock.calls[mockWriter.mock.calls.length - 1][0].message).toMatch( - /File: Space\.fsh.*Line 2\D.*Column 24\D.*Line 2\D.*Column 29\D/s + /File: Space\.fsh.*Line: 2\D/s ); }); });