question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid file names are generated because of test names

See original GitHub issue

I’m having these tests in src/androidTest/kotlin:

class ColorUtilsKtTest {

	class ReplaceAlphaFrom(
		val useCase: String,
		@ColorInt val receiver: Int,
		@ColorInt val param: Int,
		@ColorInt val expected: Int,
	)

	@TestFactory fun replaceAlphaFrom() =
		listOf(
			ReplaceAlphaFrom(
				"Replaces alpha keeping RGB",
				Color.argb(0x12, 0x34, 0x56, 0x78),
				Color.argb(0x87, 0x65, 0x43, 0x21),
				Color.argb(0x87, 0x34, 0x56, 0x78),
			),
			ReplaceAlphaFrom(
				"Adds only alpha",
				Color.argb(0x00, 0x00, 0x00, 0x00),
				Color.argb(0xAB, 0x00, 0x00, 0x00),
				Color.argb(0xAB, 0x00, 0x00, 0x00),
			),
			ReplaceAlphaFrom(
				"Clears alpha",
				Color.argb(0x12, 0x34, 0x56, 0x78),
				Color.argb(0x00, 0x00, 0x00, 0x00),
				Color.argb(0x00, 0x34, 0x56, 0x78),
			),
		).map {
			dynamicTest(it.useCase) {
				val result = it.receiver.replaceAlphaFrom(it.param)

				assertThat(it.expected, equalTo(result))
			}
		}
}

When running them in Android Studio I get image which is beautiful, well done!

I have the same structure in src/test/kotlin too, that looks like this: image

At this point I can see that there’s a limitation of nesting test containers in androidTest and you worked around it by concat-ing. I’ve identified this line to be responsible:

https://github.com/mannodermaus/android-junit5/blob/9136759f3685b4def2d4124948aa62eb5d5c233c/instrumentation/runner/src/main/kotlin/de/mannodermaus/junit5/internal/runners/AndroidJUnitPlatformTestTree.kt#L53


Now, onto the issue… When running on AGP 7.1 (gradlew :feature:base:connectedCheck) there are some new features to dump the logcat and other files, see what is the output here: image

This is on Windows, where there are reserved characters in file names (see also wiki. You can see this in action, because build/outputs/androidTest-results/connected/API_29(AVD) - 10/logcat-net.twisterrob.colorfilters.android.ColorUtilsKtTest-replaceAlphaFrom file name is truncated at the :, and actually there’s only 1 file, not 3. (AGP issue)

When running the same on Mac (CI) I get the full name: build/outputs/androidTest-results/connected/test(AVD) - 10/logcat-net.twisterrob.colorfilters.android.ColorUtilsKtTest-replaceAlphaFrom: Adds only alpha.txt, but when trying to upload artifacts I get an error because of the “invalid” character: https://github.com/TWiStErRob/net.twisterrob.colorfilters/runs/5487958432?check_suite_focus=true#step:7:17 (AGP issue)

image

At this point I would like to ask to make it configurable what the joiner characters are, e.g. I would configure it to - to prevent this error. Related android-test issue: https://github.com/android/android-test/issues/1314

Repro: https://github.com/TWiStErRob/repros/tree/master/agp/junit5-logcat-filenames

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
TWiStErRobcommented, Apr 10, 2022

Btw, I tried to type a : and Windows told me this: image

Mind you, this means that &, ;, {/}, %, =, ', !, #, @, $ are all valid characters.

image

1reaction
TWiStErRobcommented, Apr 9, 2022

Awesome investigation, brave soul embarking on a journey into the rabbit hole. 🙏

I opened a bug for AGP too, would you mind commenting on the issue with your findings?

In the meantime please consider making a change to allow for at least making it work in some way. A configuration param that’s off by default, or even just mutable private field that can be set with reflection 🥺. “Ugly working” is better than “pretty, but broken”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generating an invalid file name for testing purposes
Writable is created giving a specified output file name. I need to test the case where the Writable should fail, that it should...
Read more >
MS Test with #line directive containing invalid file name ...
cs" file generated by Visual Studio when a new test project is created. The only thing I added as the #line directive containing...
Read more >
How would I go about creating a filename with invalid ...
You can boot from a Linux disk (such as Knoppix), and mount the NTFS partition. Linux has much less restrictions on files names,...
Read more >
Programmatically Check Dynamic File Name For Invalid ...
I have a SQL Script that runs every night and will generate files showing each Sales Reps production for the previous day. This...
Read more >
Delete file containing invalid characters in windows
I guess you can try the 8.3 name? ... To get the file name dir a dir /x ... files with invalid characters...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found