[Commits] [SCM] clawsker branch, master, updated. 1.3.0-14-ga8bd715

mones at claws-mail.org mones at claws-mail.org
Sun Dec 23 11:27:53 CET 2018


The branch, master has been updated
       via  a8bd715931c5de62e4a863aebe0eb8bbec6329df (commit)
       via  e86458a81c38ee7656121963e17745898c57620c (commit)
       via  6fa96fa78f6258de6e5a2f8de9718c4c4aad50c0 (commit)
       via  f8655190a90a0b49985de13e1f73afc3e8985b6f (commit)
       via  efd3d0a4628b5583548f414fca3cba5a86647851 (commit)
      from  88e808ee45f319a125a1f2a70265793fb176f177 (commit)

Summary of changes:
 .gitignore                   |    1 +
 Makefile                     |   11 ++++-
 clawsker                     |   97 +++++++++++++++++++++---------------------
 t/get_app_icons.t            |   17 ++++++++
 t/get_claws_version.t        |   52 ++++++++++++++++++++++
 t/str_rgba.t                 |   35 +++++++++++++++
 t/version_greater_or_equal.t |   45 ++++++++++++++++++++
 7 files changed, 209 insertions(+), 49 deletions(-)
 create mode 100644 t/get_app_icons.t
 create mode 100644 t/get_claws_version.t
 create mode 100644 t/str_rgba.t
 create mode 100644 t/version_greater_or_equal.t


- Log -----------------------------------------------------------------
commit a8bd715931c5de62e4a863aebe0eb8bbec6329df
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Dec 23 11:24:50 2018 +0100

    Include tests in tarball

diff --git a/Makefile b/Makefile
index 0225b23..41a37e2 100644
--- a/Makefile
+++ b/Makefile
@@ -79,6 +79,8 @@ dist:
 	cp -p po/unmaint/*.po ${NAME}-${VERSION}/po/unmaint
 	mkdir ${NAME}-${VERSION}/icons
 	cp -p icons/*.xcf icons/*.png ${NAME}-${VERSION}/icons
+	mkdir ${NAME}-${VERSION}/t
+	cp -p t/*.t ${NAME}-${VERSION}/t
 	tar cJf ${NAME}-${VERSION}.tar.xz ${NAME}-${VERSION} \
 		&& rm -rf ${NAME}-${VERSION}
 

commit e86458a81c38ee7656121963e17745898c57620c
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Dec 23 11:23:23 2018 +0100

    Add some tests which were sleeping here

diff --git a/t/get_app_icons.t b/t/get_app_icons.t
new file mode 100644
index 0000000..620c394
--- /dev/null
+++ b/t/get_app_icons.t
@@ -0,0 +1,17 @@
+use 5.010_000;
+use strict;
+use utf8;
+use Test::More tests => 4;
+
+require_ok ('Clawsker');
+
+use Clawsker;
+
+ok ( defined &Clawsker::get_app_icons, 'has function' );
+
+my $icons = Clawsker::get_app_icons;
+
+ok ( 'ARRAY' eq ref ($icons), 'returns an array ref' );
+
+ok ( 3 == @$icons, 'contains 3 elements' );
+
diff --git a/t/get_claws_version.t b/t/get_claws_version.t
new file mode 100644
index 0000000..93d835e
--- /dev/null
+++ b/t/get_claws_version.t
@@ -0,0 +1,52 @@
+use 5.010_000;
+use strict;
+use utf8;
+use File::Temp qw(tempdir);
+use Test::More tests => 4;
+
+require_ok ('Clawsker');
+
+my ($tempdir1, $claws1, $tempdir2, $claws2);
+
+BEGIN {
+    $tempdir1 = tempdir ();
+    $tempdir2 = "$tempdir1/with space";
+    $claws1 = "$tempdir1/claws-mail";
+    $claws2 = "$tempdir2/claws-mail";
+    qx {
+        echo '#!/bin/sh' > $claws1
+        echo 'test "\$1" = '-v' && echo "Claws Mail version 3.2.1"' >> $claws1
+        chmod +x $claws1
+        mkdir "$tempdir2"
+        cp -p "$claws1" "$claws2"
+    };
+};
+
+END {
+    qx {
+        rm -rf $tempdir1
+    };
+};
+
+local %ENV;
+$ENV{'PATH'} = $tempdir1;
+
+use Clawsker;
+
+ok (
+    defined &Clawsker::get_claws_version,
+    'has function'
+);
+
+ok (
+    '3.2.1.0' eq Clawsker::get_claws_version(),
+    'version ok 1'
+);
+
+$ENV{'PATH'} = $tempdir2;
+
+ok (
+    '3.2.1.0' eq Clawsker::get_claws_version(),
+    'version ok 2'
+);
+
diff --git a/t/str_rgba.t b/t/str_rgba.t
new file mode 100644
index 0000000..6d1cef6
--- /dev/null
+++ b/t/str_rgba.t
@@ -0,0 +1,35 @@
+use 5.010_000;
+use strict;
+use utf8;
+use Test::More tests => 6;
+
+require_ok ('Clawsker');
+
+use Clawsker;
+
+ok (
+    defined &Clawsker::gdk_rgba_from_str,
+    'has gdk_rgba_from_str function'
+);
+
+ok (
+    defined &Clawsker::str_from_gdk_rgba,
+    'has str_from_gdk_rgba function'
+);
+
+
+ok (
+    '#123456' eq Clawsker::str_from_gdk_rgba(Clawsker::gdk_rgba_from_str('#123456')),
+    'complementarity'
+);
+
+ok (
+    '#000000' eq Clawsker::str_from_gdk_rgba(Clawsker::gdk_rgba_from_str('#000000')),
+    'complementarity black'
+);
+
+ok (
+    '#ffffff' eq Clawsker::str_from_gdk_rgba(Clawsker::gdk_rgba_from_str('#ffffff')),
+    'complementarity white'
+);
+
diff --git a/t/version_greater_or_equal.t b/t/version_greater_or_equal.t
new file mode 100644
index 0000000..0f169a7
--- /dev/null
+++ b/t/version_greater_or_equal.t
@@ -0,0 +1,45 @@
+use 5.010_000;
+use strict;
+use utf8;
+use Glib qw(TRUE FALSE);
+use Test::More tests => 8;
+
+require_ok ('Clawsker');
+
+use Clawsker;
+
+ok (
+    defined &Clawsker::version_greater_or_equal,
+    'has the function'
+);
+
+ok (
+    TRUE == Clawsker::version_greater_or_equal ('', ''),
+    'empty is equal to empty reference version'
+);
+
+ok (
+    FALSE == Clawsker::version_greater_or_equal ('1', ''),
+    'everything is lower than empty referece version (show it all)'
+);
+
+ok (
+    TRUE == Clawsker::version_greater_or_equal ('', '1'),
+    'empty is greater than reference version 1 (show unversioned)'
+);
+
+ok (
+    TRUE == Clawsker::version_greater_or_equal ('1', '1'),
+    '1 is equal to reference version 1'
+);
+
+ok (
+    TRUE == Clawsker::version_greater_or_equal ('2', '1'),
+    '2 is greater than reference version 1'
+);
+
+ok (
+    FALSE == Clawsker::version_greater_or_equal ('0.9.99', '1'),
+    '0.9.99 is not greater than reference version 1'
+);
+

commit 6fa96fa78f6258de6e5a2f8de9718c4c4aad50c0
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Dec 23 11:22:24 2018 +0100

    Add testing setup

diff --git a/.gitignore b/.gitignore
index f0e97b8..a1b477b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ po/*.pox~
 po/*.mo
 /build/
 /clawsker.1
+t/Clawsker.pm
diff --git a/Makefile b/Makefile
index c862b0b..0225b23 100644
--- a/Makefile
+++ b/Makefile
@@ -90,5 +90,12 @@ clean: clean-build
 	rm -f *~
 	${MAKE} -C po clean
 
-.PHONY: all build install install-dirs install-icons-dirs install-icons uninstall uninstall-icons clean clean-build dist
+test-setup:
+	@test -h t/Clawsker.pm || ( cd t/ && ln -s ../clawsker Clawsker.pm )
 
+test: test-setup
+	@env DISPLAY= prove -It
+
+.PHONY: all build install install-dirs install-icons-dirs install-icons
+.PHONY: uninstall uninstall-icons clean clean-build dist
+.PHONY: test-setup test

commit f8655190a90a0b49985de13e1f73afc3e8985b6f
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Dec 23 11:22:18 2018 +0100

    Make it a module

diff --git a/clawsker b/clawsker
index da677cb..136a156 100755
--- a/clawsker
+++ b/clawsker
@@ -11,9 +11,7 @@
 # See COPYING file for license details.
 # See AUTHORS file for a complete list of contributors.
 #
-
-binmode STDOUT, ":encoding(utf8)";
-
+package Clawsker;
 use 5.010_000;
 use strict;
 use utf8;
@@ -26,7 +24,7 @@ use POSIX qw(setlocale);
 use Locale::gettext;
 use Encode;
 use Digest::MD5 qw(md5_hex);
-use Getopt::Long;
+use Getopt::Long qw(GetOptionsFromArray);
 
 my $NAME = 'clawsker';
 my $PREFIX = '@PREFIX@';
@@ -38,11 +36,14 @@ my $READONLY = FALSE;
 my $CLAWSV = undef;
 my $main_window = undef;
 
-my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
-$locale = "C" unless defined($locale);
-setlocale (LC_ALL, $locale);
-bindtextdomain ($NAME, catdir ($PREFIX, 'share', 'locale'));
-textdomain ($NAME);
+sub initialise {
+    binmode STDOUT, ":encoding(utf8)";
+    my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
+    $locale = "C" unless defined($locale);
+    setlocale (LC_ALL, $locale);
+    bindtextdomain ($NAME, catdir ($PREFIX, 'share', 'locale'));
+    textdomain ($NAME);
+}
 
 sub _ {
     my $str = shift;
@@ -2297,10 +2298,12 @@ sub print_help() {
 }
 
 sub parse_command_line {
+    my $argv = shift;
     my $cont = TRUE;
     $CLAWSV = get_claws_version ();
     eval {
-        GetOptions('h|help' => sub { print_help (); $cont = FALSE },
+        GetOptionsFromArray($argv,
+            'h|help' => sub { print_help (); $cont = FALSE },
             'v|version' => sub { print_version (); $cont = FALSE },
             'b|verbose' => sub { $VERBOSE = TRUE },
             'r|read-only' => sub { $READONLY = TRUE },
@@ -2739,24 +2742,29 @@ sub escape_key_handler {
     }
 }
 
-# initialise
-exit unless parse_command_line ();
-Gtk3->init;
-$main_window = Gtk3::Window->new ('toplevel');
-exit unless load_preferences ();
-exit unless init_hidden_preferences ();
-# create main GUI
-my $box = Gtk3::VBox->new (FALSE, 5);
-$box->set_border_width(3);
-my $about = new_about_dialog ($main_window);
-$box->pack_start (new_notebook (), TRUE, TRUE, 0);
-$box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
-$main_window->signal_connect (delete_event => sub { exit_handler($main_window) });
-$main_window->signal_connect (key_press_event => \&escape_key_handler);
-$main_window->set_title (_('Claws Mail Hidden Preferences'));
-$main_window->set_icon_list (get_app_icons ());
-$main_window->add ($box);
-$main_window->show_all;
-$MODIFIED = 0;
-Gtk3->main;
-
+sub main {
+    my $args = shift;
+    initialise;
+    exit unless parse_command_line ($args);
+    Gtk3->init;
+    $main_window = Gtk3::Window->new ('toplevel');
+    exit unless load_preferences ();
+    exit unless init_hidden_preferences ();
+    # create main GUI
+    my $box = Gtk3::VBox->new (FALSE, 5);
+    $box->set_border_width(3);
+    my $about = new_about_dialog ($main_window);
+    $box->pack_start (new_notebook (), TRUE, TRUE, 0);
+    $box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
+    $main_window->signal_connect (delete_event => sub { exit_handler($main_window) });
+    $main_window->signal_connect (key_press_event => \&escape_key_handler);
+    $main_window->set_title (_('Claws Mail Hidden Preferences'));
+    $main_window->set_icon_list (get_app_icons ());
+    $main_window->add ($box);
+    $main_window->show_all;
+    $MODIFIED = 0;
+    Gtk3->main;
+    return 0;
+}
+
+exit Clawsker::main(\@ARGV) unless caller;

commit efd3d0a4628b5583548f414fca3cba5a86647851
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Dec 23 11:22:03 2018 +0100

    Make getting version more robust
    
    Thanks H.Merijn Brand for writting a better version of this sub at:
    https://lists.claws-mail.org/pipermail/users/2018-December/023525.html

diff --git a/clawsker b/clawsker
index d3a005f..da677cb 100755
--- a/clawsker
+++ b/clawsker
@@ -291,23 +291,16 @@ sub version_greater_or_equal {
 }
 
 sub get_claws_version {
-    $_ = which ('claws-mail');
-    return "" unless defined $_; # not installed
-    my $res = "";
-    $_ = qx/$_ -v/;
-    chomp;
-    my @fver = split (/ /);
-    die "Invalid version string" unless ($fver[2] eq "version");
-    my @ver = split (/\./, $fver[3]);
-    $res .= "$ver[0].";
-    $res .= "$ver[1].";
-    if ($ver[2] =~ /(\d+)git(\d+)/) {
-        $res .= "$1.$2";
-    }
-    else {
-        $res .= "$ver[2].0";
-    }
-    return $res;
+    my $cm_path = which ('claws-mail') or return ""; # not found
+    open my $ph, "-|", $cm_path, "-v"  or return ""; # no pipe
+    chomp (my $v = <$ph>);
+    close $ph;
+    # Claws Mail version 3.17.2git17
+    $v =~ m/\bversion\s+(\d[\w.]+)/ or die "Invalid version string: '$v'";
+    my $cmv = $1;
+    my @ver = split m/(?:\.|git)/, $cmv;
+    @ver < 4 and push @ver, 0;
+    return join ".", @ver;
 }
 
 # data handlers and auxiliar functions

-----------------------------------------------------------------------


hooks/post-receive
-- 
Hidden preferences editor for Claws Mail


More information about the Commits mailing list