Updating Correct files after Changing Error Messages
MDELite
tests are based on file regression tests. That is, an MDELite
program produces a file. During a regression test, a new file is
produced and it is compared with a "Correct" version of this file.
If exactly the same text appears in both files, the regression
test passes.
Now
this becomes problem if error messages are updated, even slightly.
Tracking down small textual changes in hundreds of files is
extraordinarilly time consuuming. So I built a tool that takes
converts statements made by outdated Error and ParsE error reports and
refresh these statements with the new format.
Example: An Error is an enum with a value and a "parameterized explanation", like so:
anError("in file FILE you should have named variable VAR1 to VAR2")
In
the string explanation, all words that are in all CAPITALS (and that
they are not just one character long) are treated as String parameters.
When this error is reported, arguments for these parameters must
be provided, as in:
Error.throw(Error.anError, filename, varname1, varname2);
The
anError String is converted into a Java format string "in file %s
you should have named variable %s to %s" and then arguments are
supplied for each string %s marker.
So here's how the tool
works: it read a Correct file and for each line, the tool sees if it
can parse the line as an existing parameterized explanation. If
so, it then rewrite the line using the new parameterized
explanation string. The tool does this for every file in a
Correct directory for all Correct directories under test/.
How to invoke the Update Correct Files Tool
Before you do anything, make sure that all regression tests of MDELite7 work. Next do the following:- In the CorrectResultsAfterChangingErrorMsgs/ directory, delete Error.java and ParsE.java.
- Copy via refactoring the MDELite/ directory files Error.java and ParsE.java to the CorrectResultsAfterChangingErrorMsgs/ directory.
- Copy the entire test/ directory of MDELite7 and rename the copy testBackup/. The testBackup directory should be the same directory as test/.
At
this point, you are ready to proceed to edit MDELite/Error.java and
MDELite/ParsE.java to change the error messages to that which you want
to use.
Once you have made all your message changes, it is time to update the Correct directories. Here's how to do this:
- Compile MDELite7 to make sure there are no type errors.
- Run
UpdateCorrectFiles.java from the Netbeans IDE. It will post a
Java GUI dialog to remind you of the three things that you should
have done above. Then it will ask for a password -- which you can
extract from the code of UpdateCorrectFiles.java. If the password
you supply is correct, all Correct files will be updated accordingly.
This update should take but a few seconds at most.
- Next, compile MDELite7 again, and run the regression tests. If
the update was correctly performed -- and it should.... --- you should
get no errors and that the correct files are now using the latest
Error explanations.