Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Sep 2, 2021
1 parent a58376c commit 3702765
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/tmp/
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributions guide

You only need Inkscape>=1.0, [xvfb][xvfb-package] and a posix shell to develop
and test.

## Make changes to the code

1. Move [text_braille_l18n.inx][ext-inx] and [text_braille_l18n.py][ext-py]
files to your user's extensions directory. If you don't know its location,
open it from `Edit` -> `Preferences` -> `System` -> `Users extensions`.
1. Edit the code there.
1. Once edited and manually tested, move the files to this repository, it's
time to run tests.

## Test your changes

- `sh tests/run.sh`: Run tests.
- `DEBUG=1 sh tests/run.sh`: Run tests showing all executed commands (mainly
for tests script debugging).

You'll see that a folder is created under `tests/tmp/` where the output for
every locale is stored.

[xvfb]: https://packages.debian.org/es/sid/xvfb
[ext-inx]: https://github.com/mondeja/inkscape-braille-l18n-ext/blob/master/text_braille_l18n.inx
[ext-py]: https://github.com/mondeja/inkscape-braille-l18n-ext/blob/master/text_braille_l18n.py
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Text-to-Braille Inkscape extension with multiple localized alphabets.
## Installation

1. [Download][download-repo] and extract this repository.
1. Move [text_braille_l18n.inx][ext-inx] and [text_braille_l18n.py][ext-py] files to your user's
extensions directory. If you don't know its location, open it from `Edit` ->
`Preferences` -> `System` -> `Users extensions`.
1. Move [text_braille_l18n.inx][ext-inx] and [text_braille_l18n.py][ext-py]
files to your user's extensions directory. If you don't know its location,
open it from `Edit` -> `Preferences` -> `System` -> `Users extensions`.
1. Run Inkscape and you'll see the extension in `Extensions` -> `Text`.

## Usage
Expand Down
6 changes: 6 additions & 0 deletions tests/ca.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵
⠨⠁⠨⠃⠨⠉⠨⠙⠨⠑⠨⠋⠨⠛⠨⠓⠨⠊⠨⠚⠨⠅⠨⠇⠨⠍⠨⠝⠨⠕⠨⠏⠨⠟⠨⠗⠨⠎⠨⠞⠨⠥⠨⠧⠨⠺⠨⠭⠨⠽⠨⠵
⠀⠐⠄'⠐⠠⠂⠦^⠨⠂⠂⠔⠐⠅⠤⠄⠸⠴[⠸⠎⠖⠖⠯⠆⠒⠣_⠢]#⠜⠶⠖⠲
⠼⠚⠼⠁⠼⠃⠼⠉⠼⠙⠼⠑⠼⠋⠼⠛⠼⠓⠼⠊
á⠿⠌⠪⠾⠷⠮ì⠬ùäë⠻ö⠳Á⠨⠿⠨⠌⠨⠪⠨⠾⠨⠷⠨⠮Ì⠨⠬ÙÄË⠨⠻Ö⠨⠳
⠯⠨⠯⠸⠴⠸⠴⠴⠣⠨⠉⠜⠣⠨⠗⠜⠣⠨⠏⠜⠣⠨⠇⠜⠠⠂⠐⠄⠐⠅⠨⠂⠸⠇⠐⠇⠸⠂⠤⠤⠸⠑⠸⠎⠘⠉⠐⠮⠸⠽⠸⠽
6 changes: 6 additions & 0 deletions tests/en.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵
⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵
⠀⠳⠄⠈⠌⠐⠘⠜⠠⠡⠣⠤⠨⠩⠪⠫⠬⠮⠯⠰⠱⠷⠸⠹⠻⠼⠾⠿⠬÷
⠴⠂⠆⠒⠲⠢⠖⠶⠦⠔
áéíóúàèìòùäëïöüÁÉÍÓÚÀÈÌÒÙÄËÏÖÜ
çÇ⠩‰©®℗🄯⠌⠳⠣⠜|{}—€⠫¢£¥¥
6 changes: 6 additions & 0 deletions tests/es.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵
⠨⠁⠨⠃⠨⠉⠨⠙⠨⠑⠨⠋⠨⠛⠨⠓⠨⠊⠨⠚⠨⠅⠨⠇⠨⠍⠨⠝⠨⠕⠨⠏⠨⠟⠨⠗⠨⠎⠨⠞⠨⠥⠨⠧⠨⠺⠨⠭⠨⠽⠨⠵
⠀⠐⠄'⠐⠠⠂⠦^⠨⠂⠂⠔⠐⠅⠤⠄⠸⠴[⠸⠎⠖⠖⠯⠆⠒⠣_⠢]#⠜⠶⠖⠲
⠼⠚⠼⠁⠼⠃⠼⠉⠼⠙⠼⠑⠼⠋⠼⠛⠼⠓⠼⠊
⠷⠮⠌⠬⠾àèìòùäëïö⠳⠨⠷⠨⠮⠨⠌⠨⠬⠨⠾ÀÈÌÒÙÄËÏÖ⠨⠳
çÇ⠸⠴⠸⠴⠴⠣⠨⠉⠜⠣⠨⠗⠜⠣⠨⠏⠜⠣⠨⠇⠜⠠⠂⠐⠄⠐⠅⠨⠂⠸⠇⠐⠇⠸⠂⠤⠤⠸⠑⠸⠎⠘⠉⠐⠮⠸⠽⠸⠽
6 changes: 6 additions & 0 deletions tests/eu.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵
⠨⠁⠨⠃⠨⠉⠨⠙⠨⠑⠨⠋⠨⠛⠨⠓⠨⠊⠨⠚⠨⠅⠨⠇⠨⠍⠨⠝⠨⠕⠨⠏⠨⠟⠨⠗⠨⠎⠨⠞⠨⠥⠨⠧⠨⠺⠨⠭⠨⠽⠨⠵
⠀⠐⠄'⠐⠠⠂⠦^⠨⠂⠂⠔⠐⠅⠤⠄⠸⠴[⠸⠎⠖⠖⠯⠆⠒⠣_⠢]#⠜⠶⠖⠲
⠼⠚⠼⠁⠼⠃⠼⠉⠼⠙⠼⠑⠼⠋⠼⠛⠼⠓⠼⠊
⠷⠮⠌⠬⠾àèìòùäëïö⠳⠨⠷⠨⠮⠨⠌⠨⠬⠨⠾ÀÈÌÒÙÄËÏÖ⠨⠳
çÇ⠸⠴⠸⠴⠴⠣⠨⠉⠜⠣⠨⠗⠜⠣⠨⠏⠜⠣⠨⠇⠜⠠⠂⠐⠄⠐⠅⠨⠂⠸⠇⠐⠇⠸⠂⠤⠤⠸⠑⠸⠎⠘⠉⠐⠮⠸⠽⠸⠽
6 changes: 6 additions & 0 deletions tests/gl.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵
⠨⠁⠨⠃⠨⠉⠨⠙⠨⠑⠨⠋⠨⠛⠨⠓⠨⠊⠨⠚⠨⠅⠨⠇⠨⠍⠨⠝⠨⠕⠨⠏⠨⠟⠨⠗⠨⠎⠨⠞⠨⠥⠨⠧⠨⠺⠨⠭⠨⠽⠨⠵
⠀⠐⠄'⠐⠠⠂⠦^⠨⠂⠂⠔⠐⠅⠤⠄⠸⠴[⠸⠎⠖⠖⠯⠆⠒⠣_⠢]#⠜⠶⠖⠲
⠼⠚⠼⠁⠼⠃⠼⠉⠼⠙⠼⠑⠼⠋⠼⠛⠼⠓⠼⠊
⠷⠮⠌⠬⠾àèìòùäëïö⠳⠨⠷⠨⠮⠨⠌⠨⠬⠨⠾ÀÈÌÒÙÄËÏÖ⠨⠳
çÇ⠸⠴⠸⠴⠴⠣⠨⠉⠜⠣⠨⠗⠜⠣⠨⠏⠜⠣⠨⠇⠜⠠⠂⠐⠄⠐⠅⠨⠂⠸⠇⠐⠇⠸⠂⠤⠤⠸⠑⠸⠎⠘⠉⠐⠮⠸⠽⠸⠽
53 changes: 53 additions & 0 deletions tests/input.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 141 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/sh

: '
Tests for braille-l18n Inkscape extension. You must have Inkscape installed
in order to run this script. WARNING: if braille-l18n extension files are
found inside your user extensions directory will be overwritten by the
development files located in this directory!
Environment variables:
- DEBUG: If not empty, all executed commands will be shown in the output.
'

error() {
printf "$1" >&2
}

configure_script() {
set -e
if [ -n "$DEBUG" ]; then
set -x
fi

if [ ! -f "text_braille_l18n.inx" ]; then
error "You must be at the root of the directory to execute the tests.\n"
exit 1
fi
}

prepare_tmp_folder() {
rm -rf tests/tmp/
mkdir tests/tmp/
}

print_user_extensions_directory() {
printf "$(inkscape --user-data-directory)/extensions"
}

move_extension_to_user_extensions_directory() {
extensions_directory="$(print_user_extensions_directory)"
rm -f "$extensions_directory/text_braille_l18n.*"
cp text_braille_l18n.* "$extensions_directory"
}

: '
Configure preferences.xml file so the extension braille-l18n can be
configured to use the parameters specified for the test.
$1 - Locale parameter.
'
configure_profile_preferences() {
locale="$1"
preferences_filepath="$(inkscape --user-data-directory)/preferences.xml"
locale_pref="$(< $preferences_filepath grep -o "org.inkscape.text.braille-l18n.locale")"

# if locale preference is present
if [ -n "$locale_pref" ]; then
# replace value with locale passed as function argument
sed -i -r "s/org.inkscape.text.braille-l18n.locale=\"(.+)\"/org.inkscape.text.braille-l18n.locale=\"$locale\"/g" "$preferences_filepath"
else
# add extension preference after 'id="extensions"' line (extensions group)
sed -i "s/id=\"extensions\"/&\n org.inkscape.text.braille-l18n.locale=\"$locale\"/g" "$preferences_filepath"
fi;
}

get_locales() {
echo "$(< "$PWD/text_braille_l18n.inx" grep '<option value=' | cut -d'"' -f2)"
}

: '
Extract Braille output from a produced SVG running a test using Inkscape,
for further comparison.
$1 - Path to the SVG file which Braille output will be extracted.
'
extract_svg_output_text() {
< "$1" grep 'id="tspan' | cut -d'>' -f2
}

test_extension_effect() {
locale="$1"
svg_output_filepath="$PWD/tests/tmp/$locale.out.svg"
txt_output_filepath="tests/tmp/$locale.out.txt"
txt_expect_filepath="tests/$locale.expect.txt"

if [ ! -f "$txt_expect_filepath" ]; then
error "File '$txt_expect_filepath' was expected to exist but not found!\nTests aborted.\n"
exit 1
fi;

printf "TEST: locale=$locale\n"

# configure parameters for extension
configure_profile_preferences "$locale"

# run extension using inkscape in headless mode with Xvfb
xvfb-run inkscape \
--batch-process \
--export-plain-svg \
--vacuum-defs \
--actions="select-by-element:text;org.inkscape.text.braille-l18n.noprefs;export-filename:$svg_output_filepath;export-do" \
tests/input.svg

# extract braille output from produced SVG and save in other file
extract_svg_output_text "$svg_output_filepath" > "$txt_output_filepath"

if ! diff --brief "$txt_output_filepath" "$txt_expect_filepath"; then
printf "Red: $txt_output_filepath - Green: $txt_expect_filepath\n"
# ignore error (or file exits due to 'set -e')
diff --color "$txt_output_filepath" "$txt_expect_filepath" || true
printf "\n"
printf "1" > "tests/tmp/exitcode"
fi
}

run_tests() {
# read possible locales from inx extension file
get_locales | tr ' ' '\n' | while read locale; do
test_extension_effect "$locale"
done
}

cleanup_and_exit() {
if [ -f "tests/tmp/exitcode" ]; then
exitcode="$(cat tests/tmp/exitcode)"
rm tests/tmp/exitcode
else
exitcode=1
fi
exit $exitcode
}

main() {
configure_script
prepare_tmp_folder
move_extension_to_user_extensions_directory
run_tests
cleanup_and_exit
}

main
4 changes: 2 additions & 2 deletions text_braille_l18n.inx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="https://www.inkscape.org/namespace/inkscape/extension">
<_name>Convert to localized Braille</_name>
<id>org.inkscape.TextBrailleL18n</id>
<name>Convert to localized Braille</name>
<id>org.inkscape.text.braille-l18n</id>

<dependency type="executable" location="extensions">text_braille_l18n.py</dependency>

Expand Down

0 comments on commit 3702765

Please sign in to comment.