def main(): cwd = os.path.abspath('.') scm = detect_scm_system(cwd) cpplint.use_mozilla_styles() (args, flags) = cpplint.parse_arguments([]) for test in TESTS: with open(test["patch"]) as fh: patch = fh.read() with closing(StringIO.StringIO()) as output: cpplint.set_stream(output) checkmozstyle.process_patch(patch, cwd, cwd, scm) result = output.getvalue() with open(test["out"]) as fh: expected_output = fh.read() test_status = "PASSED" if result != expected_output: test_status = "FAILED" print("TEST " + test["patch"] + " " + test_status) print("Got result:\n" + result + "Expected:\n" + expected_output) else: print("TEST " + test["patch"] + " " + test_status)
def test_create_patch_is_full_patch(self): test_dir_path = os.path.join(self.svn_checkout_path, 'test_dir') os.mkdir(test_dir_path) test_file_path = os.path.join(test_dir_path, 'test_file2') write_into_file_at_path(test_file_path, 'test content') run_command(['svn', 'add', 'test_dir']) # create_patch depends on 'svn-create-patch', so make a dummy version. scripts_path = os.path.join(self.svn_checkout_path, 'WebKitTools', 'Scripts') os.makedirs(scripts_path) create_patch_path = os.path.join(scripts_path, 'svn-create-patch') write_into_file_at_path( create_patch_path, '#!/bin/sh\necho $PWD' ) # We could pass -n to prevent the \n, but not all echo accept -n. os.chmod(create_patch_path, stat.S_IXUSR | stat.S_IRUSR) # Change into our test directory and run the create_patch command. os.chdir(test_dir_path) scm = detect_scm_system(test_dir_path) self.assertEqual(scm.checkout_root, self.svn_checkout_path ) # Sanity check that detection worked right. patch_contents = scm.create_patch() # Our fake 'svn-create-patch' returns $PWD instead of a patch, check that it was executed from the root of the repo. self.assertEqual("%s\n" % os.path.realpath(scm.checkout_root), patch_contents) # Add a \n because echo adds a \n.
def _setup_webkittools_scripts_symlink(self, local_scm): webkit_scm = detect_scm_system( os.path.dirname(os.path.abspath(__file__))) webkit_scripts_directory = webkit_scm.scripts_directory() local_scripts_directory = local_scm.scripts_directory() os.mkdir(os.path.dirname(local_scripts_directory)) os.symlink(webkit_scripts_directory, local_scripts_directory)
def test_create_binary_patch(self): # Create a git binary patch and check the contents. scm = detect_scm_system(self.git_checkout_path) test_file_name = 'binary_file' test_file_path = os.path.join(self.git_checkout_path, test_file_name) file_contents = ''.join(map(chr, range(256))) write_into_file_at_path(test_file_path, file_contents) run_command(['git', 'add', test_file_name]) patch = scm.create_patch() self.assertTrue(re.search(r'\nliteral 0\n', patch)) self.assertTrue(re.search(r'\nliteral 256\n', patch)) # Check if we can apply the created patch. run_command(['git', 'rm', '-f', test_file_name]) self._setup_webkittools_scripts_symlink(scm) self.scm.apply_patch(self._create_patch(patch)) self.assertEqual(file_contents, read_from_path(test_file_path)) # Check if we can create a patch from a local commit. write_into_file_at_path(test_file_path, file_contents) run_command(['git', 'add', test_file_name]) run_command(['git', 'commit', '-m', 'binary diff']) patch_from_local_commit = scm.create_patch_from_local_commit('HEAD') self.assertTrue(re.search(r'\nliteral 0\n', patch_from_local_commit)) self.assertTrue(re.search(r'\nliteral 256\n', patch_from_local_commit)) patch_since_local_commit = scm.create_patch_since_local_commit( 'HEAD^1') self.assertTrue(re.search(r'\nliteral 0\n', patch_since_local_commit)) self.assertTrue(re.search(r'\nliteral 256\n', patch_since_local_commit)) self.assertEqual(patch_from_local_commit, patch_since_local_commit)
def test_create_binary_patch(self): # Create a git binary patch and check the contents. scm = detect_scm_system(self.git_checkout_path) test_file_name = 'binary_file' test_file_path = os.path.join(self.git_checkout_path, test_file_name) file_contents = ''.join(map(chr, range(256))) write_into_file_at_path(test_file_path, file_contents) run_command(['git', 'add', test_file_name]) patch = scm.create_patch() self.assertTrue(re.search(r'\nliteral 0\n', patch)) self.assertTrue(re.search(r'\nliteral 256\n', patch)) # Check if we can apply the created patch. run_command(['git', 'rm', '-f', test_file_name]) self._setup_webkittools_scripts_symlink(scm) self.scm.apply_patch(self._create_patch(patch)) self.assertEqual(file_contents, read_from_path(test_file_path)) # Check if we can create a patch from a local commit. write_into_file_at_path(test_file_path, file_contents) run_command(['git', 'add', test_file_name]) run_command(['git', 'commit', '-m', 'binary diff']) patch_from_local_commit = scm.create_patch_from_local_commit('HEAD') self.assertTrue(re.search(r'\nliteral 0\n', patch_from_local_commit)) self.assertTrue(re.search(r'\nliteral 256\n', patch_from_local_commit)) patch_since_local_commit = scm.create_patch_since_local_commit('HEAD^1') self.assertTrue(re.search(r'\nliteral 0\n', patch_since_local_commit)) self.assertTrue(re.search(r'\nliteral 256\n', patch_since_local_commit)) self.assertEqual(patch_from_local_commit, patch_since_local_commit)
def test_rebase_in_progress(self): svn_test_file = os.path.join(self.svn_checkout_path, 'test_file') write_into_file_at_path(svn_test_file, "svn_checkout") run([ 'svn', 'commit', '--message', 'commit to conflict with git commit' ], cwd=self.svn_checkout_path) git_test_file = os.path.join(self.git_checkout_path, 'test_file') write_into_file_at_path(git_test_file, "git_checkout") run([ 'git', 'commit', '-a', '-m', 'commit to be thrown away by rebase abort' ]) # --quiet doesn't make git svn silent, so use run_silent to redirect output self.assertRaises( ScriptError, run_silent, ['git', 'svn', '--quiet', 'rebase' ]) # Will fail due to a conflict leaving us mid-rebase. scm = detect_scm_system(self.git_checkout_path) self.assertTrue(scm.rebase_in_progress()) # Make sure our cleanup works. scm.clean_working_directory() self.assertFalse(scm.rebase_in_progress()) # Make sure cleanup doesn't throw when no rebase is in progress. scm.clean_working_directory()
def test_commitish_parsing(self): scm = detect_scm_system(self.git_checkout_path) # Multiple revisions are cherry-picked. self.assertEqual(len(scm.commit_ids_from_commitish_arguments(['HEAD~2'])), 1) self.assertEqual(len(scm.commit_ids_from_commitish_arguments(['HEAD', 'HEAD~2'])), 2) # ... is an invalid range specifier self.assertRaises(ScriptError, scm.commit_ids_from_commitish_arguments, ['trunk...HEAD'])
def test_commitish_order(self): scm = detect_scm_system(self.git_checkout_path) commit_range = 'HEAD~3..HEAD' actual_commits = scm.commit_ids_from_commitish_arguments([commit_range]) expected_commits = [] expected_commits += reversed(run(['git', 'rev-list', commit_range]).splitlines()) self.assertEqual(actual_commits, expected_commits)
def test_commitish_order(self): scm = detect_scm_system(self.git_checkout_path) commit_range = 'HEAD~3..HEAD' actual_commits = scm.commit_ids_from_commitish_arguments( [commit_range]) expected_commits = [] expected_commits += reversed( run(['git', 'rev-list', commit_range]).splitlines()) self.assertEqual(actual_commits, expected_commits)
def test_commitish_parsing(self): scm = detect_scm_system(self.git_checkout_path) # Multiple revisions are cherry-picked. self.assertEqual( len(scm.commit_ids_from_commitish_arguments(['HEAD~2'])), 1) self.assertEqual( len(scm.commit_ids_from_commitish_arguments(['HEAD', 'HEAD~2'])), 2) # ... is an invalid range specifier self.assertRaises(ScriptError, scm.commit_ids_from_commitish_arguments, ['trunk...HEAD'])
def main(): cpplint.use_mozilla_styles() (args, flags) = cpplint.parse_arguments(sys.argv[1:], ["git-commit="]) if args: sys.stderr.write("ERROR: We don't support files as arguments for " + "now.\n" + cpplint._USAGE) sys.exit(1) cwd = os.path.abspath('.') scm = detect_scm_system(cwd) root = scm.find_checkout_root(cwd) if "--git-commit" in flags: process_patch(scm.create_patch_from_local_commit(flags["--git-commit"]), root, cwd, scm) else: process_patch(scm.create_patch(), root, cwd, scm) sys.stderr.write('Total errors found: %d\n' % cpplint.error_count()) sys.exit(cpplint.error_count() > 0)
def test_rebase_in_progress(self): svn_test_file = os.path.join(self.svn_checkout_path, 'test_file') write_into_file_at_path(svn_test_file, "svn_checkout") run(['svn', 'commit', '--message', 'commit to conflict with git commit'], cwd=self.svn_checkout_path) git_test_file = os.path.join(self.git_checkout_path, 'test_file') write_into_file_at_path(git_test_file, "git_checkout") run(['git', 'commit', '-a', '-m', 'commit to be thrown away by rebase abort']) # --quiet doesn't make git svn silent, so use run_silent to redirect output self.assertRaises(ScriptError, run_silent, ['git', 'svn', '--quiet', 'rebase']) # Will fail due to a conflict leaving us mid-rebase. scm = detect_scm_system(self.git_checkout_path) self.assertTrue(scm.rebase_in_progress()) # Make sure our cleanup works. scm.clean_working_directory() self.assertFalse(scm.rebase_in_progress()) # Make sure cleanup doesn't throw when no rebase is in progress. scm.clean_working_directory()
def test_create_patch_is_full_patch(self): test_dir_path = os.path.join(self.svn_checkout_path, 'test_dir') os.mkdir(test_dir_path) test_file_path = os.path.join(test_dir_path, 'test_file2') write_into_file_at_path(test_file_path, 'test content') run(['svn', 'add', 'test_dir']) # create_patch depends on 'svn-create-patch', so make a dummy version. scripts_path = os.path.join(self.svn_checkout_path, 'WebKitTools', 'Scripts') os.makedirs(scripts_path) create_patch_path = os.path.join(scripts_path, 'svn-create-patch') write_into_file_at_path(create_patch_path, '#!/bin/sh\necho $PWD') os.chmod(create_patch_path, stat.S_IXUSR | stat.S_IRUSR) # Change into our test directory and run the create_patch command. os.chdir(test_dir_path) scm = detect_scm_system(test_dir_path) self.assertEqual(scm.checkout_root, self.svn_checkout_path) # Sanity check that detection worked right. patch_contents = scm.create_patch() # Our fake 'svn-create-patch' returns $PWD instead of a patch, check that it was executed from the root of the repo. self.assertEqual(os.path.realpath(scm.checkout_root), patch_contents)
def main(): cpplint.use_mozilla_styles() (args, flags) = cpplint.parse_arguments(sys.argv[1:], ["git-commit="]) if args: sys.stderr.write("ERROR: We don't support files as arguments for " + "now.\n" + cpplint._USAGE) sys.exit(1) cwd = os.path.abspath('.') scm = detect_scm_system(cwd) root = scm.find_checkout_root(cwd) if "--git-commit" in flags: process_patch( scm.create_patch_from_local_commit(flags["--git-commit"]), root, cwd, scm) else: process_patch(scm.create_patch(), root, cwd, scm) sys.stderr.write('Total errors found: %d\n' % cpplint.error_count()) sys.exit(cpplint.error_count() > 0)
def test_detection(self): scm = detect_scm_system(self.git_checkout_path) self.assertEqual(scm.display_name(), "git") self.assertEqual(scm.supports_local_commits(), True)
def test_apply_svn_patch_force(self): scm = detect_scm_system(self.svn_checkout_path) patch = self._create_patch(run_command(['svn', 'diff', '-r2:4'])) self._setup_webkittools_scripts_symlink(scm) self.assertRaises(ScriptError, scm.apply_patch, patch, force=True)
def test_apply_svn_patch(self): scm = detect_scm_system(self.svn_checkout_path) patch = self._create_patch(run(['svn', 'diff', '-r4:3'])) self._setup_webkittools_scripts_symlink(scm) scm.apply_patch(patch)
def setUp(self): SVNTestRepository.setup(self) self._setup_git_clone_of_svn_repository() os.chdir(self.git_checkout_path) self.scm = detect_scm_system(self.git_checkout_path)
def setUp(self): SVNTestRepository.setup(self) os.chdir(self.svn_checkout_path) self.scm = detect_scm_system(self.svn_checkout_path)
def test_detection(self): scm = detect_scm_system(self.svn_checkout_path) self.assertEqual(scm.display_name(), "svn") self.assertEqual(scm.supports_local_commits(), False)
def _setup_webkittools_scripts_symlink(self, local_scm): webkit_scm = detect_scm_system(self.original_path) webkit_scripts_directory = webkit_scm.scripts_directory() local_scripts_directory = local_scm.scripts_directory() os.mkdir(os.path.dirname(local_scripts_directory)) os.symlink(webkit_scripts_directory, local_scripts_directory)
def test_apply_git_patch(self): scm = detect_scm_system(self.git_checkout_path) patch = self._create_patch(run(['git', 'diff', 'HEAD..HEAD^'])) self._setup_webkittools_scripts_symlink(scm) scm.apply_patch(patch)
def _setup_webkittools_scripts_symlink(self, local_scm): webkit_scm = detect_scm_system(os.path.dirname(os.path.abspath(__file__))) webkit_scripts_directory = webkit_scm.scripts_directory() local_scripts_directory = local_scm.scripts_directory() os.mkdir(os.path.dirname(local_scripts_directory)) os.symlink(webkit_scripts_directory, local_scripts_directory)
def test_apply_git_patch_force(self): scm = detect_scm_system(self.git_checkout_path) patch = self._create_patch(run(['git', 'diff', 'HEAD~2..HEAD'])) self._setup_webkittools_scripts_symlink(scm) self.assertRaises(ScriptError, scm.apply_patch, patch, force=True)