2016-07-06 05:53:16 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2017-01-21 09:02:33 +03:00
|
|
|
# Copyright (c) 2016-present, Facebook, Inc.
|
2016-07-06 05:53:16 +03:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the BSD-style license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
|
|
from .lib import testcase
|
|
|
|
import os
|
|
|
|
import stat
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
2016-07-08 21:25:45 +03:00
|
|
|
@testcase.eden_repo_test
|
2018-04-05 03:31:25 +03:00
|
|
|
class SedTest(testcase.EdenRepoTest):
|
2016-07-08 21:25:39 +03:00
|
|
|
def populate_repo(self):
|
|
|
|
self.repo.write_file('hello', 'hola\n')
|
|
|
|
self.repo.commit('Initial commit.')
|
|
|
|
|
2016-07-06 05:53:16 +03:00
|
|
|
def test_sed(self):
|
2016-07-08 21:25:39 +03:00
|
|
|
filename = os.path.join(self.mount, 'sedme')
|
2016-07-06 05:53:16 +03:00
|
|
|
|
|
|
|
with open(filename, 'w') as f:
|
|
|
|
f.write('foo\n')
|
|
|
|
|
|
|
|
before_st = os.lstat(filename)
|
|
|
|
self.assertTrue(stat.S_ISREG(before_st.st_mode))
|
|
|
|
|
|
|
|
subprocess.check_call(['sed', '-i', '-e', 's/foo/bar/', filename])
|
|
|
|
|
|
|
|
after_st = os.lstat(filename)
|
|
|
|
self.assertNotEqual(after_st.st_ino, before_st.st_ino,
|
|
|
|
msg='renamed file has a new inode number')
|
|
|
|
self.assertEqual(4, after_st.st_size)
|
|
|
|
with open(filename, 'r') as f:
|
|
|
|
file_st = os.fstat(f.fileno())
|
|
|
|
self.assertEqual(after_st.st_ino, file_st.st_ino)
|
|
|
|
self.assertEqual('bar\n', f.read())
|