From: Brian H. <bh...@sp...> - 2003-06-04 22:02:57
|
On Thu, 5 Jun 2003, Mikhail Fedotov wrote: > Hi! > > This won't be unit testing in the usual sense then. Unit > testing covers external interface of the library; the main > point is to figure out that something is broken; as long as > it is known, it is easy to find exact error line, even by > putting "let () = print_string error_here in" in the code. > > Including tests for internal functions does not buy much > but makes the whole thing more complex. This kind of > testing is usually implemented by inserting asserts in C > code and by raising Invalid_argument in some ocaml > functions. My general experience has been that the smaller the hunk of code you test, the more likely you are to find problems and the easier it is to get full coverage (all possible conditions are tested). Yes, this makes things more complex. What I want is classic C conditional compilation. I want to be able to do "make test" which builds a copy of the libraries with unit testing enabled, and runs the unit tests. "make" would then build copies of the library sans the unit test code for "production". Asserts get used *in addition to* strong type checking and unit tests. And stay in the final "production" code. Yes, this is way overkill. As the guy said when asked what do with his mother-in-law's mortal remains, "embalm, cremate, then bury. Take no chances." > > If you really need to test internal function I think (with > my limited ocaml expirience) that it is possible to compile > a special version of the library by copying library.ml to > testlibrary.ml and creating the specil version of the > library out of it which would include all the functions. I > don't remember if .mli file is strictly required (I've > never tried to build a library without it), but if it is > not, then it is even easier. > This is what I was talking about when I mentioned "makefile hacks". Unfortunately, I know enough about the build environment of Windows (despite several years busily repressing memories) that I am wary of doing and scripting hacks. The only scripting language I am sure exists is Ocaml. Hmm. That might be enough. All I need to do is: - move the original code foo.ml to a backup file. - concatenate the original code and the unit test code into the new foo.ml - do the same with foo.mli - Compile foo.ml[i] - run the unit tests - delete the new foo.ml[i] - move the originals back Brian |