ben-strasser / fast-cpp-csv-parser

fast-cpp-csv-parser
BSD 3-Clause "New" or "Revised" License
2.12k stars 439 forks source link

test code #12

Closed jkhoogland closed 8 years ago

jkhoogland commented 8 years ago

Hi, I was wondering if you had any test code/benchmarking code ?

I add some CMake logic to easily add bunches of gtest tests...

I would like to add an istream interface to LineReader, but before starting any coding, it would nice if there are some tests already I could add.

Cheers Jiri

ben-strasser commented 8 years ago

I was wondering if you had any test code/benchmarking code ?

None that is in a state that I'd put it in a public repro. ;)

I add some CMake logic to easily add bunches of gtest tests...

I would really prefer not to add further dependencies just for tests. Currently neither cmake nor gtest is needed.

I would like to add an istream interface to LineReader,

Newest version has support for this.

jkhoogland commented 8 years ago

well :) that sounds great!

Regarding tests, cmake and gtest. This is just something that is orthogonal to the library.

Usage of the library doesn't require any dependency.

I will push an example up to my fork.

jkhoogland commented 8 years ago

https://github.com/jkhoogland/fast-cpp-csv-parser

has an example of how this could work.

ben-strasser commented 8 years ago

My current cmake is older than the required 3.0 so I cannot run your script. Perhaps I should finally get around upgrading my distro. However, I'm not going to do this because of some csv test set.

Also I'm not convinced that gtest is superior for this particular application to a simple:

template<class A, class B>
inline expect_eq_check(const A&a, const B&b, const char*a_label, const char*b_label,int line_num){
    if(a != b){
        cout << "line " << line_num << " : " << a_label << " != "<< b_label << endl
            << "value of left side : " << (a) << endl
            << "value of right side : " << (b) << endl;
    }
}

#define EXPECT_EQ2(a,b,a_label,b_label, line_num) \
    expect_eq_check(a, b, a_label, b_label, line_num)

#define EXPECT_EQ(a, b) \
    EXPECT_EQ2(a,b,#a, #b, __LINE__)
int main(){
  // my tests
}

For a large software project with thousands of tests I buy that gtest has its advantages as for example testing does not abort at the first error but to test a single 1200 line header file...

jkhoogland commented 8 years ago

sure, you don't have to use gtest at all. It is just what i tend to use for my stuff. It can be discarded if you want. The benefit I like is that I can add a new test by adding

TEST( And, AnotherTest )
{
  // test code... 
}

CMake will pick up the test when regenerating the make file and I can use gtest to handle the main, it will register the new test.