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

Side by Side Diff: PRESUBMIT_test.py

Issue 1131903007: [Android log] Promote using hardcoded string tags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add length check and test, remove java tag check Created 5 years, 7 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
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 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 ] 842 ]
843 843
844 warnings = PRESUBMIT._CheckNoNewUtilLogUsage( 844 warnings = PRESUBMIT._CheckNoNewUtilLogUsage(
845 mock_input_api, mock_output_api) 845 mock_input_api, mock_output_api)
846 846
847 self.assertEqual(1, len(warnings)) 847 self.assertEqual(1, len(warnings))
848 self.assertEqual(2, len(warnings[0].items)) 848 self.assertEqual(2, len(warnings[0].items))
849 self.assertTrue('HasAndroidLog.java' in warnings[0].items[0]) 849 self.assertTrue('HasAndroidLog.java' in warnings[0].items[0])
850 self.assertTrue('HasExplicitLog.java' in warnings[0].items[1]) 850 self.assertTrue('HasExplicitLog.java' in warnings[0].items[1])
851 851
852 def testCheckAndroidCrLogUsage(self):
853 mock_input_api = MockInputApi()
854 mock_output_api = MockOutputApi()
855
856 mock_input_api.files = [
857 MockAffectedFile('RandomStuff.java', [
858 'random stuff'
859 ]),
860 MockAffectedFile('HasCorrectTag.java', [
861 'import org.chromium.base.Log;',
862 'some random stuff',
863 'private static final String TAG = "cr.Foo";',
864 'Log.d(TAG, "foo");',
865 ]),
866 MockAffectedFile('HasShortCorrectTag.java', [
867 'import org.chromium.base.Log;',
868 'some random stuff',
869 'private static final String TAG = "cr";',
870 'Log.d(TAG, "foo");',
871 ]),
872 MockAffectedFile('HasNoTagDecl.java', [
873 'import org.chromium.base.Log;',
874 'some random stuff',
875 'Log.d(TAG, "foo");',
876 ]),
877 MockAffectedFile('HasIncorrectTagDecl.java', [
878 'import org.chromium.base.Log;',
879 'private static final String TAHG = "cr.Foo";',
880 'some random stuff',
881 'Log.d(TAG, "foo");',
882 ]),
883 MockAffectedFile('HasInlineTag.java', [
884 'import org.chromium.base.Log;',
885 'some random stuff',
886 'private static final String TAG = "cr.Foo";',
887 'Log.d("TAG", "foo");',
888 ]),
889 MockAffectedFile('HasIncorrectTag.java', [
890 'import org.chromium.base.Log;',
891 'some random stuff',
892 'private static final String TAG = "rubbish";',
893 'Log.d(TAG, "foo");',
894 ]),
895 MockAffectedFile('HasTooLongTag.java', [
896 'import org.chromium.base.Log;',
897 'some random stuff',
898 'private static final String TAG = "cr.24_charachers_long___";',
899 'Log.d(TAG, "foo");',
900 ]),
901 ]
902
903 msgs = PRESUBMIT._CheckAndroidCrLogUsage(
904 mock_input_api, mock_output_api)
905
906 self.assertEqual(3, len(msgs))
907
908 # Declaration format
909 self.assertEqual(3, len(msgs[0].items))
910 self.assertTrue('HasNoTagDecl.java' in msgs[0].items)
911 self.assertTrue('HasIncorrectTagDecl.java' in msgs[0].items)
912 self.assertTrue('HasIncorrectTag.java' in msgs[0].items)
913
914 # Tag length
915 self.assertEqual(1, len(msgs[1].items))
916 self.assertTrue('HasTooLongTag.java' in msgs[1].items)
917
918 # Tag must be a variable named TAG
919 self.assertEqual(1, len(msgs[2].items))
920 self.assertTrue('HasInlineTag.java:4' in msgs[2].items)
921
922
852 923
853 if __name__ == '__main__': 924 if __name__ == '__main__':
854 unittest.main() 925 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698