New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
L10n tests and better error handling #421
Conversation
|
Looks good. |
| try { | ||
| addL10nSubstitutionInner(tempNode, value, patterns, values); | ||
| } catch (L10nParseException e) { | ||
| Logger.error(this, "Error in l10n value \""+value+"\" for "+key+": "+e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's Logger.error(Object o, String s, Throwable e) for logging exceptions (it also logs the stack trace, which might be useful).
|
This is not a blocker, but something I'd like to add anyhow. I find the naming of the methods confusing. You currently have: Only the former two are specific to l10n (they pass / lookup keys), the latter two are generally applicable pattern substitution methods. Given the length of this chain, it's a bit odd to call As a suggestion, the following might be more clear:
|
|
Looks pretty sane in general, I only had some minor comments. Special thanks for creating the unit tests! |
Add some unit tests for BaseL10n.getString() and addL10nSubstitution().
Throw exceptions in BaseL10n.addL10nSubstitutionInner() when problems are encountered. Add wrapping tryAddL10nSubstitution() method which only applies changes to the node if no exception is thrown.
Always clone node before adding to parent in BaseL10n.addL10nSubstitutionInner(), to avoid errors and for consistency.
If there's an error in the l10n string in BaseL10n.addL10nSubstitutionInner(), use the default string instead.
Add test that tries to parse all l10n strings in order to find invalid ones.
If we encounter errors in both the current language's value and the fallback value for a key, return the key itself from addL10nSubstitution().
Pass l10n parse exception into Logger.error() instead of extracting the message ourselves.
Implement an iterator over the current language string, fallback language string, and literal key. Use in place of logic in getString(), getDefaultString(), and getL10nSubstitution().
|
Commits have "changed" due only to merging the first two. Other changes are in new commits. |
|
These tests do not pass on my machine. Have I misconfigured something perhaps? I ran |
Change buildfile to copy l10n test properties files into the unit test build dir.
|
Ah, my mistake. I was running without "ant clean", and eclipse had previously copied the test properties files into the build dir. I've added a task to the buildfile to copy them. |
|
Turns out these don't pass in Java 6: I'll look into it. Any ideas why? |
|
When it breaks under Java 6 it's looking for the override file here: "/home/steve/freenet/fred/run/file:/usr/lib/jvm/java-6-openjdk-common/jre/lib/ext/pulse-java.jar!/../test/freenet/l10n/freenet.l10n.en.override.properties". When it works under Java 7 it's looking for "/home/steve/Documents/Coding/freenet/fred/build/main/../test/freenet/l10n/freenet.l10n.en.override.properties". Looks like the classLoaderDir cannot be assumed to be reasonable. I'll see what the other tests with files do. |
Added some unit tests for l10n. Also changed addL10nSubstitutionInner() to address some problems like the one in bug 6386. Added a test that validates the l10n files, and fixed problems revealed by that test.