0

I am trying to learn testing with makefiles . I searched online for a framework. Many people talked about "catch2" so I downloaded it. I read the tutorial in git and I've searched about it in many other webpages. I wrote this : mytests (without any suffix in the name) to check myprogram.cpp.

#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_MAIN 
#include "catch.hpp"

TEST_CASE("maximum space is","[myprogram]"){
    REQUIRE( myprogram(test.in1)==50)
    REQUIRE( myprogram(test.in2)==20)
    REQUIRE( myprogram(test.in3) ==1100)
    REQUIRE( myprogram(test.in4)==23)
    REQUIRE( myprogram(test.in5)==10);
}

The are many articles about how to write this and how to add features and specialisations or how to run it while choosing which tests to run and other stuff...
But I could not find somewhere explicitly explaining how to run this . I am a beginner . I know that I can run a single test in my program which takes as input a file, like that : ./myprogram test.in1 . So, what I need to type to use this testing framework??

tonythestark
  • 519
  • 4
  • 15
  • 2
    You would need to compile your test program and run it as you would do with any C++ program. Without knowing any details of the specific test framework, I assume that the `REQUIRE` lines would try to call a function named `myprogram` with the value of a structure field `in1` etc. of a variable `test` and compare the return value. This does **not** call a program named `myprogram` as you seem to think. – Bodo Apr 28 '21 at 11:26
  • 1
    Rename `mytests` to `mytests.cpp`, then compile it, and run it. – Eljay Apr 28 '21 at 12:15
  • @Bodo so how do I this? – tonythestark Apr 28 '21 at 13:29
  • With the little information in the question it is difficult to give specific instructions. Please [edit] your questions and add details about the tests you want to automate. Describe **in the question** what exactly you would do manually. If you want to run `./myprogram test.in1` and check the output, then a C++ unit test framework is not the correct tool. I never used a test tool for command line programs. See e.g. https://spin.atomicobject.com/2016/01/11/command-line-interface-testing-tools/ or https://stackoverflow.com/q/353198/10622916 or https://hackage.haskell.org/package/shelltestrunner – Bodo Apr 28 '21 at 14:45

0 Answers0