record.pl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #! /usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use Cwd qw/abs_path/;
  5. use FindBin;
  6. # We can only dzil from the root of the repository.
  7. my $this_folder = $FindBin::Bin . '/../../'; # t/bin/../../
  8. my $repo_root = abs_path($this_folder) . '/';
  9. reset_env();
  10. start_server();
  11. my $built_lib = find_built_lib();
  12. my $export = $^O eq 'MSWin32' ? 'set' : 'export';
  13. my $wait = $^O eq 'MSWin32' ? 'START /WAIT' : '';
  14. my $prove_opts = '-I' . $built_lib .' -j9 -r --verbose --trap --merge --state=save,slow';
  15. my $default_prove = "prove $prove_opts t/";
  16. my $executable = $ARGV[0] ? "perl -I$built_lib $ARGV[0]" : $default_prove;
  17. my $command = "$export WD_MOCKING_RECORD=1 && cd $repo_root && $executable";
  18. print "Executing: $command\n";
  19. print `$command`;
  20. reset_env();
  21. sub find_built_lib {
  22. my $built_lib = glob($repo_root . 'Selenium-Remote-Driver-*/lib');
  23. if (not defined $built_lib) {
  24. print 'Building a dist.' . "\n";
  25. print `cd $repo_root && dzil build`;
  26. }
  27. # If built_lib wasn't around in the first place, we'll have to glob
  28. # for it again.
  29. $built_lib ||= glob($repo_root . 'Selenium-Remote-Driver-*/lib');
  30. return $built_lib;
  31. }
  32. sub start_server {
  33. if ($^O eq 'MSWin32') {
  34. system('start "TEMP_HTTP_SERVER" /MIN perl ' . $repo_root . 't/http-server.pl');
  35. }
  36. else {
  37. system('perl ' . $repo_root . 't/http-server.pl > /dev/null &');
  38. }
  39. print 'Starting a new server.' . "\n";
  40. }
  41. sub kill_server {
  42. if ($^O eq 'MSWin32') {
  43. system("taskkill /FI \"WINDOWTITLE eq TEMP_HTTP_SERVER\"");
  44. }
  45. else {
  46. `ps aux | grep [h]ttp-server\.pl | awk '{print \$2}' | xargs kill`;
  47. }
  48. }
  49. sub reset_env {
  50. print 'dzil cleaning...';
  51. `cd $repo_root && dzil clean`;
  52. print 'and taking out any existing servers. ' . "\n";
  53. kill_server();
  54. }