tests/test-editor-filename.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 45877 ac362d5a7893
child 49621 55c6ebd11cb9
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.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34029
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     1
Test temp file used with an editor has the expected suffix.
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     2
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     3
  $ hg init
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     4
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     5
Create an editor that writes its arguments to stdout and set it to $HGEDITOR.
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     6
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     7
  $ cat > editor.sh << EOF
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     8
  > echo "\$@"
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
     9
  > exit 1
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    10
  > EOF
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    11
  $ hg add editor.sh
34058
4bf1889456f3 test-editor-filename: fix portability of fake editor command
Yuya Nishihara <yuya@tcha.org>
parents: 34054
diff changeset
    12
  $ HGEDITOR="sh $TESTTMP/editor.sh"
34029
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    13
  $ export HGEDITOR
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    14
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    15
Verify that the path for a commit editor has the expected suffix.
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    16
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    17
  $ hg commit
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    18
  *.commit.hg.txt (glob)
34058
4bf1889456f3 test-editor-filename: fix portability of fake editor command
Yuya Nishihara <yuya@tcha.org>
parents: 34054
diff changeset
    19
  abort: edit failed: sh exited with status 1
45877
ac362d5a7893 errors: introduce CanceledError and use it in a few places
Martin von Zweigbergk <martinvonz@google.com>
parents: 42566
diff changeset
    20
  [250]
34029
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    21
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    22
Verify that the path for a histedit editor has the expected suffix.
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    23
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    24
  $ cat >> $HGRCPATH <<EOF
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    25
  > [extensions]
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    26
  > rebase=
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    27
  > histedit=
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    28
  > EOF
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    29
  $ hg commit --message 'At least one commit for histedit.'
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    30
  $ hg histedit
6e6452bc441d editor: use an unambiguous path suffix for editor files
Michael Bolin <mbolin@fb.com>
parents:
diff changeset
    31
  *.histedit.hg.txt (glob)
34058
4bf1889456f3 test-editor-filename: fix portability of fake editor command
Yuya Nishihara <yuya@tcha.org>
parents: 34054
diff changeset
    32
  abort: edit failed: sh exited with status 1
45877
ac362d5a7893 errors: introduce CanceledError and use it in a few places
Martin von Zweigbergk <martinvonz@google.com>
parents: 42566
diff changeset
    33
  [250]
34054
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    34
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    35
Verify that when performing an action that has the side-effect of creating an
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    36
editor for a diff, the file ends in .diff.
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    37
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    38
  $ echo 1 > one
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    39
  $ echo 2 > two
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    40
  $ hg add
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    41
  adding one
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    42
  adding two
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    43
  $ hg commit --interactive --config ui.interactive=true --config ui.interface=text << EOF
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    44
  > y
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    45
  > e
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    46
  > q
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    47
  > EOF
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    48
  diff --git a/one b/one
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    49
  new file mode 100644
42566
f802a75da585 patch: use a short, fixed-size message for last line of prompt (issue6158)
Kyle Lippincott <spectral@google.com>
parents: 34058
diff changeset
    50
  examine changes to 'one'?
f802a75da585 patch: use a short, fixed-size message for last line of prompt (issue6158)
Kyle Lippincott <spectral@google.com>
parents: 34058
diff changeset
    51
  (enter ? for help) [Ynesfdaq?] y
34054
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    52
  
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    53
  @@ -0,0 +1,1 @@
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    54
  +1
42566
f802a75da585 patch: use a short, fixed-size message for last line of prompt (issue6158)
Kyle Lippincott <spectral@google.com>
parents: 34058
diff changeset
    55
  record change 1/2 to 'one'?
f802a75da585 patch: use a short, fixed-size message for last line of prompt (issue6158)
Kyle Lippincott <spectral@google.com>
parents: 34058
diff changeset
    56
  (enter ? for help) [Ynesfdaq?] e
34054
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    57
  
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    58
  *.diff (glob)
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    59
  editor exited with exit code 1
42566
f802a75da585 patch: use a short, fixed-size message for last line of prompt (issue6158)
Kyle Lippincott <spectral@google.com>
parents: 34058
diff changeset
    60
  record change 1/2 to 'one'?
f802a75da585 patch: use a short, fixed-size message for last line of prompt (issue6158)
Kyle Lippincott <spectral@google.com>
parents: 34058
diff changeset
    61
  (enter ? for help) [Ynesfdaq?] q
34054
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    62
  
3c82b14d2838 editor: file created for diff action should have .diff suffix
Michael Bolin <mbolin@fb.com>
parents: 34029
diff changeset
    63
  abort: user quit
45877
ac362d5a7893 errors: introduce CanceledError and use it in a few places
Martin von Zweigbergk <martinvonz@google.com>
parents: 42566
diff changeset
    64
  [250]