|
| 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 { DebugProtocol } from '@vscode/debugprotocol'; |
| 18 | +import { OutputEventFilter } from './output-event-filter'; |
| 19 | + |
| 20 | +const makeOutputEvent = (output: string, category: string|undefined): DebugProtocol.OutputEvent => { |
| 21 | + const event = { |
| 22 | + seq: 1, |
| 23 | + type: 'event', |
| 24 | + event: 'output', |
| 25 | + body: { |
| 26 | + output |
| 27 | + } |
| 28 | + }; |
| 29 | + if (category) { |
| 30 | + Object.assign(event.body, { category }); |
| 31 | + } |
| 32 | + return event; |
| 33 | +}; |
| 34 | + |
| 35 | +describe('OutputEventFilter', () => { |
| 36 | + let eventFilter: OutputEventFilter; |
| 37 | + |
| 38 | + beforeEach(() => { |
| 39 | + eventFilter = new OutputEventFilter(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('filters events correctly', () => { |
| 43 | + const events = [ |
| 44 | + makeOutputEvent('warning: (Internal error: pc 0x12345678 in read in CU, but not in symtab.)\n', 'log'), |
| 45 | + makeOutputEvent('warning: (Internal error: pc 0x12345678 in read in CU, but not in symtab.)\r\n', 'log'), |
| 46 | + makeOutputEvent('warning: (Error: pc 0x12345678 in address map, but not in symtab.)\n', 'log'), |
| 47 | + ]; |
| 48 | + events.forEach(event => expect(eventFilter.filterOutputEvent(event)).toBe(true)); |
| 49 | + }); |
| 50 | + |
| 51 | + it('does not filter events with unexpected category', () => { |
| 52 | + const events = [ |
| 53 | + makeOutputEvent('warning: (Internal error: pc 0x12345678 in read in CU, but not in symtab.)\n', 'stdout'), |
| 54 | + makeOutputEvent('warning: (Internal error: pc 0x12345678 in read in CU, but not in symtab.)\n', 'stderr'), |
| 55 | + makeOutputEvent('warning: (Internal error: pc 0x12345678 in read in CU, but not in symtab.)\n', 'console'), |
| 56 | + makeOutputEvent('warning: (Internal error: pc 0x12345678 in read in CU, but not in symtab.)\n', undefined), |
| 57 | + ]; |
| 58 | + events.forEach(event => expect(eventFilter.filterOutputEvent(event)).toBe(false)); |
| 59 | + }); |
| 60 | + |
| 61 | + it('does not filter events that do not match the regular expressions', () => { |
| 62 | + const events = [ |
| 63 | + makeOutputEvent('foo', 'log'), |
| 64 | + makeOutputEvent('warning: Internal error: pc 0x12345678 in read in CU, but not in symtab.\n', 'log'), |
| 65 | + makeOutputEvent('Internal error: pc 0x12345678 in read in CU, but not in symtab.', 'log'), |
| 66 | + makeOutputEvent('warning: (Internal error: pc in read in CU, but not in symtab.)\n', 'log'), |
| 67 | + ]; |
| 68 | + events.forEach(event => expect(eventFilter.filterOutputEvent(event)).toBe(false)); |
| 69 | + }); |
| 70 | +}); |
0 commit comments