Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add brainfuck #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ written in the host language which starts a Prybar-compatible REPL.
| Ruby 2.5 | ✔ | ✔ | ✔ | ✔ | ✗ | ✗ |
| SQLite | ✔ | ✔ | ✔ | ✔ | ✗ | ✔ |
| Tcl | ✔ | ✔ | ✔ | ✗ | ✗ | - |
| Brainfuck | ✔ | ✗ | ✗ | ✗ | ✔ | ✔ |

## Build and run

Expand Down Expand Up @@ -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
Expand Down
115 changes: 115 additions & 0 deletions languages/brainfuck/main.go
Original file line number Diff line number Diff line change
@@ -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{}
22 changes: 22 additions & 0 deletions test_files/cell_size.bf
Original file line number Diff line number Diff line change
@@ -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.
[[-]<]

2 changes: 2 additions & 0 deletions test_files/hello_world.bf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

48 changes: 48 additions & 0 deletions tests/brainfuck/cell_size.exp
Original file line number Diff line number Diff line change
@@ -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
Binary file added tests/brainfuck/clear.exp
Binary file not shown.
56 changes: 56 additions & 0 deletions tests/brainfuck/hello_world.exp
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions tests/brainfuck/hello_world_file.exp
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions tests/brainfuck/no_matching_close.exp
Original file line number Diff line number Diff line change
@@ -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
Loading