Bug 1646700 [wpt PR 24235] - Update picture-in-picture idlharness test, a=testonly
[gecko.git] / config / check_js_msg_encoding.py
blob6a0ece99b73961b3d28fb23ac9d785c6efe18bd3
1 # vim: set ts=8 sts=4 et sw=4 tw=99:
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 # ----------------------------------------------------------------------------
7 # This script checks encoding of the files that define JSErrorFormatStrings.
9 # JSErrorFormatString.format member should be in ASCII encoding.
10 # ----------------------------------------------------------------------------
12 from __future__ import absolute_import, print_function, unicode_literals
14 import os
15 import sys
17 from mozversioncontrol import get_repository_from_env
20 scriptname = os.path.basename(__file__)
21 expected_encoding = 'ascii'
23 # The following files don't define JSErrorFormatString.
24 ignore_files = [
25 'dom/base/domerr.msg',
26 'js/xpconnect/src/xpc.msg',
30 def log_pass(filename, text):
31 print('TEST-PASS | {} | {} | {}'.format(scriptname, filename, text))
34 def log_fail(filename, text):
35 print('TEST-UNEXPECTED-FAIL | {} | {} | {}'.format(scriptname, filename,
36 text))
39 def check_single_file(filename):
40 with open(filename, 'rb') as f:
41 data = f.read()
42 try:
43 data.decode(expected_encoding)
44 except Exception:
45 log_fail(filename, 'not in {} encoding'.format(expected_encoding))
47 log_pass(filename, 'ok')
48 return True
51 def check_files():
52 result = True
54 with get_repository_from_env() as repo:
55 root = repo.path
57 for filename in repo.get_files_in_working_directory():
58 if filename.endswith('.msg'):
59 if filename not in ignore_files:
60 if not check_single_file(os.path.join(root, filename)):
61 result = False
63 return result
66 def main():
67 if not check_files():
68 sys.exit(1)
70 sys.exit(0)
73 if __name__ == '__main__':
74 main()