diff options
| author | 2019-12-23 13:32:08 +0000 | |
|---|---|---|
| committer | 2019-12-23 13:32:08 +0000 | |
| commit | e2bc36f12c6b4237ac1cc94f7ad7ba78737a5132 (patch) | |
| tree | 66771d84404c3c1b9b03d2605e597d6a5b240d68 /android/testing.go | |
| parent | 97e7279cc6ffaf707f03d0548392861e33034f98 (diff) | |
| parent | 9b478b083197297f7a08b795e1d392aa12d1c493 (diff) | |
Merge "Generate .srcjar for prebuilt_stubs_sources"
Diffstat (limited to 'android/testing.go')
| -rw-r--r-- | android/testing.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/android/testing.go b/android/testing.go index aaf98f595..4f0591b1d 100644 --- a/android/testing.go +++ b/android/testing.go @@ -16,6 +16,7 @@ package android import ( "fmt" + "path/filepath" "regexp" "strings" "testing" @@ -411,3 +412,33 @@ func AndroidMkDataForTest(t *testing.T, config Config, bpPath string, mod bluepr data.fillInData(config, bpPath, mod) return data } + +// Normalize the path for testing. +// +// If the path is relative to the build directory then return the relative path +// to avoid tests having to deal with the dynamically generated build directory. +// +// Otherwise, return the supplied path as it is almost certainly a source path +// that is relative to the root of the source tree. +// +// The build and source paths should be distinguishable based on their contents. +func NormalizePathForTesting(path Path) string { + p := path.String() + if w, ok := path.(WritablePath); ok { + rel, err := filepath.Rel(w.buildDir(), p) + if err != nil { + panic(err) + } + return rel + } + return p +} + +func NormalizePathsForTesting(paths Paths) []string { + var result []string + for _, path := range paths { + relative := NormalizePathForTesting(path) + result = append(result, relative) + } + return result +} |