|
| 1 | +/** |
| 2 | + * Copyright 2025 Arm Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { CbuildRunReader } from './cbuild-run-reader'; |
| 18 | + |
| 19 | +const TEST_CBUILD_RUN_FILE = 'test-data/simple.cbuild-run.yml'; // Relative to repo root |
| 20 | +const TEST_FILE_PATH = 'test-data/fileReaderTest.txt'; // Relative to repo root |
| 21 | + |
| 22 | +describe('CbuildRunReader', () => { |
| 23 | + |
| 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 and correctly responds to raw contents calls', 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 | + }); |
| 41 | + |
| 42 | + it('correctly responds to raw contents calls if nothing is parsed', () => { |
| 43 | + const cbuildRunReader = new CbuildRunReader(); |
| 44 | + expect(cbuildRunReader.hasContents()).toBe(false); |
| 45 | + expect(cbuildRunReader.getContents()).toBeUndefined(); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + describe('Extract Values', () => { |
| 50 | + let cbuildRunReader: CbuildRunReader; |
| 51 | + |
| 52 | + beforeEach(() => { |
| 53 | + cbuildRunReader = new CbuildRunReader(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('returns SVD file path', async () => { |
| 57 | + const expectedSvdFilePaths = ['/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core0.svd']; |
| 58 | + await cbuildRunReader.parse(TEST_CBUILD_RUN_FILE); |
| 59 | + const svdFilePaths = cbuildRunReader.getSvdFilePaths('/my/pack/root'); |
| 60 | + expect(svdFilePaths).toEqual(expectedSvdFilePaths); |
| 61 | + }); |
| 62 | + |
| 63 | + it('returns empty SVD file path list if nothing is parsed', () => { |
| 64 | + const svdFilePaths = cbuildRunReader.getSvdFilePaths('/my/pack/root'); |
| 65 | + expect(svdFilePaths.length).toEqual(0); |
| 66 | + }); |
| 67 | + }); |
| 68 | +}); |
0 commit comments