Testing a C ++ module using a scripting language

I would like to use some scripting languages ​​to do unit testing of C ++ code. It would be easier to develop tests in a scripting language, given that it has access to the required C ++ functions.

I mean Ruby or Perl (because I am familiar with them). It seems that I could use SWIG to interact with C ++ code.

Are there any better alternatives to SWIG ? What scripting language would you personally use for this purpose?

And finally, is it appropriate (and effective) to use this approach for testing?

+3
source share
3 answers

Inline: CPP ++ Perl.

script ( script):

perl -MInline=FORCE,NOISY,NOCLEAN test.pl
+3

++ , Perl-, , TAP.

TAP , ++.

GitHub libtap ++.

#include <tap++.h>
#include <string>

using namespace TAP;

int foo() {
  return 1;
}

std::string bar() {
  return "a string";
}

int main() {
  plan(3);
  ok(true, "This test passes");
  is(foo(), 1, "foo() should be 1");
  is(bar(), "a string", "bar() should be \"a string\"");
  return exit_status();
}

- :

1..3
ok 1 - This test passes
ok 2 - foo() should be 1
ok 3 - bar() should be "a string"

prove, Test:: .


- , , .

+2

If you write C code and compile it using the C ++ compiler, you can use a different language for testing.

But not for code written in C ++ style.

How do you verify the correctness and uptime of copying, assignment, overloading? What about patterns? No scripting language will call them in the same way that C ++ does; many do not even have the concept of pass-by-value.

Test the environment that you intend to use ultimately to use the code.

+1
source

All Articles