Class BinaryStubFileGeneratorTest
java.lang.Object
org.checkerframework.framework.stubifier.BinaryStubFileGeneratorTest
Tests for
BinaryStubFileGenerator's two modes (per-file siblings, and a whole-directory
--bundle), and for the source-fingerprint staleness detection that BinaryStubData.matchesSource(byte[]) provides for a user-supplied -Astubs file (see
AnnotationFileElementTypes#commandLineBinaryStub, which relies on it instead of comparing file
modification times).
These tests call BinaryStubFileGenerator.main(java.lang.String[]) directly, so they exercise only its
success paths: its usage-error and bundle-name-collision paths call System.exit, which
would terminate the test JVM, and are intentionally not exercised here.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal org.junit.rules.TemporaryFolderA fresh directory per test, deleted afterwards along with everything under it -- including a bundle file, which--bundlewrites as a sibling of the directory it covers rather than inside it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidA bare relative input root with no directory component (e.g.voidThe JAR-mode analogue ofbareRelativeBundleRootDoesNotCrash(): a bare relative.jarargument (e.g.void--bundlemode combines every.astubfile under the directory, including one in a subdirectory, into a single file with one entry per source file, keyed by its slash-separated relative path.voidA directory passed to per-file mode is searched recursively for.jarfiles, not just.astubfiles, and each one found is updated the same way a directly-named.jarroot would be -- matchingAnnotationFileUtil's directory walk, which likewise descends into a nested.jarwhen resolving-Astubs.voidWhen a.astubentry that already has a binary sibling is edited into something unparseable, regenerating removes the now-unregenerable sibling instead of leaving it behind: unlike the directory case (which callsdeleteStaleOutput) or a bundle (which is rewritten from scratch each time), a JAR is modified incrementally, so this must be handled explicitly -- otherwise the stale sibling would trigger astale.binary.stubwarning on every future compilation, with the tool's own suggested fix (re-running it) unable to clear it.voidRegenerating a JAR whose entries already have binary siblings from a previous run replaces them, rather than leaving stale duplicates.voidA.jarinput root has each of its.astubentries pre-parsed into a new sibling.astub.bin.gzentry, written into the same JAR file in place: the original entries are untouched, and the output directory argument is ignored (there is nowhere else a JAR's own entries could sensibly be written).voidPer-file mode writes a sibling.astub.bin.gzwhose recorded fingerprint matches the exact source bytes it was generated from, and no other bytes.
-
Field Details
-
tempFolder
public final org.junit.rules.TemporaryFolder tempFolderA fresh directory per test, deleted afterwards along with everything under it -- including a bundle file, which--bundlewrites as a sibling of the directory it covers rather than inside it.
-
-
Constructor Details
-
BinaryStubFileGeneratorTest
public BinaryStubFileGeneratorTest()
-
-
Method Details
-
perFileModeWritesReadableSibling
Per-file mode writes a sibling.astub.bin.gzwhose recorded fingerprint matches the exact source bytes it was generated from, and no other bytes.- Throws:
Exception
-
bundleModeCombinesEveryFile
--bundlemode combines every.astubfile under the directory, including one in a subdirectory, into a single file with one entry per source file, keyed by its slash-separated relative path.- Throws:
Exception
-
jarModeWritesEntriesInPlace
A.jarinput root has each of its.astubentries pre-parsed into a new sibling.astub.bin.gzentry, written into the same JAR file in place: the original entries are untouched, and the output directory argument is ignored (there is nowhere else a JAR's own entries could sensibly be written).- Throws:
Exception
-
jarModeReplacesStaleEntry
Regenerating a JAR whose entries already have binary siblings from a previous run replaces them, rather than leaving stale duplicates.- Throws:
Exception
-
jarModeRemovesEntryThatNoLongerParses
When a.astubentry that already has a binary sibling is edited into something unparseable, regenerating removes the now-unregenerable sibling instead of leaving it behind: unlike the directory case (which callsdeleteStaleOutput) or a bundle (which is rewritten from scratch each time), a JAR is modified incrementally, so this must be handled explicitly -- otherwise the stale sibling would trigger astale.binary.stubwarning on every future compilation, with the tool's own suggested fix (re-running it) unable to clear it.- Throws:
Exception
-
directoryModeRecursesIntoNestedJar
A directory passed to per-file mode is searched recursively for.jarfiles, not just.astubfiles, and each one found is updated the same way a directly-named.jarroot would be -- matchingAnnotationFileUtil's directory walk, which likewise descends into a nested.jarwhen resolving-Astubs. Without this, a nested jar's entries could never get a binary form through the enclosing directory root, permanently triggering the "incomplete binary stub setup" warning with no way to clear it.- Throws:
Exception
-
bareRelativeBundleRootDoesNotCrash
A bare relative input root with no directory component (e.g."project-stubs", the exact form the manual's own--bundleexample uses) must not crash:Path#getParent()isnullfor such a path, whichFiles.createTempFilerejects with aNullPointerExceptionunless the path is first made absolute.BinaryStubFileGenerator.main(java.lang.String[])resolves relative arguments against the process's current working directory, which cannot be changed within this JVM once started, so this runs the generator in a genuinely separate process with a controlled working directory, passing bare relative names exactly as a user would from within that directory.- Throws:
Exception
-
bareRelativeJarRootDoesNotCrash
The JAR-mode analogue ofbareRelativeBundleRootDoesNotCrash(): a bare relative.jarargument (e.g."project-stubs.jar", the manual's own example) must not crash either.- Throws:
Exception
-