20,741
edits
m (→Status 06/2013: http://sourceforge.net/p/flightgear/mailman/message/31708442/) |
m (clever wiki ...) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{infobox subsystem | |||
|image = | |||
|name =Nasal Unit Testing Framework | |||
|started= 02/2014 (stalled) | |||
|description = Unit Testing support for Nasal | |||
|status = RFC | |||
|maintainers = F-JYL, dbelcham, Hooray, Philosopher | |||
|developers = dbelcham, F-JYL (since 02/2014), | |||
}} | |||
{{Template:Nasal Navigation}} | {{Template:Nasal Navigation}} | ||
Line 4: | Line 15: | ||
We do not currently have any established unit testing framework for Nasal. For the time being, this whole discussion is just about coming up with the requirements and a possible design. | We do not currently have any established unit testing framework for Nasal. For the time being, this whole discussion is just about coming up with the requirements and a possible design. | ||
The intent is to explore the idea of being able to run isolated unit tests against Nasal scripts. The idea was being able to do something like this: | The intent is to explore the idea of being able to run isolated unit tests against Nasal scripts. The idea was being able to do something like this: | ||
See also {{flightgear commit|d7a680}}. | |||
=== Concept === | === Concept === | ||
< | <syntaxhighlight lang="bash"> | ||
standalone-nasal.exe ATR72-FMC-tests.nas | standalone-nasal.exe ATR72-FMC-tests.nas | ||
</ | </syntaxhighlight> | ||
and see output like this: | and see output like this: | ||
< | <syntaxhighlight> | ||
When_calculating_deflection_that_is_greater_than_the_provided_maximum | When_calculating_deflection_that_is_greater_than_the_provided_maximum | ||
the_provided_maximum_should_be_returned (failed: expected 180 was 99) | the_provided_maximum_should_be_returned (failed: expected 180 was 99) | ||
Line 17: | Line 30: | ||
When_calculating_deflection_from_33_degrees_to_90_degrees | When_calculating_deflection_from_33_degrees_to_90_degrees | ||
the_result_should_be_67_degrees (failed: expected 67 was 66) | the_result_should_be_67_degrees (failed: expected 67 was 66) | ||
</ | </syntaxhighlight> | ||
Line 23: | Line 36: | ||
Based on what I read about the current stand-alone interpreter this should be fairly easy to do. That should now be possible, the nasal-standalone branch builds successfully for Windows (make sure to have boost available for building cppbind): | Based on what I read about the current stand-alone interpreter this should be fairly easy to do. That should now be possible, the nasal-standalone branch builds successfully for Windows (make sure to have boost available for building cppbind): | ||
Here's the Nasal standalone interpreter as part of SimGear: | Here's the Nasal standalone interpreter as part of SimGear: {{gitorious source|proj=fg|repo=hoorays-simgear|branch=topics/nasal-standalone|view=shortlog}} | ||
Just check out the branch named "nasal-bin". | Just check out the branch named "nasal-bin". | ||
To build it: | To build it: | ||
< | <syntaxhighlight lang="bash"> | ||
cd $SG_SRC | |||
mkdir BUILD | |||
cd BUILD | |||
cmake ../ -DENABLE_TESTS=ON -DSIMGEAR_HEADLESS=ON -DENABLE_SOUND=OFF -DENABLE_LIBSVN=OFF | |||
make | |||
</ | </syntaxhighlight> | ||
Basically | Basically | ||
*create and use a separate build folder, separate from the source tree | * create and use a separate build folder, separate from the source tree | ||
* configure the build via -DENABLE_TESTS=ON -DSIMGEAR_HEADLESS=ON -DENABLE_SOUND=OFF -DENABLE_LIBSVN=OFF | * configure the build via -DENABLE_TESTS=ON -DSIMGEAR_HEADLESS=ON -DENABLE_SOUND=OFF -DENABLE_LIBSVN=OFF | ||
* build | * build | ||
Line 50: | Line 59: | ||
Let us know if there are still any windows-specific build errors so that we can fix the config file. It should give you a "nasal-bin.exe" in $SG_BUILD/simgear/nasal/ that runs just Nasal scripts, no FG APIs whatsoever - you '''need''' to pass a valid Nasal script when running the file. | Let us know if there are still any windows-specific build errors so that we can fix the config file. It should give you a "nasal-bin.exe" in $SG_BUILD/simgear/nasal/ that runs just Nasal scripts, no FG APIs whatsoever - you '''need''' to pass a valid Nasal script when running the file. | ||
You should be able to "make test" to run a bunch of standard Nasal tests from the original Nasal repository, which are to be found in $SG_SRC/nasal/tests: | You should be able to "make test" to run a bunch of standard Nasal tests from the original Nasal repository, which are to be found in $SG_SRC/nasal/tests: {{gitorious source|proj=fg|repo=hoorays-simgear|view=tree|branch=topics/nasal-standalone|path=simgear/nasal/tests}} | ||
Meanwhile, the build actually works for Windows using the MingW compiler - providing a nasal-bin.exe, which I cannot test currently because I don't have a Windows VM available: http://www.speedyshare.com/MbBTA/download/nasal-bin.exe | Meanwhile, the build actually works for Windows using the MingW compiler - providing a nasal-bin.exe, which I cannot test currently because I don't have a Windows VM available: http://www.speedyshare.com/MbBTA/download/nasal-bin.exe{{dead link}} | ||
To run it, open a shell (START/EXECUTE cmd/command) and go to the folder of the binary, add a simple Nasal script and run "nasal-bin script.nas", i.e. use one of the scripts in: | To run it, open a shell (START/EXECUTE cmd/command) and go to the folder of the binary, add a simple Nasal script and run "nasal-bin script.nas", i.e. use one of the scripts in: {{gitorious source|proj=fg|repo=hoorays-simgear|view=tree|branch=topics/nasal-standalone|path=simgear/nasal/tests}} | ||
=== Roadmap === | === Roadmap === | ||
Line 64: | Line 73: | ||
Once we have those three things we would be able to write and execute tests independent of FG and still have them be meaningful. The key thing to remember is that this would be only for isolated unit tests. For integration tests (verifying that different systems, whether 2 different scripts/methods/application, work together correctly) we would need to think about a different approach. | Once we have those three things we would be able to write and execute tests independent of FG and still have them be meaningful. The key thing to remember is that this would be only for isolated unit tests. For integration tests (verifying that different systems, whether 2 different scripts/methods/application, work together correctly) we would need to think about a different approach. | ||
It should be doable to teach the nasal-bin.exe to check $FG_ROOT, and use that if available to load a semi-plausible FG environment (API-wise) - using some fancy | It should be doable to teach the nasal-bin.exe to check $FG_ROOT, and use that if available to load a semi-plausible FG environment (API-wise) - using some fancy meta-programming tricks, most of the default APIs could probably be wrapped, without too much manual work involved. Philosopher could be truly instrumental here, because he really has a deep understanding of some of the more esoteric tricks that can be done in Nasal space, referring to advanced uses of compile(), bind(), call(), closure() and caller() - which make meta-programming a fantastic experience. Basically, familiarity with this handful of APIs, can save tons of time: http://plausible.org/nasal/ | ||
There's quite a lot of stuff possible in Nasal, that nobody ever used in FG - Philosopher has started writing a bunch of tutorials, for example see: | There's quite a lot of stuff possible in Nasal, that nobody ever used in FG - Philosopher has started writing a bunch of tutorials, for example see: [[Nasal Meta-Programming]] | ||
And you can take a look at some of the scripts in the standalone branch, which support fancy constructs like dependency resolution using import("foo"); but also completely sandboxed/wrapped environments: | And you can take a look at some of the scripts in the standalone branch, which support fancy constructs like dependency resolution using import("foo"); but also completely sandboxed/wrapped environments: {{gitorious source|proj=fg|repo=hoorays-simgear|view=tree|branch=topics/nasal-standalone|path=simgear/nasal/tests}} | ||
These are regression tests developed by the Nasal developer himself, so not true unit testing - but only regression tests for the interpreter itself. | These are regression tests developed by the Nasal developer himself, so not true unit testing - but only regression tests for the interpreter itself. | ||
=== Contributing === | === Contributing === | ||
If possible, new code should be contributed | If possible, new code should be contributed to the maintainers, ideally even a branch of FG_ROOT, because that will make it easier to directly integrate such a unit testing system with all the code we got in $FG_ROOT/Nasal. | ||
== Problem == | == Problem == |