]> granicus.if.org Git - fortune-mod/commitdiff
Fix unrotated offensive fortunes.
authorShlomi Fish <shlomif@shlomifish.org>
Mon, 9 Jul 2018 12:13:05 +0000 (15:13 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Mon, 9 Jul 2018 12:13:05 +0000 (15:13 +0300)
See https://github.com/shlomif/fortune-mod/issues/26 - thanks to
@vassilmladenov

fortune-mod/datfiles/off/CMakeLists.txt
fortune-mod/fortune/fortune.c
fortune-mod/tests/t/test-fortune-o-rot.t [new file with mode: 0644]

index 112167ed34bbbf55984860cb4a2c19344b8c3487..be2ebbc3c0ca0102082fed3936eef504432f4fe8 100644 (file)
@@ -18,7 +18,7 @@ FOREACH(c ${OFFENSIVE_COOKIES})
     ADD_CUSTOM_COMMAND(
         OUTPUT "${DEST}"
         COMMAND "${_strfile}"
-        ARGS "${rot_dest}" "${DEST}"
+        ARGS "-x" "${rot_dest}" "${DEST}"
         DEPENDS "${rot_dest}" "${_strfile}"
     )
 
index b41a8a66f02ff33feb5a0daee69f6179cb504091..eb56875bb52e4eb35b0bdd7d32e6a3b7dc8c1d3e 100644 (file)
@@ -224,6 +224,13 @@ static unsigned long my_random(unsigned long base)
 {
     FILE * fp;
     unsigned long long l = 0;
+    char * hard_coded_val;
+
+    hard_coded_val = getenv("FORTUNE_MOD_RAND_HARD_CODED_VALS");
+    if (hard_coded_val)
+    {
+        return ((unsigned long)atol(hard_coded_val) % base);
+    }
     if (getenv("FORTUNE_MOD_USE_SRAND"))
     {
         goto fallback;
diff --git a/fortune-mod/tests/t/test-fortune-o-rot.t b/fortune-mod/tests/t/test-fortune-o-rot.t
new file mode 100644 (file)
index 0000000..eabf7e1
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+
+# See:
+# https://github.com/shlomif/fortune-mod/issues/26
+# " Offensive fortunes not automatically decrypting #26 "
+
+
+use strict;
+use warnings;
+
+use File::Path qw/mkpath rmtree/;
+use Cwd qw/getcwd/;
+
+use Test::More tests => 1;
+
+sub do_system
+{
+    my ($args) = @_;
+
+    my $cmd = $args->{cmd};
+    print "Running [@$cmd]\n";
+    if ( system(@$cmd) )
+    {
+        die "Running [@$cmd] failed!";
+    }
+}
+
+{
+    my $cwd       = getcwd();
+    my $build_dir = "$cwd/fortune-m-build-dir";
+    my $inst_dir  = "$cwd/fortune-m-INST_DIR";
+    rmtree( $build_dir, 0, 0 );
+    rmtree( $inst_dir,  0, 0 );
+    mkpath($build_dir);
+    chdir $build_dir;
+    do_system(
+        {
+            cmd =>
+                [ 'cmake', "-DCMAKE_INSTALL_PREFIX=$inst_dir", $ENV{SRC_DIR} ]
+        }
+    );
+    do_system( { cmd => ['make'] } );
+    do_system( { cmd => [ 'make', 'install', ] } );
+
+    local $ENV{FORTUNE_MOD_RAND_HARD_CODED_VALS} = 240;
+    my $text = `'$inst_dir/games/fortune' -o`;
+
+    # TEST
+    like( $text, qr/\ADrinking when we are/, 'fortune -m matched' );
+}