-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add workaround when patching variables with selector
- Loading branch information
Showing
10 changed files
with
135 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Tests of the runtime package | ||
Runnable tests are listed in file [../../script/run-test/main.go](../../script/run-test/main.go). | ||
|
||
# Run tests | ||
```sh | ||
# all | ||
|
||
# specific test | ||
go run -tags dev ./cmd/xgo test --with-goroot go1.17.13 --project-dir ./runtime/test/mock_var -v -run TestThirdPartyTypeMethodVar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
package sub | ||
|
||
var A string = "subA" | ||
|
||
type Mapping map[int]string | ||
|
||
func (c Mapping) Get(i int) string { | ||
return c[i] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// var mock: | ||
// | ||
// if variable is not a pointer, taking its address, then use it as receiver, it can be converted to value receiver implicitly | ||
// otherwise if variable is a pointer, taking its address does not work. | ||
package proof_of_var_mock | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type Stub struct { | ||
} | ||
|
||
type PtrStub *Stub | ||
|
||
func (c Stub) A() { | ||
} | ||
func (c *Stub) B() { | ||
} | ||
|
||
// invalid receiver type PtrStub (pointer or interface type) | ||
// | ||
// func (c PtrStub) X(){ | ||
// | ||
// } | ||
|
||
var stub Stub = Stub{} | ||
var pstub *Stub = &Stub{} | ||
|
||
func TestVariableCanBeTrapped(t *testing.T) { | ||
|
||
stub.A() | ||
stub.B() | ||
|
||
__mock_stub := &stub | ||
__mock_stub.A() | ||
__mock_stub.B() | ||
|
||
pstub.A() | ||
pstub.B() | ||
|
||
// __mock_pstub.B undefined (type **Stub has no field or method | ||
// | ||
// __mock_pstub := &pstub | ||
// __mock_pstub.A() | ||
// __mock_pstub.B() | ||
} |