tests/test-releasenotes-parsing.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 36769 3fff6f30bd7f
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.

#require fuzzywuzzy

  $ cat >> $HGRCPATH << EOF
  > [extensions]
  > releasenotes=
  > EOF

Bullet point with a single item spanning a single line

  $ hg debugparsereleasenotes - << EOF
  > New Features
  > ============
  > 
  > * Bullet point item with a single line
  > EOF
  section: feature
    bullet point:
      paragraph: Bullet point item with a single line

Bullet point that spans multiple lines.

  $ hg debugparsereleasenotes - << EOF
  > New Features
  > ============
  > 
  > * Bullet point with a paragraph
  >   that spans multiple lines.
  > EOF
  section: feature
    bullet point:
      paragraph: Bullet point with a paragraph that spans multiple lines.

  $ hg debugparsereleasenotes - << EOF
  > New Features
  > ============
  > 
  > * Bullet point with a paragraph
  >   that spans multiple lines.
  > 
  >   And has an empty line between lines too.
  >   With a line cuddling that.
  > EOF
  section: feature
    bullet point:
      paragraph: Bullet point with a paragraph that spans multiple lines.
      paragraph: And has an empty line between lines too. With a line cuddling that.

Multiple bullet points. With some entries being multiple lines.

  $ hg debugparsereleasenotes - << EOF
  > New Features
  > ============
  > 
  > * First bullet point. It has a single line.
  > 
  > * Second bullet point.
  >   It consists of multiple lines.
  > 
  > * Third bullet point. It has a single line.
  > EOF
  section: feature
    bullet point:
      paragraph: First bullet point. It has a single line.
    bullet point:
      paragraph: Second bullet point. It consists of multiple lines.
    bullet point:
      paragraph: Third bullet point. It has a single line.

Bullet point without newline between items

  $ hg debugparsereleasenotes - << EOF
  > New Features
  > ============
  > 
  > * First bullet point
  > * Second bullet point
  >   And it has multiple lines
  > * Third bullet point
  > * Fourth bullet point
  > EOF
  section: feature
    bullet point:
      paragraph: First bullet point
    bullet point:
      paragraph: Second bullet point And it has multiple lines
    bullet point:
      paragraph: Third bullet point
    bullet point:
      paragraph: Fourth bullet point

Sub-section contents are read

  $ hg debugparsereleasenotes - << EOF
  > New Features
  > ============
  > 
  > First Feature
  > -------------
  > 
  > This is the first new feature that was implemented.
  > 
  > And a second paragraph about it.
  > 
  > Second Feature
  > --------------
  > 
  > This is the second new feature that was implemented.
  > 
  > Paragraph two.
  > 
  > Paragraph three.
  > EOF
  section: feature
    subsection: First Feature
      paragraph: This is the first new feature that was implemented.
      paragraph: And a second paragraph about it.
    subsection: Second Feature
      paragraph: This is the second new feature that was implemented.
      paragraph: Paragraph two.
      paragraph: Paragraph three.

Multiple sections are read

  $ hg debugparsereleasenotes - << EOF
  > New Features
  > ============
  > 
  > * Feature 1
  > * Feature 2
  > 
  > Bug Fixes
  > =========
  > 
  > * Fix 1
  > * Fix 2
  > EOF
  section: feature
    bullet point:
      paragraph: Feature 1
    bullet point:
      paragraph: Feature 2
  section: fix
    bullet point:
      paragraph: Fix 1
    bullet point:
      paragraph: Fix 2

Mixed sub-sections and bullet list

  $ hg debugparsereleasenotes - << EOF
  > New Features
  > ============
  > 
  > Feature 1
  > ---------
  > 
  > Some words about the first feature.
  > 
  > Feature 2
  > ---------
  > 
  > Some words about the second feature.
  > That span multiple lines.
  > 
  > Other Changes
  > -------------
  > 
  > * Bullet item 1
  > * Bullet item 2
  > EOF
  section: feature
    subsection: Feature 1
      paragraph: Some words about the first feature.
    subsection: Feature 2
      paragraph: Some words about the second feature. That span multiple lines.
    bullet point:
      paragraph: Bullet item 1
    bullet point:
      paragraph: Bullet item 2

Warn user in case of unexpected block while parsing

  $ hg init relnotes-warn
  $ cd relnotes-warn
  $ touch feature1
  $ hg -q commit -A -l - << EOF
  > commit 1
  > 
  > .. feature::
  > 
  >    new feature added.
  >     some words about the feature.
  > EOF

  $ hg releasenote -r .
  changeset a4251905c440: unexpected block in release notes directive feature
  New Features
  ============
  
  * new feature added.  some words about the feature.

  $ cd ..