Skip to content

Patching local function does not work in a string interpolation#78

Description

@ollien

馃憢

In my testing, it looks like patching does not work if a method is called from within a string interpolation expression. I took a look at the "limitations" section of the docs, and didn't see this mentioned, so I think it's a bug.

Module:

defmodule Patchtest do
  def greet() do
    "Hello, world!"
  end

  def format_greeting_1() do
    greeting = greet()
    "The program says: #{greeting}"
  end

  def format_greeting_2() do
    "The program says: #{greet()}"
  end
end

Test:

defmodule PatchtestTest do
  use ExUnit.Case
  use Patch
  doctest Patchtest

  test "greets the world" do
    patch(Patchtest, :greet, "Hello, patched!")

    assert Patchtest.format_greeting_1() == "The program says: Hello, patched!"
    assert Patchtest.format_greeting_2() == "The program says: Hello, patched!"
  end
end

This fails with:

  1) test greets the world (PatchtestTest)
     test/patchtest_test.exs:6
     Assertion with == failed
     code:  assert Patchtest.format_greeting_2() == "The program says: Hello, patched!"
     left:  "The program says: Hello, world!"
     right: "The program says: Hello, patched!"
     stacktrace:
       test/patchtest_test.exs:10: (test)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions