Illustrates carryover between shspec examples.
Carryover example to example:
$ shpec carryover_it_to_it.sh
shpec
shares state between examples a
shares state between examples b
(Expected [] to equal [value])
| class NonFairQueue | |
| attr_reader :nodes | |
| attr_reader :edges | |
| def initialize(options = {}) | |
| @nodes = options.fetch(:nodes, {}) # {name => {:command, :stdin_type, :stdout_type}} | |
| @edges = options.fetch(:edges, {}) # {parent => [child]} | |
| end | |
| def run |
| # Fast Multi-Process Nonfair-Queue via FIFOs, leveraging PIPE_BUF | |
| # =============================================================== | |
| # | |
| # Provided `ulimit -a` indicates pipe size is 512 bytes This will repeat a | |
| # message n times and confirm all the messages are received intact after pipe | |
| # traversal (ie PIPE_BUF is respected). | |
| # | |
| # Increasing the message size by 1 (511 -> 512 for a total length of 513) will | |
| # demonstrate how the messages are interleaved. | |
| # |
| #!/bin/bash | |
| # 8... always? | |
| mkfifo fifo | |
| ruby -e '100000.times {|i| puts "a"}' > fifo & | |
| ruby -e '100000.times {|i| puts "b"}' > fifo & | |
| ruby -e '100000.times {|i| puts "c"}' > fifo & | |
| ruby -e '100000.times {|i| puts "d"}' > fifo & | |
| ruby -e '100000.times {|i| puts "e"}' > fifo & | |
| ruby -e '100000.times {|i| puts "f"}' > fifo & | |
| ruby -e '100000.times {|i| puts "g"}' > fifo & |
| #!/usr/bin/env ruby | |
| r, w = IO.pipe | |
| # exec on ruby 2.0 closes the fds and so cat fails with "Bad file descriptor" | |
| # on ree this works as expected. | |
| # | |
| # I thought close_on_exec was the issue, but this doesn't fix it at all. | |
| # Perhaps it is not being respected? | |
| # | |
| # r.close_on_exec = false |
| sed -e 's/a/A/' <<DOC | sed -e "\ | |
| s/b/B/ | |
| " | |
| abc | |
| DOC | |
| (sed -e 's/a/A/' | sed -e "\ | |
| s/b/B/ | |
| ") <<DOC | |
| abc |
| #!/bin/sh | |
| cat > example <<"DOC" | |
| #!/usr/bin/env ruby | |
| puts "got: #{`git log | head -n 1`}" | |
| DOC | |
| chmod +x example | |
| test_example () { | |
| ./example | grep "got: commit [[:xdigit:]]\{40\}" |
Illustrates carryover between shspec examples.
Carryover example to example:
$ shpec carryover_it_to_it.sh
shpec
shares state between examples a
shares state between examples b
(Expected [] to equal [value])
| #!/bin/bash | |
| export A=a | |
| exec ./b.rb | |
| echo not here |
| interpolate () { | |
| eval " | |
| sed -e 's/^://' <<TEMPLATE | |
| $(sed -e 's/^/:/' -e 's/\([`\]\)/\\\1/g' -e 's/$(/\\$(/g') | |
| TEMPLATE | |
| " | |
| } | |
| item=milk | |
| cat <<<'got $item' |
| #!/bin/sh | |
| sed -e ' | |
| s/\\/\\\\/g | |
| s/'\''/\\'\''/g | |
| s/$/\\n/g | |
| s//\\001/g | |
| s//\\002/g | |
| s//\\003/g | |
| s//\\004/g | |
| s//\\005/g |