1*3ee4fc2aSCody Peter Mello#!/bin/bash 2*3ee4fc2aSCody Peter Mello 3*3ee4fc2aSCody Peter Melloif [[ -z "$AWK" || -z "$WORKDIR" ]]; then 4*3ee4fc2aSCody Peter Mello printf '$AWK and $WORKDIR must be set\n' >&2 5*3ee4fc2aSCody Peter Mello exit 1 6*3ee4fc2aSCody Peter Mellofi 7*3ee4fc2aSCody Peter Mello 8*3ee4fc2aSCody Peter MelloTEMP0=$WORKDIR/test.temp.0 9*3ee4fc2aSCody Peter MelloTEMP1=$WORKDIR/test.temp.1 10*3ee4fc2aSCody Peter MelloTEMP2=$WORKDIR/test.temp.2 11*3ee4fc2aSCody Peter Mello 12*3ee4fc2aSCody Peter MelloRESULT=0 13*3ee4fc2aSCody Peter Mello 14*3ee4fc2aSCody Peter Mellofail() { 15*3ee4fc2aSCody Peter Mello echo "$1" >&2 16*3ee4fc2aSCody Peter Mello RESULT=1 17*3ee4fc2aSCody Peter Mello} 18*3ee4fc2aSCody Peter Mello 19*3ee4fc2aSCody Peter Melloecho T.rt: tests for the RT variable 20*3ee4fc2aSCody Peter Mello 21*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { print (RT == "" ? "true" : "false"); }' > $TEMP1 22*3ee4fc2aSCody Peter Melloprintf 'true\n' > $TEMP2 23*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "" in BEGIN' 24*3ee4fc2aSCody Peter Mello 25*3ee4fc2aSCody Peter Melloprintf 'a\n' > $TEMP0 26*3ee4fc2aSCody Peter Mello$AWK '{ print (RT == "\n" ? "true" : "false"); }' $TEMP0 > $TEMP1 27*3ee4fc2aSCody Peter Melloprintf 'true\n' > $TEMP2 28*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "\n"' 29*3ee4fc2aSCody Peter Mello 30*3ee4fc2aSCody Peter Melloprintf 'a' > $TEMP0 31*3ee4fc2aSCody Peter Mello$AWK '{ print (RT == "" ? "true" : "false"); }' $TEMP0 > $TEMP1 32*3ee4fc2aSCody Peter Melloprintf 'true\n' > $TEMP2 33*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to ""' 34*3ee4fc2aSCody Peter Mello 35*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { "echo hello" | getline; print (RT == "\n" ? "true" : "false"); }' > $TEMP1 36*3ee4fc2aSCody Peter Melloprintf 'true\n' > $TEMP2 37*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "\n" (getline)' 38*3ee4fc2aSCody Peter Mello 39*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { "printf a" | getline; print (RT == "" ? "true" : "false"); }' > $TEMP1 40*3ee4fc2aSCody Peter Melloprintf 'true\n' > $TEMP2 41*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "" (getline)' 42*3ee4fc2aSCody Peter Mello 43*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { "echo hello" | getline v; print (RT == "\n" ? "true" : "false"); }' > $TEMP1 44*3ee4fc2aSCody Peter Melloprintf 'true\n' > $TEMP2 45*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "\n" (getline var)' 46*3ee4fc2aSCody Peter Mello 47*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { 48*3ee4fc2aSCody Peter Mello RT = "foo"; 49*3ee4fc2aSCody Peter Mello getline < "/etc/passwd"; 50*3ee4fc2aSCody Peter Mello print (RT == "\n" ? "true" : "false"); 51*3ee4fc2aSCody Peter Mello}' > $TEMP1 52*3ee4fc2aSCody Peter Melloprintf 'true\n' > $TEMP2 53*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "\n" (getline < file)' 54*3ee4fc2aSCody Peter Mello 55*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { 56*3ee4fc2aSCody Peter Mello RT = "foo"; 57*3ee4fc2aSCody Peter Mello getline v < "/etc/passwd"; 58*3ee4fc2aSCody Peter Mello print (RT == "\n" ? "true" : "false"); 59*3ee4fc2aSCody Peter Mello}' > $TEMP1 60*3ee4fc2aSCody Peter Melloprintf 'true\n' > $TEMP2 61*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "\n" (getline var < file)' 62*3ee4fc2aSCody Peter Mello 63*3ee4fc2aSCody Peter Mello# Single newline at end 64*3ee4fc2aSCody Peter Melloprintf '\n\n\n\n\na\n\na b\na b c d\nq r s t u\n\n\n\n\nv w x y z\n' > $TEMP0 65*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { RS = ""; } { print NF, length(RT); }' $TEMP0 > $TEMP1 66*3ee4fc2aSCody Peter Melloprintf '1 2\n11 5\n5 1\n' > $TEMP2 67*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt empty RS variable (1 newline at end)' 68*3ee4fc2aSCody Peter Mello 69*3ee4fc2aSCody Peter Mello# Two newlines at end 70*3ee4fc2aSCody Peter Melloprintf '\n\n\n\n\na\n\na b\na b c d\nq r s t u\n\n\n\n\nv w x y z\n\n' > $TEMP0 71*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { RS = ""; } { print NF, length(RT); }' $TEMP0 > $TEMP1 72*3ee4fc2aSCody Peter Melloprintf '1 2\n11 5\n5 2\n' > $TEMP2 73*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt empty RS variable (2 newlines at end)' 74*3ee4fc2aSCody Peter Mello 75*3ee4fc2aSCody Peter Mello# Multiple newlines at end 76*3ee4fc2aSCody Peter Melloprintf 'a\n\na b\na b c d\nq r s t u\n\n\n\n\nv w x y z\n\n\n\n' > $TEMP0 77*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { RS = ""; } { print NF, length(RT); }' $TEMP0 > $TEMP1 78*3ee4fc2aSCody Peter Melloprintf '1 2\n11 5\n5 4\n' > $TEMP2 79*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt empty RS variable (many newlines at end)' 80*3ee4fc2aSCody Peter Mello 81*3ee4fc2aSCody Peter Mello# No newlines at end 82*3ee4fc2aSCody Peter Melloprintf 'a\n\na b\na b c d\nq r s t u\n\n\n\n\nv w x y z' > $TEMP0 83*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { RS = ""; } { print NF, length(RT); }' $TEMP0 > $TEMP1 84*3ee4fc2aSCody Peter Melloprintf '1 2\n11 5\n5 0\n' > $TEMP2 85*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt empty RS variable (no ending newline)' 86*3ee4fc2aSCody Peter Mello 87*3ee4fc2aSCody Peter Mello# Non-newline separators 88*3ee4fc2aSCody Peter Mello 89*3ee4fc2aSCody Peter Melloprintf 'a\036' > $TEMP0 90*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { RS="\036" } { print (RT == "\036" ? "true" : "false"), length(RS); }' $TEMP0 > $TEMP1 91*3ee4fc2aSCody Peter Melloprintf 'true 1\n' > $TEMP2 92*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "\036" (RS="\036")' 93*3ee4fc2aSCody Peter Mello 94*3ee4fc2aSCody Peter Melloprintf 'a' > $TEMP0 95*3ee4fc2aSCody Peter Mello$AWK 'BEGIN { RS="\036" } { print (RT == "" ? "true" : "false"), length(RS); }' $TEMP0 > $TEMP1 96*3ee4fc2aSCody Peter Melloprintf 'true 1\n' > $TEMP2 97*3ee4fc2aSCody Peter Mellodiff $TEMP1 $TEMP2 || fail 'BAD: T.rt RT is set to "" (RS="\036")' 98*3ee4fc2aSCody Peter Mello 99*3ee4fc2aSCody Peter Melloexit $RESULT 100