| || |
Formal language for functional tests / code gen.
in my company, we are frequently dealing with functional tests ensuring the integrity of XML-files.
Those tests are usually described like this:
If the header type equals 1 and the sum of the items in the body is less then five or the body does not exist at all, then set error code 001.
Inherently, this is a pretty error-prone method, because the programmer implementing this test might read the code as:
IF /Header/Type = 1 AND (SUM /body/items = 1 OR /body IS NULL) SET ERROR 001
IF (/Header/Type = 1 AND SUM /body/items = 1) OR /body IS NULL SET ERROR 001
Thus, it would be great to have some formal language describing the intended behavior.
Furthermore, it would be even better to have some automated code generator which automatically generates the required source code to implement the desired functionality.
So, is there any formal language available to achieve this?
And, do you have any code generator (or may be some other idea?) in mind to have the source code generated automatically?
Thanks in advance!
Re: Formal language for functional tests / code gen.
What you're looking for is pseudocode. Anything that is hard to read in plain English, but is still supposed to be logically structured, is usually better written in pseudocode. Wikipedia puts it well:
"Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of some programming language, but is intended for human reading rather than machine reading."
There's no standard syntax for pseudocode. The two examples you gave would be great ways of replacing the plain English text. Another example, assuming the second grouping is the right way, would be:
<font class="small">Code:</font><hr /><pre>IF (Header type = 1 AND Number of body items < 5) OR Body is NULL Then:
Set Error Code 001</pre><hr />
I would pick a syntax that is similar to the language that your developers are using.
I don't know much about programs that convert pseudocode into executable code, but you could start by looking at the wikipedia article on pseudocode. Also, abstract state machines provide a formal language and look like they provide a method of executing the high-level code.