Hi Toon! On Fri, Jun 5, 2009 at 8:09 AM, Toon Verstraelen<toon.verstrae...@ugent.be> wrote: > Hello, > > I'm writing a very initial version of a code generator. I would like to add > proper tests for the generated c code. The test will involve a compilation > with > gcc and linking against a small c program that tests the output of the > function > for several inputs. If some outputs are wrong, the negative return code can be > captured with a proper assert statement.
Excellent, thanks for looking into this, this is needed. > > I could not find existing tests that generate output files. What is the > recommended directory to write these files? I was thinking of > tempfile.mkdtemp, > but that makes it annoying to check the generated code manually. A temporary > test_output directory at the root level of the source tree with subdirectories > created by the tests seems convenient to me, but this involves changes in > setup.py, which runs the tests. './setup.py test' should create this directory > and './setup.py clean' should remove it enterily. Is this OK? I think we should test it using statements like: assert code_generate(<whatever>) == """\n int some_function(...) { return a*b-23; } """ That way you don't need a compiler and it will run even if gcc is not installed or not working properly, or if you are not allowed to create any files. Remember, that all tests need to run even if you install sympy and then do: import sympy sympy.test() Besides that, it's a good idea to also have tests, that actually compile things using gcc, as you suggested. For that, I suggest to create a new test sympy/test_external, for example "test_code_generation.py", that will work something like this: try: <try to write a file (if it works) and find a gcc executable (I am not sure if we should also test if gcc works here)> except <anything from above fails>: disabled = True def test_code1(): <generate C file> <compile it> <run it?> assert <all is fine> ... That way, if gcc is not installed, or you can't generate output files, the test will be skipped. It's the same philosophy as we use for test_numpy and test_sage. Ondrej These tests should be in regular sympy and --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---