Created
October 14, 2012 21:34
-
-
Save tomthorogood/3889884 to your computer and use it in GitHub Desktop.
Easy VimDiff for Stanford compilers VM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # | |
| # Note! The VM has Python 2.6.6, which does not have argparse installed by default. | |
| # | |
| # You can fix this by running the following two commands: | |
| # sudo apt-get install python-pip | |
| # sudo pip install argparse | |
| # | |
| # Make sure to chmod +x opencompare.py | |
| # Then you can do ./opencompare.py test_name | |
| # | |
| # You do not need to add the "cl.cool.out" extension or the `grading` directory. This will take care of it for you. | |
| # it will open up a window of the expected output on the left, and your actual output on the right. | |
| from os import system | |
| from argparse import ArgumentParser | |
| parser = ArgumentParser() | |
| parser.add_argument( | |
| "test_name", | |
| nargs="+", | |
| type=str, | |
| action="store", | |
| help="The test for which you want to see the comparison") | |
| args = parser.parse_args() | |
| def clean_str(string): | |
| if (".") in string: | |
| return string.split(".")[0] | |
| else: return string | |
| def expected_output(testname): | |
| tname = testname+".cl.cool.out" | |
| return "grading/"+tname | |
| def actual_output(testname): | |
| tname = testname+".cl.cool.out.unfilt" | |
| return "grading/test-output/"+tname | |
| def file_exists(f, direct): | |
| return f.split("/")[-1] in listdir(direct) | |
| test = clean_str(args.test_name[0]) | |
| expect = expected_output(test) | |
| actual = actual_output(test) | |
| if not file_exists(expect, "grading"): | |
| expect = expect.replace(".cl","") | |
| if not file_exists(actual, "grading/test-output"): | |
| actual = actual.replace(".cl","") | |
| system("vimdiff %s %s" % (expect, actual)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment