Convert UNIX makefile test paramaters to msbuild for vs2010, C++
Full disclosure: this is for a school project. The project is in C++. They usually want us to use their lab computers, which are UNIX systems, which means that the makefile works fine on the lab comps. But, like most lab comps, they are pieces of crap. I've lost more than one project to their nonsense. But, that is neither here nor there.
As I said, I have this UNIX makefile. I don't care about the compilation instructions; I will let msbuild handle that. What I do care about are the testing procedures at the end of the makefile. These are the tests (using another .cpp file) that my project must pass in order for it to be graded. Now, I would like to do this project in vs, but I am not sure how to convert the instructions from the UNIX makefile into something that msbuild can understand. Is there a way to add this to the xml file in vs? Should I use a post-build command line option to run these tests? What is my best option here? I included the relevant code from the makefile below. I know I can just run each test separately from the command line, but that would be excruciatingly time-consuming. Any advice, etc., would be greatly appreciated. Thanks!
Note that I removed the compile instructions for the other files as they (I don't think) are relevant to my question. CODE:
test:
rm -f test_results
ListTemplateTest && \
(echo "ListTemplateTest OK" >> test_results) || \
(echo "ListTemplateTest Failed" >> test_results) && \
HashTableTemplateTest test1 && \
(echo "HashTableTemplateTest test1 OK" >> test_results) || \
(echo "HashTableTemplateTest test1 Failed" >> test_results) && \
HashTableTemplateTest test2 && \
(echo "HashTableTemplateTest test2 OK" >> test_results) || \
(echo "HashTableTemplateTest test2 Failed" >> test_results) && \
HashTableTemplateTest test3 && \
(echo "HashTableTemplateTest test3 OK" >> test_results) || \
(echo "HashTableTemplateTest test3 Failed" >> test_results) && \
HashTableTemplateTest test4 && \
(echo "HashTableTemplateTest test4 OK" >> test_results) || \
(echo "HashTableTemplateTest test4 Failed" >> test_results) && \
HashTableTemplateTest test5 && \
(echo "HashTableTemplateTest test5 OK" >> test_results) || \
(echo "HashTableTemplateTest test5 Failed" >> test_results) && \
HashTableTemplateTest test6 && \
(echo "HashTableTemplateTest test6 OK" >> test_results) || \
(echo "HashTableTemplateTest test6 Failed" >> test_results) && \
HashTableVoidTest test1 && \
(echo "HashTableVoidTest test1 OK" >> test_results) || \
(echo "HashTableVoidTest test1 Failed" >> test_results) && \
HashTableVoidTest test2 && \
(echo "HashTableVoidTest test2 OK" >> test_results) || \
(echo "HashTableVoidTest test2 Failed" >> test_results) && \
HashTableVoidTest test3 && \
(echo "HashTableVoidTest test3 OK" >> test_results) || \
(echo "HashTableVoidTest test3 Failed" >> test_results) && \
HashTableVoidTest test4 && \
(echo "HashTableVoidTest test4 OK" >> test_results) || \
(echo "HashTableVoidTest test4 Failed" >> test_results) && \
HashTableVoidTest test5 && \
(echo "HashTableVoidTest test5 OK" >> test_results) || \
(echo "HashTableVoidTest test5 Failed" >> test_results) && \
HashTableVoidTest test6 && \
(echo "HashTableVoidTest test6 OK" >> test_results) || \
(echo "HashTableVoidTest test6 Failed" >> test_results) && \
(wcVoid greetings.txt | sort > out1) && (wcVoidExample greetings.txt | sort > out2) && \
diff out1 out2 && \
(echo "wcVoid greetings.txt OK" >> test_results) || \
(echo "wcVoid greetings.txt Failed" >> test_results) &开发者_如何学编程& \
(wcTemplate greetings.txt | sort > out1) && (wcVoidExample greetings.txt | sort > out2) && \
diff out1 out2 && \
(echo "wcTemplate greetings.txt OK" >> test_results) || \
(echo "wcTemplate greetings.txt Failed" >> test_results) && \
echo && \
echo ------ Test Results ----- && \
cat test_results
clean: rm -f core *.o HashTableTemplateTest HashTableVoidTest ListTemplateTest \ wcVoid wcTemplate out1 out2 test_results
First of all, change it to a DOS batch file.
test:
del /Q /F test_results
ListTemplateTest
if NOT ERRORLEVEL 1
echo "ListTemplateTest OK" >> test_results
if ERRORLEVEL 1
echo "ListTemplateTest Failed" >> test_results
HashTableTemplateTest test1
if NOT ERRORLEVEL 1
echo "HashTableTemplateTest test1 OK" >> test_results
if ERRORLEVEL 1
echo "HashTableTemplateTest test1 Failed" >> test_results
etc ...
Now, in Visual Studio
- Right click on the project name
- Select "Properties" from the menu.
- In the property tree select
- Configuration Properties
- Build Events
- Post-Build Event
- Post-Build Event
- Build Events
- Configuration Properties
- Put your batch file in as the "Command Line"
That should do it.
精彩评论