|
| 1 | +var assert = require('assert'); |
| 2 | +var fs = require('fs'); |
| 3 | + |
| 4 | +const matcherJSON = fs.readFileSync('sphinx_matcher.json'); |
| 5 | +const matcher = JSON.parse(matcherJSON); |
| 6 | + |
| 7 | +const patterns = matcher.problemMatcher[0].pattern; |
| 8 | + |
| 9 | +for (const pattern of patterns) { |
| 10 | + console.log("Patterns under test: ", pattern.regexp); |
| 11 | +} |
| 12 | + |
| 13 | +const sphinx_log = |
| 14 | +`/home/travis/build/ammaraskar/sphinx-action/tests/test_projects/warnings_and_errors/index.rst:16: WARNING: Error in "code-block" directive: |
| 15 | +maximum 1 argument(s) allowed, 2 supplied. |
| 16 | +.. code-block:: ruby |
| 17 | + as |
| 18 | +
|
| 19 | +/home/travis/build/ammaraskar/sphinx-action/tests/test_projects/warnings/index.rst:22: WARNING: Problems with "include" directive path: |
| 20 | +InputError: [Errno 2] No such file or directory: 'I_DONT_EXIST'. |
| 21 | +
|
| 22 | +
|
| 23 | +/home/travis/build/ammaraskar/sphinx-action/tests/test_projects/warnings/index.rst:24: WARNING: Unknown directive type "BADDIRECTIVE". |
| 24 | +.. BADDIRECTIVE:: asdf |
| 25 | +
|
| 26 | +checking consistency... /home/travis/build/ammaraskar/sphinx-action/tests/test_projects/warnings/notintoc.rst: WARNING: document isn't included in any toctree`; |
| 27 | + |
| 28 | + |
| 29 | +const expected_matches = [ |
| 30 | + { |
| 31 | + 'file': '/home/travis/build/ammaraskar/sphinx-action/tests/test_projects/warnings_and_errors/index.rst', |
| 32 | + 'line': '16', |
| 33 | + 'severity': 'WARNING', |
| 34 | + 'message': 'Error in "code-block" directive:' |
| 35 | + }, |
| 36 | + { |
| 37 | + 'file': '/home/travis/build/ammaraskar/sphinx-action/tests/test_projects/warnings/index.rst', |
| 38 | + 'line': '22', |
| 39 | + 'severity': 'WARNING', |
| 40 | + 'message': 'Problems with "include" directive path:' |
| 41 | + }, |
| 42 | + { |
| 43 | + 'file': '/home/travis/build/ammaraskar/sphinx-action/tests/test_projects/warnings/index.rst', |
| 44 | + 'line': '24', |
| 45 | + 'severity': 'WARNING', |
| 46 | + 'message': 'Unknown directive type "BADDIRECTIVE".', |
| 47 | + }, |
| 48 | + { |
| 49 | + 'file': '/home/travis/build/ammaraskar/sphinx-action/tests/test_projects/warnings/notintoc.rst', |
| 50 | + 'line': null, |
| 51 | + 'severity': 'WARNING', |
| 52 | + 'message': "document isn't included in any toctree" |
| 53 | + } |
| 54 | +] |
| 55 | + |
| 56 | +function perform_match(pattern_object, line) { |
| 57 | + const match = line.match(pattern_object.regexp); |
| 58 | + |
| 59 | + if (!match) { |
| 60 | + return null; |
| 61 | + } |
| 62 | + |
| 63 | + return { |
| 64 | + file: pattern_object.file ? match[pattern_object.file] : null, |
| 65 | + line: pattern_object.line ? match[pattern_object.line] : null, |
| 66 | + severity: pattern_object.severity ? match[pattern_object.severity] : null, |
| 67 | + message: pattern_object.message ? match[pattern_object.message] : null |
| 68 | + }; |
| 69 | +} |
| 70 | + |
| 71 | +let matches = []; |
| 72 | +for (const line of sphinx_log.split(/\n/)) { |
| 73 | + for (const pattern_object of patterns) { |
| 74 | + const match = perform_match(pattern_object, line); |
| 75 | + if (match) { |
| 76 | + matches.push(match); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +console.log("Matches: ", matches); |
| 82 | +console.log("Expected matches: ", expected_matches); |
| 83 | +assert.deepEqual(expected_matches, matches); |
| 84 | + |
| 85 | +console.log("[x] All good!"); |
0 commit comments