Emacs-Run

 view release on metacpan or  search on metacpan

t/lib/Emacs/Run/Testorama.pm  view on Meta::CPAN

    print STDERR "code_lib_alt: $code_lib_alt\n";
    print STDERR "dot_emacs_tpl: $dot_emacs_tpl\n";
  }

  # make sure $mock_home exists
  mkpath( $mock_home ) unless -d $mock_home;

  # read in template used to create a mock .emacs
  open my $fh_in, "<", $dot_emacs_tpl
    or die "Could not open $dot_emacs_tpl for read:$!";

  my $slurpie;
  {
    undef $/;
    $slurpie =<$fh_in>;
  }

  # munge template placeholders XXX and YYY with mock library locations.
  $slurpie =~ s{XXX}{$code_lib}xmsg;
  $slurpie =~ s{YYY}{$code_lib_alt}xmsg;

  # output the mock .emacs file in the mock home directory
  my $dot_emacs = "$mock_home/.emacs";
  open my $fh_out, ">", $dot_emacs
    or die "Could not open $dot_emacs for read:$!";

  print {$fh_out} $slurpie;
  close($fh_out);

  return $dot_emacs;
}

=item echo_home

Prints the current home location to STDERR (for debugging purposes).

=cut


sub echo_home {
  print STDERR "HOME is now: $ENV{HOME}\n";
}


=item slurp_files

Given two files (with full paths, most likely) open them, slurp in
their contents, and return a list of both of them.

This is a utility to make it slightly easier to compare the effects
of a file munging operation to an archived copy of the expected
results.

Example usage:

  my ($result, $expected) = slurp_files($result_file, $expected_file);

  eq_or_diff( $result, $expected,
              "$test_name: checking effects of upcase-region on $result_file");

  # Note: presumes Test::Differences is in use.

=cut


sub slurp_files {
  my $result_file   = shift;
  my $expected_file = shift;

  # open each file, slurp in.
  local $/; # mister slurpie
  open my $fh, "<", $result_file or die "Could not open $result_file for read:$!";
  my $result = <$fh>;
  close( $fh );

  open $fh, "<", $expected_file or die "Could not open $expected_file for read:$!";
  my $expected = <$fh>;
  close( $fh );

  return ($result, $expected);
}

=item get_short_label_from_name

If a given name is long (i.e. has many hyphens),
will create a short version of it (arbitrarily
taking the fourth element).

=cut

sub  get_short_label_from_name {
  my $varname = shift;
  my @frags = split /-/, $varname;
  my $varlabel;
  if (scalar @frags > 3) {
    $varlabel = $frags[3];
  } else {
    $varlabel = $varname;
  }
  return $varlabel;
}



1;

=back

=head1 SEE ALSO

L<Emacs::Run>

=head1 AUTHOR

Joseph Brenner, E<lt>doom@kzsu.stanford.eduE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2008 by Joseph Brenner

This library is free software; you can redistribute it and/or modify



( run in 2.047 seconds using v1.01-cache-2.11-cpan-ff9377addf4 )