Emacs-Run
view release on metacpan or search on metacpan
t/04-working_with_emacs.t view on Meta::CPAN
{
my $test_name = "Testing internal quoting handling on elisp";
my $mock_home = "$Bin/dat/home/nicesuit";
my $code_lib = "$USR/lib";
my $code_lib_alt = "$USR/lib-alt";
my $dot_emacs_tpl = "$SRC_LOC/templates/.emacs-3-template";
create_dot_emacs_in_mock_home( $mock_home, $code_lib, $code_lib_alt, $dot_emacs_tpl );
# change the environment variable $HOME to point at the $mock_home
$ENV{HOME} = $mock_home;
echo_home() if $DEBUG;
my $er = Emacs::Run->new;
my $elisp = q{ (message (mapconcat 'identity load-path " | ")) };
my $result = $er->eval_elisp( $elisp );
my $expected = "/tmp | $USR/lib | $USR/lib-alt";
is( $result, $expected, "$test_name" );
}
{
my $test_name = "Eval simple elisp with current user's actual emacs init files";
my $er = Emacs::Run->new;
my $result = $er->eval_elisp( '(message "yow")' );
is( $result, "yow", "$test_name: elisp message" );
$result = $er->eval_elisp( '(print (+ 2 2))' );
cmp_ok( $result, 'eq', '4', "$test_name: plus" );
}
{
my $test_name = "Testing run_elisp_on_file";
my $mock_home = "$Bin/dat/home/ghostcowboy";
my $code_lib = "$USR/lib";
my $code_lib_alt = "$USR/lib-alt";
my $dot_emacs_tpl = "$SRC_LOC/templates/.emacs-3-template";
my $src = "$Bin/dat/src/text";
my $arc = "$Bin/dat/arc/text";
create_dot_emacs_in_mock_home( $mock_home, $code_lib, $code_lib_alt, $dot_emacs_tpl );
my $test_subject = "chesterson.txt";
my $source_file = "$src/$test_subject";
my $result_file = "$mock_home/$test_subject";
my $expected_file = "$arc/$test_subject";
copy($source_file, $result_file) or die "$!";
# we will act on the "result" file
my $filename = $result_file;
# change the environment variable $HOME to point at the $mock_home
$ENV{HOME} = $mock_home;
echo_home() if $DEBUG;
my $er = Emacs::Run->new;
my $emacs_version = $er->emacs_version;
# Make every other word upper-case - return number of iterations
my $elisp = q{
(let ( (count 0) )
(while (progn
(upcase-word 1) (forward-word 1)
(setq count (+ count 1))
(not (looking-at "^$"))))
(print count))
};
my $ret = 0;
$ret ||= $er->run_elisp_on_file( $filename, $elisp, {shell_output_director=>'2>/dev/null' } );
print STDERR "ret: $ret\n" if $DEBUG; # 49
SKIP: {
unless ($ret > 25) {
skip "Repeated 'forward-word' counts way too low: weird idea of word chracters?", 1;
}
my ($result, $expected) = slurp_files( $result_file, $expected_file );
eq_or_diff( $result, $expected,
"$test_name: upcase/forward-word on ghostcowboy/chesterson.txt") or
print STDERR "using emacs version: $emacs_version";
}
}
{
my $test_name = "Testing run_elisp_on_file";
my $mock_home = "$Bin/dat/home/penguindust";
my $code_lib = "$USR/lib";
my $code_lib_alt = "$USR/lib-alt";
my $dot_emacs_tpl = "$SRC_LOC/templates/.emacs-5-template";
my $src = "$Bin/dat/src/text";
my $arc = "$Bin/dat/arc/text";
create_dot_emacs_in_mock_home( $mock_home, $code_lib, $code_lib_alt, $dot_emacs_tpl );
my $test_subject = "chesterson.txt";
my $source_file = "$src/$test_subject";
my $test_subject_base = ( fileparse( $test_subject, qw{\.txt} ) )[0];
my $result_file = "$mock_home/$test_subject_base-uc.txt";
my $expected_file = "$arc/$test_subject_base-uc.txt";
copy($source_file, $result_file) or die "$!";
# we will now act on the "result" file
my $filename = $result_file;
# change the environment variable $HOME to point at the $mock_home
$ENV{HOME} = $mock_home;
echo_home() if $DEBUG;
my $er = Emacs::Run->new;
my $emacs_version = $er->emacs_version;
# Make the text upper case
my $elisp = q{ (upcase-region (point-min) (point-max)) };
$er->run_elisp_on_file( $filename, $elisp );
( run in 2.245 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )