Skip to content

Commit f63407c

Browse files
committed
Add symlink testing
1 parent 3d6b39e commit f63407c

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

_test_image.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ trap "rm -r \"$tmp_dir\"" EXIT
2828
echo "[test] Using temporary directory: $tmp_dir"
2929
echo "[test] Generating files..."
3030
echo "hello world" >"$tmp_dir"/test.txt
31+
ln -s test.txt "$tmp_dir"/symlink.txt
3132
for i in {1..1000}; do
3233
echo "echo "hello world" >>'$tmp_dir/test.txt'"
3334
done | xargs -P "$(nproc)" -I {} bash -c '{}'

test.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def test_path_tuple(path: str | bytes, expected: tuple[bytes, ...]) -> None:
2828
except Exception as e:
2929
FAILED = True # pyright: ignore[reportConstantRedefinition]
3030
print("fail")
31-
print(" ", end="")
32-
print(e)
31+
print(" ", end="", file=sys.stderr)
32+
print(e, file=sys.stderr)
3333

3434

3535
def _eval_or_False(source: str) -> Any: # pyright: ignore[reportExplicitAny, reportAny] # noqa: ANN401
@@ -51,7 +51,7 @@ def _assert(source: str, debug: Callable[[], Any] | None = None) -> None: # pyr
5151
FAILED = True # pyright: ignore[reportConstantRedefinition]
5252
print("fail")
5353
if debug is not None:
54-
print(f" {debug()}")
54+
print(f" {debug()}", file=sys.stderr)
5555

5656

5757
def test_magic_error(f: BufferedReader) -> None:
@@ -68,8 +68,8 @@ def test_magic_error(f: BufferedReader) -> None:
6868
except Exception as e:
6969
FAILED = True # pyright: ignore[reportConstantRedefinition]
7070
print("fail")
71-
print(" ", end="")
72-
print(e)
71+
print(" ", end="", file=sys.stderr)
72+
print(e, file=sys.stderr)
7373

7474

7575
def test_root_inode(volume: ext4.Volume) -> None:
@@ -82,8 +82,8 @@ def test_root_inode(volume: ext4.Volume) -> None:
8282
except ext4.struct.ChecksumError as e:
8383
FAILED = True # pyright: ignore[reportConstantRedefinition]
8484
print("fail")
85-
print(" ", end="")
86-
print(e)
85+
print(" ", end="", file=sys.stderr)
86+
print(e, file=sys.stderr)
8787

8888

8989
print("check ext4.Volume stream validation: ", end="")
@@ -98,8 +98,8 @@ def test_root_inode(volume: ext4.Volume) -> None:
9898
except Exception as e:
9999
FAILED = True # pyright: ignore[reportConstantRedefinition]
100100
print("fail")
101-
print(" ", end="")
102-
print(e)
101+
print(" ", end="", file=sys.stderr)
102+
print(e, file=sys.stderr)
103103

104104
test_path_tuple("/", tuple())
105105
test_path_tuple(b"/", tuple())
@@ -162,6 +162,10 @@ def test_root_inode(volume: ext4.Volume) -> None:
162162
_ = b.seek(0)
163163
_assert(f"b.read({x}) == {data[:x]}", lambda: b.seek(0) == 0 and b.read(x))
164164

165+
inode = cast(ext4.SymbolicLink, volume.inode_at("/symlink.txt"))
166+
_assert("isinstance(inode, ext4.SymbolicLink)")
167+
_assert('inode.readlink() == b"test.txt"', inode.readlink)
168+
165169
img_file = "test_htree.ext4"
166170
print(f"Testing image: {img_file}")
167171
with open(img_file, "rb") as f:

0 commit comments

Comments
 (0)