@ -4,19 +4,16 @@
package main
package main
import (
import (
"encoding/binary"
"flag"
"flag"
"fmt"
"fmt"
"go/ast"
"go/ast"
"go/printer"
"go/printer"
"go/token"
"go/token"
"math"
mathrand "math/rand"
mathrand "math/rand"
"os"
"os"
"os/exec"
"os/exec"
"path/filepath"
"path/filepath"
"runtime"
"runtime"
"strconv"
"strings"
"strings"
"testing"
"testing"
"time"
"time"
@ -78,8 +75,6 @@ func TestScripts(t *testing.T) {
Cmds : map [ string ] func ( ts * testscript . TestScript , neg bool , args [ ] string ) {
Cmds : map [ string ] func ( ts * testscript . TestScript , neg bool , args [ ] string ) {
"binsubstr" : binsubstr ,
"binsubstr" : binsubstr ,
"bincmp" : bincmp ,
"bincmp" : bincmp ,
"binsubint" : binsubint ,
"binsubfloat" : binsubfloat ,
"generate-literals" : generateLiterals ,
"generate-literals" : generateLiterals ,
} ,
} ,
UpdateScripts : * update ,
UpdateScripts : * update ,
@ -144,73 +139,6 @@ func binsubstr(ts *testscript.TestScript, neg bool, args []string) {
}
}
}
}
func binsubint ( ts * testscript . TestScript , neg bool , args [ ] string ) {
if len ( args ) < 2 {
ts . Fatalf ( "usage: binsubint file subint..." )
}
data := readFile ( ts , args [ 0 ] )
var failed [ ] string
for _ , subIntStr := range args [ 1 : ] {
subInt , err := strconv . Atoi ( subIntStr )
if err != nil {
ts . Fatalf ( "%v" , err )
}
b := make ( [ ] byte , 8 )
binary . LittleEndian . PutUint64 ( b , uint64 ( subInt ) )
match := strings . Contains ( data , string ( b ) )
if ! match {
binary . BigEndian . PutUint64 ( b , uint64 ( subInt ) )
match = strings . Contains ( data , string ( b ) )
}
if match && neg {
failed = append ( failed , subIntStr )
} else if ! match && ! neg {
failed = append ( failed , subIntStr )
}
}
if len ( failed ) > 0 && neg {
ts . Fatalf ( "unexpected match for %s in %s" , failed , args [ 0 ] )
} else if len ( failed ) > 0 {
ts . Fatalf ( "expected match for %s in %s" , failed , args [ 0 ] )
}
}
func binsubfloat ( ts * testscript . TestScript , neg bool , args [ ] string ) {
if len ( args ) < 2 {
ts . Fatalf ( "usage: binsubint file binsubfloat..." )
}
data := readFile ( ts , args [ 0 ] )
var failed [ ] string
for _ , subFloatStr := range args [ 1 : ] {
subFloat , err := strconv . ParseFloat ( subFloatStr , 64 )
if err != nil {
ts . Fatalf ( "%v" , err )
}
b := make ( [ ] byte , 8 )
binary . LittleEndian . PutUint64 ( b , math . Float64bits ( subFloat ) )
match := strings . Contains ( data , string ( b ) )
if ! match {
binary . BigEndian . PutUint64 ( b , math . Float64bits ( subFloat ) )
match = strings . Contains ( data , string ( b ) )
}
if match && neg {
failed = append ( failed , subFloatStr )
} else if ! match && ! neg {
failed = append ( failed , subFloatStr )
}
}
if len ( failed ) > 0 && neg {
ts . Fatalf ( "unexpected match for %s in %s" , failed , args [ 0 ] )
} else if len ( failed ) > 0 {
ts . Fatalf ( "expected match for %s in %s" , failed , args [ 0 ] )
}
}
func bincmp ( ts * testscript . TestScript , neg bool , args [ ] string ) {
func bincmp ( ts * testscript . TestScript , neg bool , args [ ] string ) {
if len ( args ) != 2 {
if len ( args ) != 2 {
ts . Fatalf ( "usage: bincmp file1 file2" )
ts . Fatalf ( "usage: bincmp file1 file2" )