Skip to content

Commit

Permalink
Update location format in log messages (#48)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cmoesel authored and mint-thompson committed Dec 6, 2019
1 parent 550aa39 commit b71e1e9
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 28 deletions.
5 changes: 3 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/utils/FSHLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/export/ExtensionExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/export/ProfileExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});

Expand Down
22 changes: 11 additions & 11 deletions test/export/StructureDefinitionExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});

Expand Down Expand Up @@ -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
);
});

Expand Down Expand Up @@ -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
);
});

Expand All @@ -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
);
});

Expand Down Expand Up @@ -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
);
});

Expand All @@ -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
);
});

Expand Down Expand Up @@ -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
);
});

Expand Down Expand Up @@ -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
);
});

Expand Down Expand Up @@ -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
);
});

Expand Down Expand Up @@ -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
);
});

Expand Down Expand Up @@ -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
);
});

Expand Down
4 changes: 2 additions & 2 deletions test/import/FSHImporter.Extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/import/FSHImporter.Instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
});
Expand Down Expand Up @@ -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
);
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/import/FSHImporter.Profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
});
Expand Down Expand Up @@ -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
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/import/FSHImporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});

Expand All @@ -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
);
});
});

0 comments on commit b71e1e9

Please sign in to comment.