Class BinaryStubFileGeneratorTest

java.lang.Object
org.checkerframework.framework.stubifier.BinaryStubFileGeneratorTest

public class BinaryStubFileGeneratorTest extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    final org.junit.rules.TemporaryFolder
    A fresh directory per test, deleted afterwards along with everything under it -- including a bundle file, which --bundle writes as a sibling of the directory it covers rather than inside it.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    A bare relative input root with no directory component (e.g.
    void
    The JAR-mode analogue of bareRelativeBundleRootDoesNotCrash(): a bare relative .jar argument (e.g.
    void
    --bundle mode combines every .astub file 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.
    void
    A directory passed to per-file mode is searched recursively for .jar files, not just .astub files, and each one found is updated the same way a directly-named .jar root would be -- matching AnnotationFileUtil's directory walk, which likewise descends into a nested .jar when resolving -Astubs.
    void
    When a .astub entry 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 calls deleteStaleOutput) 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 a stale.binary.stub warning on every future compilation, with the tool's own suggested fix (re-running it) unable to clear it.
    void
    Regenerating a JAR whose entries already have binary siblings from a previous run replaces them, rather than leaving stale duplicates.
    void
    A .jar input root has each of its .astub entries pre-parsed into a new sibling .astub.bin.gz entry, 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).
    void
    Per-file mode writes a sibling .astub.bin.gz whose recorded fingerprint matches the exact source bytes it was generated from, and no other bytes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • tempFolder

      public final org.junit.rules.TemporaryFolder tempFolder
      A fresh directory per test, deleted afterwards along with everything under it -- including a bundle file, which --bundle writes as a sibling of the directory it covers rather than inside it.
  • Constructor Details

    • BinaryStubFileGeneratorTest

      public BinaryStubFileGeneratorTest()
  • Method Details

    • perFileModeWritesReadableSibling

      public void perFileModeWritesReadableSibling() throws Exception
      Per-file mode writes a sibling .astub.bin.gz whose recorded fingerprint matches the exact source bytes it was generated from, and no other bytes.
      Throws:
      Exception
    • bundleModeCombinesEveryFile

      public void bundleModeCombinesEveryFile() throws Exception
      --bundle mode combines every .astub file 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

      public void jarModeWritesEntriesInPlace() throws Exception
      A .jar input root has each of its .astub entries pre-parsed into a new sibling .astub.bin.gz entry, 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

      public void jarModeReplacesStaleEntry() throws Exception
      Regenerating a JAR whose entries already have binary siblings from a previous run replaces them, rather than leaving stale duplicates.
      Throws:
      Exception
    • jarModeRemovesEntryThatNoLongerParses

      public void jarModeRemovesEntryThatNoLongerParses() throws Exception
      When a .astub entry 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 calls deleteStaleOutput) 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 a stale.binary.stub warning on every future compilation, with the tool's own suggested fix (re-running it) unable to clear it.
      Throws:
      Exception
    • directoryModeRecursesIntoNestedJar

      public void directoryModeRecursesIntoNestedJar() throws Exception
      A directory passed to per-file mode is searched recursively for .jar files, not just .astub files, and each one found is updated the same way a directly-named .jar root would be -- matching AnnotationFileUtil's directory walk, which likewise descends into a nested .jar when 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

      public void bareRelativeBundleRootDoesNotCrash() throws Exception
      A bare relative input root with no directory component (e.g. "project-stubs", the exact form the manual's own --bundle example uses) must not crash: Path#getParent() is null for such a path, which Files.createTempFile rejects with a NullPointerException unless 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

      public void bareRelativeJarRootDoesNotCrash() throws Exception
      The JAR-mode analogue of bareRelativeBundleRootDoesNotCrash(): a bare relative .jar argument (e.g. "project-stubs.jar", the manual's own example) must not crash either.
      Throws:
      Exception