Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: PRESUBMIT_test.py

Issue 1183493002: [Android log] Fix presubmit check reports in base package (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import glob 6 import glob
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 import subprocess 10 import subprocess
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 self.assertEqual( 814 self.assertEqual(
815 ('File %s line %d: %s is missing in ' 815 ('File %s line %d: %s is missing in '
816 'tools/metrics/actions/actions.xml. Please run ' 816 'tools/metrics/actions/actions.xml. Please run '
817 'tools/metrics/actions/extract_actions.py to update.' 817 'tools/metrics/actions/extract_actions.py to update.'
818 % (file_with_user_action, 1, 'NotInActionsXml')), 818 % (file_with_user_action, 1, 'NotInActionsXml')),
819 output[0].message) 819 output[0].message)
820 820
821 821
822 class LogUsageTest(unittest.TestCase): 822 class LogUsageTest(unittest.TestCase):
823 823
824 def testCheckNoNewUtilLogUsage(self): 824 def testCheckAndroidCrLogUsage(self):
825 mock_input_api = MockInputApi() 825 mock_input_api = MockInputApi()
826 mock_output_api = MockOutputApi() 826 mock_output_api = MockOutputApi()
827 827
828 mock_input_api.files = [ 828 mock_input_api.files = [
829 MockAffectedFile('RandomStuff.java', [ 829 MockAffectedFile('RandomStuff.java', [
830 'random stuff' 830 'random stuff'
831 ]), 831 ]),
832 MockAffectedFile('HasCrLog.java', [
833 'import org.chromium.base.Log;',
834 'some random stuff',
835 'Log.d("TAG", "foo");',
836 ]),
837 MockAffectedFile('HasAndroidLog.java', [ 832 MockAffectedFile('HasAndroidLog.java', [
838 'import android.util.Log;', 833 'import android.util.Log;',
839 'some random stuff', 834 'some random stuff',
840 'Log.d("TAG", "foo");', 835 'Log.d("TAG", "foo");',
841 ]), 836 ]),
842 MockAffectedFile('HasExplicitLog.java', [ 837 MockAffectedFile('HasExplicitUtilLog.java', [
843 'some random stuff', 838 'some random stuff',
844 'android.util.Log.d("TAG", "foo");', 839 'android.util.Log.d("TAG", "foo");',
845 ]), 840 ]),
841 MockAffectedFile('IsInBasePackage.java', [
842 'package org.chromium.base;',
843 'private static final String TAG = "cr.Foo";',
844 'Log.d(TAG, "foo");',
845 ]),
846 MockAffectedFile('IsInBasePackageButImportsLog.java', [
847 'package org.chromium.base;',
848 'import android.util.Log;',
849 'private static final String TAG = "cr.Foo";',
850 'Log.d(TAG, "foo");',
851 ]),
846 MockAffectedFile('HasBothLog.java', [ 852 MockAffectedFile('HasBothLog.java', [
847 'import org.chromium.base.Log;', 853 'import org.chromium.base.Log;',
848 'some random stuff', 854 'some random stuff',
849 'Log.d("TAG", "foo");', 855 'private static final String TAG = "cr.Foo";',
856 'Log.d(TAG, "foo");',
850 'android.util.Log.d("TAG", "foo");', 857 'android.util.Log.d("TAG", "foo");',
851 ]), 858 ]),
852 ]
853
854 warnings = PRESUBMIT._CheckNoNewUtilLogUsage(
855 mock_input_api, mock_output_api)
856
857 self.assertEqual(1, len(warnings))
858 self.assertEqual(2, len(warnings[0].items))
859 self.assertTrue('HasAndroidLog.java' in warnings[0].items[0])
860 self.assertTrue('HasExplicitLog.java' in warnings[0].items[1])
861
862 def testCheckAndroidCrLogUsage(self):
863 mock_input_api = MockInputApi()
864 mock_output_api = MockOutputApi()
865
866 mock_input_api.files = [
867 MockAffectedFile('RandomStuff.java', [
868 'random stuff'
869 ]),
870 MockAffectedFile('HasCorrectTag.java', [ 859 MockAffectedFile('HasCorrectTag.java', [
871 'import org.chromium.base.Log;', 860 'import org.chromium.base.Log;',
872 'some random stuff', 861 'some random stuff',
873 'private static final String TAG = "cr.Foo";', 862 'private static final String TAG = "cr.Foo";',
874 'Log.d(TAG, "foo");', 863 'Log.d(TAG, "foo");',
875 ]), 864 ]),
876 MockAffectedFile('HasShortCorrectTag.java', [ 865 MockAffectedFile('HasShortCorrectTag.java', [
877 'import org.chromium.base.Log;', 866 'import org.chromium.base.Log;',
878 'some random stuff', 867 'some random stuff',
879 'private static final String TAG = "cr";', 868 'private static final String TAG = "cr";',
(...skipping 26 matching lines...) Expand all
906 'import org.chromium.base.Log;', 895 'import org.chromium.base.Log;',
907 'some random stuff', 896 'some random stuff',
908 'private static final String TAG = "cr.24_charachers_long___";', 897 'private static final String TAG = "cr.24_charachers_long___";',
909 'Log.d(TAG, "foo");', 898 'Log.d(TAG, "foo");',
910 ]), 899 ]),
911 ] 900 ]
912 901
913 msgs = PRESUBMIT._CheckAndroidCrLogUsage( 902 msgs = PRESUBMIT._CheckAndroidCrLogUsage(
914 mock_input_api, mock_output_api) 903 mock_input_api, mock_output_api)
915 904
916 self.assertEqual(3, len(msgs)) 905 self.assertEqual(4, len(msgs))
917 906
918 # Declaration format 907 # Declaration format
919 self.assertEqual(3, len(msgs[0].items)) 908 self.assertEqual(3, len(msgs[0].items))
920 self.assertTrue('HasNoTagDecl.java' in msgs[0].items) 909 self.assertTrue('HasNoTagDecl.java' in msgs[0].items)
921 self.assertTrue('HasIncorrectTagDecl.java' in msgs[0].items) 910 self.assertTrue('HasIncorrectTagDecl.java' in msgs[0].items)
922 self.assertTrue('HasIncorrectTag.java' in msgs[0].items) 911 self.assertTrue('HasIncorrectTag.java' in msgs[0].items)
923 912
924 # Tag length 913 # Tag length
925 self.assertEqual(1, len(msgs[1].items)) 914 self.assertEqual(1, len(msgs[1].items))
926 self.assertTrue('HasTooLongTag.java' in msgs[1].items) 915 self.assertTrue('HasTooLongTag.java' in msgs[1].items)
927 916
928 # Tag must be a variable named TAG 917 # Tag must be a variable named TAG
929 self.assertEqual(1, len(msgs[2].items)) 918 self.assertEqual(1, len(msgs[2].items))
930 self.assertTrue('HasInlineTag.java:4' in msgs[2].items) 919 self.assertTrue('HasInlineTag.java:4' in msgs[2].items)
931 920
921 # Util Log usage
922 self.assertEqual(2, len(msgs[3].items))
923 self.assertTrue('HasAndroidLog.java:3' in msgs[3].items)
924 self.assertTrue('IsInBasePackageButImportsLog.java:4' in msgs[3].items)
932 925
933 926
934 if __name__ == '__main__': 927 if __name__ == '__main__':
935 unittest.main() 928 unittest.main()
OLDNEW
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698