1# Copyright 2019 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Tests that doc/grammar.md is up to date.""" 16 17import pkgutil 18 19import unittest 20from compiler.front_end import generate_grammar_md 21 22 23class DocsAreUpToDateTest(unittest.TestCase): 24 """Tests that auto-generated, checked-in documentation is up to date.""" 25 26 def test_grammar_md(self): 27 doc_md = pkgutil.get_data("doc", "grammar.md").decode(encoding="UTF-8") 28 correct_md = generate_grammar_md.generate_grammar_md() 29 # If this fails, run: 30 # 31 # bazel run //compiler/front_end:generate_grammar_md > doc/grammar.md 32 # 33 # Be sure to check that the results look good before committing! 34 doc_md_lines = doc_md.splitlines() 35 correct_md_lines = correct_md.splitlines() 36 for i in range(len(doc_md_lines)): 37 self.assertEqual(correct_md_lines[i], doc_md_lines[i]) 38 self.assertEqual(correct_md, doc_md) 39 40 41if __name__ == "__main__": 42 unittest.main() 43