diff --git a/README.md b/README.md index e683c3b..49305b4 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ written in the host language which starts a Prybar-compatible REPL. | Ruby 2.5 | ✔ | ✔ | ✔ | ✔ | ✗ | ✗ | | SQLite | ✔ | ✔ | ✔ | ✔ | ✗ | ✔ | | Tcl | ✔ | ✔ | ✔ | ✗ | ✗ | - | +| Brainfuck | ✔ | ✗ | ✗ | ✗ | ✔ | ✔ | ## Build and run @@ -88,8 +89,7 @@ repository](languages)): Run `make image` to create a Docker image containing not only Prybar's dependencies and source code but also its compiled binaries, which can -be embedded inside other Docker images by means of `COPY ---from=basicer/prybar`. +be embedded inside other Docker images by means of `COPY --from=basicer/prybar`. This image is automatically built and deployed to [Docker Hub](https://hub.docker.com/) every time a commit is merged to diff --git a/languages/brainfuck/main.go b/languages/brainfuck/main.go new file mode 100644 index 0000000..6508ff4 --- /dev/null +++ b/languages/brainfuck/main.go @@ -0,0 +1,115 @@ +package main + +import ( + "fmt" + "os" +) + +// USING_CGO + +type Brainfuck struct { + tape []uint8 + cursor int +} + +func (p *Brainfuck) Open() { + p.tape = make([]uint8, 1000) +} + +func (p *Brainfuck) Version() string { + return "Brainfuck" +} + +func (p *Brainfuck) Eval(code string) { + didPrint := false + + for pc := 0; pc < len(code); pc++ { + switch code[pc] { + case '>': + if p.cursor == len(p.tape)-1 { + p.tape = append(p.tape, 0) + } + p.cursor++ + case '<': + if p.cursor == 0 { + fmt.Fprintln(os.Stderr, "Tried to move past the beginning of the tape!") + return + } + p.cursor-- + case '+': + p.tape[p.cursor]++ + case '-': + p.tape[p.cursor]-- + case '.': + fmt.Printf("%c", p.tape[p.cursor]) + didPrint = true + case ',': + var b [1]byte + _, err := os.Stdin.Read(b[:]) + if err != nil { + b[0] = 0 + } + + p.tape[p.cursor] = b[0] + case '[': + if p.tape[p.cursor] == 0 { + depth := 0 + npc := pc + 1 + for { + if npc == len(code) { + fmt.Fprintln(os.Stderr, "Couldn't find a matching ']'") + return + } + + if code[npc] == ']' && depth == 0 { + break + } + + if code[npc] == '[' { + depth++ + } else if code[npc] == ']' { + depth-- + } + npc++ + } + + pc = npc + + } + case ']': + if p.tape[p.cursor] != 0 { + depth := 0 + npc := pc - 1 + for { + if npc < 0 { + fmt.Fprintln(os.Stderr, "Couldn't find a matching '['") + return + } + + if code[npc] == '[' && depth == 0 { + break + } + + if code[npc] == ']' { + depth++ + } else if code[npc] == '[' { + depth-- + } + + npc-- + } + + pc = npc + + } + } + } + + if didPrint { + fmt.Printf("\n") + } +} + +func (p *Brainfuck) Close() {} + +var Instance = &Brainfuck{} diff --git a/test_files/cell_size.bf b/test_files/cell_size.bf new file mode 100644 index 0000000..95b966f --- /dev/null +++ b/test_files/cell_size.bf @@ -0,0 +1,22 @@ +Calculate the value 256 and test if it's zero +If the interpreter errors on overflow this is where it'll happen +++++++++[>++++++++<-]>[<++++>-] ++<[>-< + Not zero so multiply by 256 again to get 65536 + [>++++<-]>[<++++++++>-]<[>++++++++<-] + +>[> + # Print "32" + ++++++++++[>+++++<-]>+.-.[-]< + <[-]<->] <[>> + # Print "16" + +++++++[>+++++++<-]>.+++++.[-]< +<<-]] >[> + # Print "8" + ++++++++[>+++++++<-]>.[-]< +<-]< +# Print " bit cells\n" ++++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<. +>>.++.+++++++..<-.>>- +Clean up used cells. +[[-]<] + diff --git a/test_files/hello_world.bf b/test_files/hello_world.bf new file mode 100644 index 0000000..5b07704 --- /dev/null +++ b/test_files/hello_world.bf @@ -0,0 +1,2 @@ +++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++. + diff --git a/tests/brainfuck/cell_size.exp b/tests/brainfuck/cell_size.exp new file mode 100755 index 0000000..022f883 --- /dev/null +++ b/tests/brainfuck/cell_size.exp @@ -0,0 +1,48 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Thu Jul 15 16:22:11 2021 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn ./prybar-brainfuck ./test_files/cell_size.bf +match_max 100000 +expect eof diff --git a/tests/brainfuck/clear.exp b/tests/brainfuck/clear.exp new file mode 100755 index 0000000..8aa3039 Binary files /dev/null and b/tests/brainfuck/clear.exp differ diff --git a/tests/brainfuck/hello_world.exp b/tests/brainfuck/hello_world.exp new file mode 100755 index 0000000..a99a1bb --- /dev/null +++ b/tests/brainfuck/hello_world.exp @@ -0,0 +1,56 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Thu Jul 15 16:19:06 2021 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn ./prybar-brainfuck -I +match_max 100000 +expect -exact "Brainfuck\r +\[J\[2K\r--> " +send -- "++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\r" +expect -exact "\[J\[2K\r--> +\[J\[2K\r--> ++\[J\[2K\r--> +++\[J\[2K\r--> ++++\[J\[2K\r--> +++++\[J\[2K\r--> ++++++\[J\[2K\r--> +++++++\[J\[2K\r--> ++++++++\[J\[2K\r--> ++++++++\[\[J\[2K\r--> ++++++++\[>\[J\[2K\r--> ++++++++\[>+\[J\[2K\r--> ++++++++\[>++\[J\[2K\r--> ++++++++\[>+++\[J\[2K\r--> ++++++++\[>++++\[J\[2K\r--> ++++++++\[>++++\[\[J\[2K\r--> ++++++++\[>++++\[>\[J\[2K\r--> ++++++++\[>++++\[>+\[J\[2K\r--> ++++++++\[>++++\[>++\[J\[2K\r--> ++++++++\[>++++\[>++>\[J\[2K\r--> ++++++++\[>++++\[>++>+\[J\[2K\r--> ++++++++\[>++++\[>++>++\[J\[2K\r--> ++++++++\[>++++\[>++>+++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>-\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>-\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>--\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.++++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.++++++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.-\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.--\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.---\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.----\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.-----\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.-\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.---\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.----\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.-----\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.------\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.-------\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>+\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\[J\[2K\r--> ++++++++\[>++++\[>++>+++>+++>+<<<<-\]>+>+>->>+\[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.\r +Hello World!\r +\r +\[J\[2K\r--> " +send -- "" +expect eof diff --git a/tests/brainfuck/hello_world_file.exp b/tests/brainfuck/hello_world_file.exp new file mode 100755 index 0000000..4b7fc95 --- /dev/null +++ b/tests/brainfuck/hello_world_file.exp @@ -0,0 +1,48 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Thu Jul 15 16:21:38 2021 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn ./prybar-brainfuck ./test_files/hello_world.bf +match_max 100000 +expect eof diff --git a/tests/brainfuck/no_matching_close.exp b/tests/brainfuck/no_matching_close.exp new file mode 100755 index 0000000..595ead8 --- /dev/null +++ b/tests/brainfuck/no_matching_close.exp @@ -0,0 +1,71 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Thu Jul 15 16:06:52 2021 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn ./prybar-brainfuck -I +match_max 100000 +expect -exact "Brainfuck\r +\[J\[2K\r--> " +send -- "\[" +expect -exact "\[J\[2K\r--> \[" +send -- "+" +expect -exact "\[J\[2K\r--> \[+" +send -- "+" +expect -exact "\[J\[2K\r--> \[++" +send -- "+" +expect -exact "\[J\[2K\r--> \[+++" +send -- "+" +expect -exact "\[J\[2K\r--> \[++++" +send -- "+" +expect -exact "\[J\[2K\r--> \[+++++" +send -- "+" +expect -exact "\[J\[2K\r--> \[++++++" +send -- "+" +expect -exact "\[J\[2K\r--> \[+++++++" +send -- "\r" +expect -exact "\[J\[2K\r--> \[+++++++\[J\[2K\r--> \[+++++++\r +Couldn't find a matching '\]'\r +\[J\[2K\r--> " +send -- "" +expect eof diff --git a/tests/brainfuck/no_matching_open.exp b/tests/brainfuck/no_matching_open.exp new file mode 100755 index 0000000..d939fb7 --- /dev/null +++ b/tests/brainfuck/no_matching_open.exp @@ -0,0 +1,59 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Thu Jul 15 16:07:56 2021 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn ./prybar-brainfuck -I +match_max 100000 +expect -exact "Brainfuck\r +\[J\[2K\r--> " +send -- "+" +expect -exact "\[J\[2K\r--> +" +send -- "\]" +expect -exact "\[J\[2K\r--> +\]" +send -- "\r" +expect -exact "\[J\[2K\r--> +\]\[J\[2K\r--> +\]\r +Couldn't find a matching '\['\r +\[J\[2K\r--> " +send -- "" +expect eof diff --git a/tests/brainfuck/read_and_print.exp b/tests/brainfuck/read_and_print.exp new file mode 100755 index 0000000..55c212b --- /dev/null +++ b/tests/brainfuck/read_and_print.exp @@ -0,0 +1,61 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Thu Jul 15 16:00:13 2021 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn ./prybar-brainfuck -I +match_max 100000 +expect -exact "Brainfuck\r +\[J\[2K\r--> " +send -- ",>,<.>.<" +expect -exact "\[J\[2K\r--> ,\[J\[2K\r--> ,>\[J\[2K\r--> ,>,\[J\[2K\r--> ,>,<\[J\[2K\r--> ,>,<.\[J\[2K\r--> ,>,<.>\[J\[2K\r--> ,>,<.>.\[J\[2K\r--> ,>,<.>.<" +send -- "\r" +expect -exact "\[J\[2K\r--> ,>,<.>.<\[J\[2K\r--> ,>,<.>.<\r +" +send -- "w\r" +expect -exact "w\r +w\r +\r +\[J\[2K\r--> " +send -- "" +expect eof