tests/test-mactext.t
author Gregory Szorc <gregory.szorc@gmail.com>
Sat, 28 Mar 2020 13:29:25 -0700
changeset 44642 da9b7f9635a2
parent 39707 5abc47d4ca6b
child 46417 768056549737
permissions -rw-r--r--
tests: use `f --hexdump` to print file content The inline print.py in this test wasn't fully compatible with Python 3 because it was reading from sys.stdin, which already normalized line endings since it operates in the realm of str on Python 3. To do this correctly, we'd need to read from sys.stdin.buffer on Python 3. This would entail conditional code. I felt this was too much effort. So I just replaced the custom script with `f`, which already knows how to do the right thing. test-mactext.t now passes on Python 3 on Windows. Differential Revision: https://phab.mercurial-scm.org/D8336


  $ cat > unix2mac.py <<EOF
  > import sys
  > 
  > for path in sys.argv[1:]:
  >     data = open(path, 'rb').read()
  >     data = data.replace(b'\n', b'\r')
  >     open(path, 'wb').write(data)
  > EOF
  $ hg init
  $ echo '[hooks]' >> .hg/hgrc
  $ echo 'pretxncommit.cr = python:hgext.win32text.forbidcr' >> .hg/hgrc
  $ echo 'pretxnchangegroup.cr = python:hgext.win32text.forbidcr' >> .hg/hgrc
  $ cat .hg/hgrc
  [hooks]
  pretxncommit.cr = python:hgext.win32text.forbidcr
  pretxnchangegroup.cr = python:hgext.win32text.forbidcr

  $ echo hello > f
  $ hg add f
  $ hg ci -m 1

  $ "$PYTHON" unix2mac.py f
  $ hg ci -m 2
  attempt to commit or push text file(s) using CR line endings
  in dea860dc51ec: f
  transaction abort!
  rollback completed
  abort: pretxncommit.cr hook failed
  [255]
  $ hg cat f | f --hexdump
  
  0000: 68 65 6c 6c 6f 0a                               |hello.|
  $ f --hexdump f
  f:
  0000: 68 65 6c 6c 6f 0d                               |hello.|