将 UNIX makefile 测试参数转换为 vs2010、C++ 的 msbuild

发布于 2024-10-27 22:09:59 字数 3817 浏览 1 评论 0原文

全面披露:这是一个学校项目。该项目是用 C++ 编写的。他们通常希望我们使用他们的实验室计算机,这些计算机是 UNIX 系统,这意味着 makefile 在实验室计算机上运行良好。但是,就像大多数实验室比较一样,它们都是垃圾。我已经因为他们的胡言乱语而失去了不止一个项目。但是,那既不在这里也不在那里。

正如我所说,我有这个 UNIX makefile。我不关心编译指令;我会让 msbuild 处理这个问题。我真正关心的是 makefile 末尾的测试过程。这些是我的项目必须通过的测试(使用另一个 .cpp 文件)才能进行评分。现在,我想在 vs 中完成这个项目,但我不确定如何将 UNIX makefile 中的指令转换为 msbuild 可以理解的内容。有没有办法将其添加到vs中的xml文件中?我应该使用构建后命令行选项来运行这些测试吗?我在这里最好的选择是什么?我包含了下面 makefile 中的相关代码。我知道我可以从命令行单独运行每个测试,但这将非常耗时。任何建议等,将不胜感激。谢谢!

请注意,我删除了其他文件的编译指令,因为它们(我认为)与我的问题无关。 代码:

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 

干净: rm -f core *.o HashTableTemplateTest HashTableVoidTest ListTemplateTest \ wcVoid wcTemplate out1 out2 test_results

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又怨 2024-11-03 22:09:59

首先,将其更改为DOS批处理文件。

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 ...

现在,在 Visual Studio 中

  • 右键单击项目名称
  • 从菜单中选择“属性”。
  • 在属性树中选择
    • 配置属性
      • 构建活动
        • 构建后事件
  • 将批处理文件作为“命令行”放入

应该可以做到这一点。

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



  • Put your batch file in as the "Command Line"

That should do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文