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.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import stat
|
|
|
|
import subprocess
|
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
from .lib import testcase
|
|
|
|
|
2016-07-06 05:53:16 +03:00
|
|
|
|
2016-07-08 21:25:45 +03:00
|
|
|
@testcase.eden_repo_test
|
2018-04-05 03:31:25 +03:00
|
|
|
class SedTest(testcase.EdenRepoTest):
|
2018-04-05 03:31:28 +03:00
|
|
|
def populate_repo(self) -> None:
|
2018-05-10 07:33:49 +03:00
|
|
|
self.repo.write_file("hello", "hola\n")
|
|
|
|
self.repo.commit("Initial commit.")
|
2016-07-08 21:25:39 +03:00
|
|
|
|
2018-04-05 03:31:28 +03:00
|
|
|
def test_sed(self) -> None:
|
2018-05-10 07:33:49 +03:00
|
|
|
filename = os.path.join(self.mount, "sedme")
|
2016-07-06 05:53:16 +03:00
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
with open(filename, "w") as f:
|
|
|
|
f.write("foo\n")
|
2016-07-06 05:53:16 +03:00
|
|
|
|
|
|
|
before_st = os.lstat(filename)
|
|
|
|
self.assertTrue(stat.S_ISREG(before_st.st_mode))
|
|
|
|
|
2018-05-10 07:33:49 +03:00
|
|
|
subprocess.check_call(["sed", "-i", "-e", "s/foo/bar/", filename])
|
2016-07-06 05:53:16 +03:00
|
|
|
|
|
|
|
after_st = os.lstat(filename)
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertNotEqual(
|
|
|
|
after_st.st_ino, before_st.st_ino, msg="renamed file has a new inode number"
|
|
|
|
)
|
2016-07-06 05:53:16 +03:00
|
|
|
self.assertEqual(4, after_st.st_size)
|
2018-05-10 07:33:49 +03:00
|
|
|
with open(filename, "r") as f:
|
2016-07-06 05:53:16 +03:00
|
|
|
file_st = os.fstat(f.fileno())
|
|
|
|
self.assertEqual(after_st.st_ino, file_st.st_ino)
|
2018-05-10 07:33:49 +03:00
|
|
|
self.assertEqual("bar\n", f.read())
|