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:

defmodulePatchtestdodefgreet()do"Hello, world!"enddefformat_greeting_1()dogreeting=greet()"The program says: #{greeting}"enddefformat_greeting_2()do"The program says: #{greet()}"endend

Test:

defmodulePatchtestTestdouseExUnit.CaseusePatchdoctestPatchtesttest"greets the world"dopatch(Patchtest,:greet,"Hello, patched!")assertPatchtest.format_greeting_1()=="The program says: Hello, patched!"assertPatchtest.format_greeting_2()=="The program says: Hello, patched!"endend

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)

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