1# Test user-defined commands 2 3# $Id: newcmd.t,v 3.0 1993/11/29 13:50:10 ram Exp ram $ 4# 5# Copyright (c) 1990-2006, Raphael Manfredi 6# 7# You may redistribute only under the terms of the Artistic License, 8# as specified in the README file that comes with the distribution. 9# You may reuse parts of this distribution only within the terms of 10# that same Artistic License; a copy of which may be found at the root 11# of the source tree for mailagent 3.0. 12# 13# $Log: newcmd.t,v $ 14# Revision 3.0 1993/11/29 13:50:10 ram 15# Baseline for mailagent 3.0 netwide release. 16# 17 18do '../pl/misc.pl'; 19unlink "$user", 'always', 'test'; 20 21&add_option("-o 'newcmd: ~/.newcmd'"); 22open(NEWCMD, '>.newcmd') || print "1\n"; 23print NEWCMD <<EOF || print "2\n"; 24FIRST_CMD ~/commands first 25SECOND_CMD ~/commands second 26THIRD_CMD ~/commands third 27EOF 28close NEWCMD || print "3\n"; 29 30open(COM, '>commands') || print "4\n"; 31print COM <<'EOC' || print "5\n"; 32sub first { 33 &mailhook'third_cmd('test'); # Make sure interface function is there 34 open(OUT, '>output1'); 35 print OUT join(' ', @ARGV), "\n"; 36 print OUT "$to\n"; 37 close OUT; 38 0; 39} 40 41sub second { 42 &main'add_log('second user-defined command ran ok'); 43 open(OUT, '>output2'); 44 print OUT "$from\n"; 45 print OUT "$header{'Date'}\n"; 46 close OUT; 47 0; 48} 49 50sub third { 51 local($cmd) = @_; 52 local(@cmd) = split(' ', $cmd); 53 open(TEST, ">$cmd[1]"); 54 print TEST "$cmd\n"; 55 close TEST; 56 0; 57} 58EOC 59close COM || print "6\n"; 60 61&add_header('X-Tag: newcmd'); 62`$cmd`; 63$? == 0 || print "7\n"; 64-f "$user" && print "8\n"; # Has defaulted to LEAVE -> something's wrong 65-f 'output1' || print "9\n"; 66-f 'output2' || print "10\n"; 67-f 'test' || print "11\n"; 68 69chop($test = `cat test 2>/dev/null`); 70$test eq 'third_cmd test' || print "12\n"; 71 72chop(@test = `cat output1 2>/dev/null`); 73$test[0] eq 'FIRST_CMD arg1 arg2' || print "13\n"; 74$test[1] eq 'ram@eiffel.com' || print "14\n"; 75 76chop(@test = `cat output2 2>/dev/null`); 77$test[0] eq 'compilers-request@iecc.cambridge.ma.us' || print "15\n"; 78$test[1] eq '3 Jul 92 00:43:22 EDT (Fri)' || print "16\n"; 79 80&get_log(17); 81&check_log('second user-defined command ran ok', 18) == 1 || print "19\n"; 82 83unlink "$user", 'mail', 'test', 'output1', 'output2', 'commands', '.newcmd'; 84print "0\n"; 85