Skip to content

Commit 63d7948

Browse files
committed
tests
Signed-off-by: Jens Reinecke <jens.reinecke@arm.com>
1 parent 6a06173 commit 63d7948

3 files changed

Lines changed: 36 additions & 9 deletions

File tree

src/cbuild-run/__snapshots__/cbuild-run-reader.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`CbuildRunReader successfully parses a *.cbuild-run.yml file 1`] = `
3+
exports[`CbuildRunReader Parser successfully parses a *.cbuild-run.yml file 1`] = `
44
{
55
"compiler": "AC6",
66
"debug-sequences": [

src/cbuild-run/cbuild-run-reader.test.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,38 @@ const TEST_FILE_PATH = 'test-data/fileReaderTest.txt'; // Relative to repo root
2121

2222
describe('CbuildRunReader', () => {
2323

24-
it('successfully parses a *.cbuild-run.yml file', async () => {
25-
const reader = new CbuildRunReader();
26-
const contents = await reader.parse(TEST_CBUILD_RUN_FILE);
27-
expect(contents).toMatchSnapshot();
24+
describe('Parser', () => {
25+
it('successfully parses a *.cbuild-run.yml file', async () => {
26+
const cbuildRunReader = new CbuildRunReader();
27+
await expect(cbuildRunReader.parse(TEST_CBUILD_RUN_FILE)).resolves.not.toThrow();
28+
expect(cbuildRunReader.hasContents()).toBe(true);
29+
const contents = cbuildRunReader.getContents();
30+
expect(contents).toBeDefined();
31+
expect(contents).toMatchSnapshot();
32+
});
33+
34+
it('throws if it parses something other than a *.cbuild-run.yml file', async () => {
35+
const expectedError = /Invalid '\*\.cbuild-run\.yml' file: .*test-data\/fileReaderTest\.txt/;
36+
const cbuildRunReader = new CbuildRunReader();
37+
await expect(cbuildRunReader.parse(TEST_FILE_PATH)).rejects.toThrow(expectedError);
38+
expect(cbuildRunReader.hasContents()).toBe(false);
39+
expect(cbuildRunReader.getContents()).toBeUndefined();
40+
});
2841
});
2942

30-
it('throws if it parses something other than a *.cbuild-run.yml file', async () => {
31-
const expectedError = /Invalid '\*\.cbuild-run\.yml' file: .*test-data\/fileReaderTest\.txt/;
32-
const reader = new CbuildRunReader();
33-
await expect(reader.parse(TEST_FILE_PATH)).rejects.toThrow(expectedError);
43+
describe('Extract Values', () => {
44+
let cbuildRunReader: CbuildRunReader;
45+
46+
beforeAll(async () => {
47+
cbuildRunReader = new CbuildRunReader();
48+
});
49+
50+
it('returns SVD file path', async () => {
51+
const expectedSvdFilePaths = ['/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core0.svd'];
52+
await cbuildRunReader.parse(TEST_CBUILD_RUN_FILE);
53+
const svdFilePaths = cbuildRunReader.getSvdFilePaths('/my/pack/root');
54+
expect(svdFilePaths).toEqual(expectedSvdFilePaths);
55+
});
56+
3457
});
3558
});

src/cbuild-run/cbuild-run-reader.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export class CbuildRunReader {
3131
return !!this.cbuildRun;
3232
}
3333

34+
public getContents(): CbuildRunType|undefined {
35+
return this.cbuildRun;
36+
}
37+
3438
public async parse(filePath: string): Promise<void> {
3539
const fileContents = await this.reader.readFileToString(filePath);
3640
const fileRoot = yaml.parse(fileContents);

0 commit comments

Comments
 (0)