Open alirezah7 opened 6 years ago
Can you give more information? Can you make sure the patch
tool is found in your system's path? What is the version?
please help me with that. what should i do to fix the problem?
GNU patch 2.7.5
Copyright (C) 2003, 2009-2012 Free Software Foundation, Inc.
Copyright (C) 1988 Larry Wall
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Larry Wall and Paul Eggert
Hello, i try to fix my problem with your code: this is about doing patch and the error is :
1 out of 1 hunk FAILED -- saving rejects to file /home/test/Desktop/example.cpp.rej
Hi, I had similar issue and I figured it out. Compared to @alirezah7 in my case difference was that I followed step by step with instruction.
Issue patch tool fail because similarities don't match what's in the original file. More precisely there was different line break type in generated patch and example.cpp Thats why we have this error (in my case):
Hunk #1 FAILED at 1 (different line endings). 1 out of 1 hunk FAILED -- saving rejects to file /tmp/cmake-example/src/example.cpp.rej
(I used patch command that was printed in log to achive this error) If you check generated patch file and exmaple.cpp file you can see something like: for patch
$ file /tmp/tmpyxoqpka0 /tmp/tmpyxoqpka0: unified diff output, ASCII text, with CRLF, LF line terminators
and for example.cpp
file /tmp/cmake-example/src/example.cpp /tmp/cmake-example/src/example.cpp: C source, ASCII text
Solution
Check line endings type and change it acordingly.
I used unix2dos
command and then result for file was:
$ file /tmp/cmake-example/src/example.cpp /tmp/cmake-example/src/example.cpp: C source, ASCII text, with CRLF line terminators
Now everything work like a charm.
I hope this will help. For clarity: I'am using debian 9
The tool is still a bit buggy when it comes to patching. If a patch fails, there is no proper rollback and subsequent patches keep failing. You sometimes can fix this by restoring the original copy of the source file.
Hi! Thanks for providing this tool!
I have a similar problem as above. The mutation process just stops with this error in terminal:
Exception in thread Thread-2: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/Users/christofferochcamilla/Downloads/mutate_cpp-master/app/utils/Executor.py", line 42, in main self.workflow(patch) File "/Users/christofferochcamilla/Downloads/mutate_cpp-master/app/utils/Executor.py", line 89, in workflow self.__execute_command_timeout('patch -p1 --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename), cwd='/') File "/Users/christofferochcamilla/Downloads/mutate_cpp-master/app/utils/Executor.py", line 71, in __execute_command_timeout raise subprocess.CalledProcessError(errcode, command, stdout) subprocess.CalledProcessError: Command 'patch -p1 --input=/var/folders/py/kq1mb1057jx8cs_k656_k43h0000gn/T/tmp2sr_54xf /MySourceCode.cpp' returned non-zero exit status 1.
When I run the patch command as outputted in the console i get:
patching file /MySourceCode.cpp Hunk #1 FAILED at 1025. 1 out of 1 hunk FAILED -- saving rejects to file /MySourceCode.cpp.rej
When I read the cpp.rej file I don't get any clue of what is wrong. Tested both on a windows box and macosx.
Also, when generating patches the checkboxes doesnt seem to do anything. I selected only comparision operator but it seemed to generate patches for all options, include line deletions which this particular patch was (it was the first one, I have yet to be able to run any patch).
Thanks for any help!
So I read zawadsoons post above little more carefully and indeed I had the same problem. I could change both encoding and line-ending in CLion. Patches still failed randomly though so I wrote this in Executor.py on line 88:
try:
self.__execute_command_timeout('patch -p1 --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename), cwd='/')
# step 3: command pipeline
success = self.__apply_command(patch, 'build_command') and \
self.__apply_command(patch, 'quickcheck_command') and \
self.__apply_command(patch, 'test_command')
if success:
patch.state = 'survived'
db.session.commit()
# step 4: revert patch
self.__execute_command_timeout('patch -p1 --reverse --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename),
cwd='/')
except subprocess.CalledProcessError as e:
# patching failed
patch.state = 'survived'
print("Patching failed. Marking as survived.")
(markdown doesnt work well for that snipper)
I ran in that problem too. I had to regenerate the patches to make it work. However, to do it properly, I had to regenerate the project entirely (i.e. delete + new). Why? Because if I click Regenerate again and again, it ADDs the same patches over and over again. (i.e. 700, 1400, 2100, etc.) It should replace the patches. Delete the existing ones and create new ones with the current file content, but that's probably a different issue than this one.
To fix this one, we'd need to have a try/catch and avoid just dying on such errors. The patch may not apply properly because of recent changes right around the same location. i.e. click the "generate patches" button, edit code at a location which you know has a patch (i.e. a statement such as if(a == b)
) so that patch cannot be applied. Then try reproducing the error and add the necessary to avoid just dying on it.
Hey @AlexisWilke, thanks for your help and your recent MRs! In fact, the work on this project is dormant from my side: I am happy to merge any MRs, but I will not be able to contribute further in the foreseeable future.
File "/home/test/Desktop/mutate_cpp/app/utils/Executor.py", line 89, in workflow self.__execute_command_timeout('patch -p1 --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename), cwd='/') File "/home/test/Desktop/mutate_cpp/app/utils/Executor.py", line 71, in __execute_command_timeout raise subprocess.CalledProcessError(errcode, command, stdout) subprocess.CalledProcessError: Command 'patch -p1 --input=/tmp/tmpo7vp4cdf /home/test/Desktop/cmake-example/src/example.cpp' returned non-zero exit status 1
and also in reverse patch