Skip to content

Commit

Permalink
Perform deep copy of referenced Sexp before mangling it
Browse files Browse the repository at this point in the history
  • Loading branch information
larsch committed Jun 28, 2009
1 parent 9901a4c commit 769b434
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/foliage.rb
Expand Up @@ -163,8 +163,9 @@ def self.instrument_branch(sexp, in_condition)
end

def self.instrument_cond(sexp, in_condition)
isexp = instrument(sexp.dup, in_condition)
branch = ConditionHook.new(isexp, sexp.deep_dup)
orig_cond = sexp.deep_dup
isexp = instrument(sexp, in_condition)
branch = ConditionHook.new(isexp, orig_cond)
BranchTable.last.push(branch)
sexp.replace(branch.sexp)
return sexp
Expand Down Expand Up @@ -204,7 +205,9 @@ def self.instrument_case(sexp, in_condition)
return sexp
end

# Recursively instruments an Sexp instance.
# Recursively instruments an Sexp instance. This will mangle the
# Sexp tree by extra instructions. Expressions that are instrumented
# are copied first to preserve their printed form.
#
# == Parameters:
#
Expand Down Expand Up @@ -233,7 +236,6 @@ def self.instrument(sexp, in_condition = nil)
end
end
end

return sexp
end

Expand Down
6 changes: 3 additions & 3 deletions test/test_foliage.rb
Expand Up @@ -40,9 +40,9 @@ def test_short_circuit

def test_postifmulti
report = Foliage.cov_text("for a in [false,true] do nil if a or !a; end")
puts report
assert_equal 1, report.size
assert_match(/condition true was never false/, report[0])
assert_equal 2, report.size
assert report.find { |x| x =~ /condition \((not |!)a\) was never false/ }
assert report.find { |x| x =~ /condition \(a or \((not |!)a\)\) was never false/ }
end

def test_postif
Expand Down

0 comments on commit 769b434

Please sign in to comment.