Skip to content

Commit be407ed

Browse files
committed
Merge remote-tracking branch 'ben/st-test'
2 parents 3335c00 + 5607d7b commit be407ed

File tree

24 files changed

+618
-126
lines changed

24 files changed

+618
-126
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
build-essential debhelper dh-python dh-apparmor
3939
git config --global --add safe.directory "$GITHUB_WORKSPACE"
4040
- uses: actions/checkout@v4
41-
4241
- name: Test build
4342
run: |
4443
dpkg-buildpackage -b -i -us -uc
@@ -47,3 +46,5 @@ jobs:
4746
run: |
4847
set -o xtrace
4948
./run-tests
49+
git clone https://github.com/nickboucher/trojan-source
50+
./unicode-testscript

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
line-length = 79
33
[tool.mypy]
44
strict="yes"
5+
[tool.pylint.'SIMILARITIES']
6+
min-similarity-lines=10
57
[tool.pylint.'FORMAT']
68
expected-line-ending-format="LF"
79
max-line-length=79

run-tests

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ pyrc="${git_toplevel}/pyproject.toml"
55
pythonpath="${git_toplevel}/usr/lib/python3/dist-packages"
66
export PYTHONPATH="${pythonpath}${PYTHONPATH+":${PYTHONPATH}"}"
77

8-
pytest=(python3 -m pytest -o 'python_files=*.py')
8+
pytest=(python3 -m pytest -o 'python_files=tests/*.py')
99
black=(black --config="${pyrc}" --color --diff --check)
1010
pylint=(pylint --rcfile="${pyrc}")
1111
mypy=(mypy --config-file="${pyrc}")
1212

1313
cd "${pythonpath}/stdisplay/"
14-
"${pytest[@]}" "${@}"
14+
# Ideally, these variables should be ignored by the tests...
15+
NO_COLOR="" COLORTERM="" TERM="xterm-direct" "${pytest[@]}" "${@}"
1516
"${black[@]}" .
1617
find . -type f -name "*.py" -print0 | xargs -0 "${pylint[@]}"
1718
"${mypy[@]}" .

unicode-testscript

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@
33
## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <[email protected]>
44
## See the file COPYING for copying conditions.
55

6-
## NOTE:
7-
## Assumes folder 'trojan-source' in the home folder.
8-
##
9-
## cd ~
10-
## git clone [email protected]:nickboucher/trojan-source.git
11-
12-
## TODO: Convert into proper unit test and/or CI.
13-
146
#set -x
157
set -e
168
set -o nounset
179
set -o pipefail
1810
set -o errtrace
1911

20-
if [ "$(id -u)" = 0 ]; then
21-
printf "%s\n" "$0: ERROR: No need to run as root!" >&2
22-
exit 1
12+
if [ "$(id -u)" = 0 ] && [ -z "${GITHUB_WORKSPACE:-}" ]; then
13+
printf "%s\n" "$0: ERROR: No need to run as root!" >&2
14+
exit 1
2315
fi
2416

2517
folder_list="Assembly Bash C C# C++ Go Java JavaScript Python RegEx Rust Solidity"

usr/bin/stcat

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
#!/usr/bin/env python3
2+
# pylint: disable=missing-module-docstring
23

34
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
45
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
56
##
67
## SPDX-License-Identifier: AGPL-3.0-or-later
78

8-
"""Safely print stdin or file to stdout."""
9-
10-
from fileinput import input as file_input
11-
from sys import stdin, stdout
12-
from stdisplay.stdisplay import stdisplay
13-
14-
15-
def main() -> None:
16-
"""Safely print stdin or file to stdout."""
17-
stdin.reconfigure(errors="ignore") # type: ignore
18-
## File input reads stdin when no file is provided or file is '-'.
19-
for untrusted_text in file_input(encoding="ascii", errors="replace"):
20-
stdout.write(stdisplay(untrusted_text))
21-
stdout.flush()
22-
9+
from stdisplay.stcat import main
2310

2411
if __name__ == "__main__":
2512
main()

usr/bin/stcatn

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
#!/usr/bin/env python3
2+
# pylint: disable=missing-module-docstring
23

34
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
45
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
56
##
67
## SPDX-License-Identifier: AGPL-3.0-or-later
78

8-
"""
9-
Safely print stdin or file to stdout with tweaks
10-
(trim trailing whitespace, ensure final newline).
11-
"""
12-
13-
from fileinput import input as file_input
14-
from sys import stdin, stdout
15-
from stdisplay.stdisplay import stdisplay
16-
17-
18-
def main() -> None:
19-
"""
20-
main
21-
"""
22-
stdin.reconfigure(errors="ignore") # type: ignore
23-
24-
for line in file_input(encoding="ascii", errors="replace"):
25-
stdout.write(stdisplay(line).rstrip() + "\n")
26-
27-
stdout.flush()
28-
9+
from stdisplay.stcatn import main
2910

3011
if __name__ == "__main__":
3112
main()

usr/bin/stecho

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
#!/usr/bin/env python3
2+
# pylint: disable=missing-module-docstring
23

34
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
45
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
56
##
67
## SPDX-License-Identifier: AGPL-3.0-or-later
78

8-
"""Safely print argument to stdout with echo's formatting."""
9-
10-
from sys import argv, stdout
11-
from stdisplay.stdisplay import stdisplay
12-
13-
14-
def main() -> None:
15-
"""Safely print argument to stdout with echo's formatting."""
16-
if len(argv) > 1:
17-
untrusted_text = " ".join(argv[1:])
18-
stdout.write(stdisplay(untrusted_text))
19-
stdout.write("\n")
20-
stdout.flush()
21-
9+
from stdisplay.stecho import main
2210

2311
if __name__ == "__main__":
2412
main()

usr/bin/stprint

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
#!/usr/bin/env python3
2+
# pylint: disable=missing-module-docstring
23

34
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
45
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
56
##
67
## SPDX-License-Identifier: AGPL-3.0-or-later
78

8-
"""Safely print argument to stdout."""
9-
10-
from sys import argv, stdout
11-
from stdisplay.stdisplay import stdisplay
12-
13-
14-
def main() -> None:
15-
"""Safely print argument to stdout."""
16-
if len(argv) > 1:
17-
untrusted_text = "".join(argv[1:])
18-
stdout.write(stdisplay(untrusted_text))
19-
stdout.flush()
20-
9+
from stdisplay.stprint import main
2110

2211
if __name__ == "__main__":
2312
main()

usr/bin/stsponge

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,12 @@
11
#!/usr/bin/env python3
2+
# pylint: disable=missing-module-docstring
23

34
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
45
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
56
##
67
## SPDX-License-Identifier: AGPL-3.0-or-later
78

8-
"""Safely print stdin to stdout or file."""
9-
10-
from sys import argv, stdin, stdout
11-
import shutil
12-
from tempfile import NamedTemporaryFile
13-
from stdisplay.stdisplay import stdisplay
14-
15-
16-
def main() -> None:
17-
"""Safely print stdin to stdout or file."""
18-
untrusted_text_list = []
19-
stdin.reconfigure(errors="ignore") # type: ignore
20-
for untrusted_text in stdin:
21-
untrusted_text_list.append(untrusted_text)
22-
if len(argv) == 1:
23-
stdout.write(stdisplay("".join(untrusted_text_list)))
24-
stdout.flush()
25-
else:
26-
with NamedTemporaryFile(mode="w", delete=False) as temp_file:
27-
temp_file.write(stdisplay("".join(untrusted_text_list)))
28-
temp_file.flush()
29-
for file in argv[1:]:
30-
shutil.copy2(temp_file.name, file)
31-
temp_file.close()
32-
9+
from stdisplay.stsponge import main
3310

3411
if __name__ == "__main__":
3512
main()

usr/bin/sttee

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
#!/usr/bin/env python3
2+
# pylint: disable=missing-module-docstring
23

34
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
45
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
56
##
67
## SPDX-License-Identifier: AGPL-3.0-or-later
78

8-
"""Safely print stdin to stdout and file."""
9-
from sys import argv, stdin, stdout
10-
from stdisplay.stdisplay import stdisplay
11-
12-
13-
def main() -> None:
14-
"""Safely print stdin to stdout and file."""
15-
untrusted_text_list = []
16-
stdin.reconfigure(errors="ignore") # type: ignore
17-
for untrusted_text in stdin:
18-
untrusted_text_list.append(untrusted_text)
19-
stdout.write(stdisplay(untrusted_text))
20-
stdout.flush()
21-
if len(argv) > 1:
22-
for file_arg in argv[1:]:
23-
with open(file_arg, mode="w", encoding="ascii") as file:
24-
file.write(stdisplay("".join(untrusted_text_list)))
25-
9+
from stdisplay.sttee import main
2610

2711
if __name__ == "__main__":
2812
main()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
4+
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
5+
##
6+
## SPDX-License-Identifier: AGPL-3.0-or-later
7+
8+
"""Safely print stdin or file to stdout."""
9+
10+
from fileinput import input as file_input
11+
from sys import stdin, stdout, modules
12+
from stdisplay.stdisplay import stdisplay
13+
14+
15+
def main() -> None:
16+
"""Safely print stdin or file to stdout."""
17+
# https://github.com/pytest-dev/pytest/issues/4843
18+
if "pytest" not in modules:
19+
stdin.reconfigure(errors="ignore") # type: ignore
20+
## File input reads stdin when no file is provided or file is '-'.
21+
for untrusted_text in file_input(encoding="ascii", errors="replace"):
22+
stdout.write(stdisplay(untrusted_text))
23+
stdout.flush()
24+
25+
26+
if __name__ == "__main__":
27+
main()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
4+
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
5+
##
6+
## SPDX-License-Identifier: AGPL-3.0-or-later
7+
8+
"""
9+
Safely print stdin or file to stdout with tweaks
10+
(trim trailing whitespace, ensure final newline).
11+
"""
12+
13+
from fileinput import input as file_input
14+
from sys import stdin, stdout, modules
15+
from stdisplay.stdisplay import stdisplay
16+
17+
18+
def main() -> None:
19+
"""
20+
main
21+
"""
22+
# https://github.com/pytest-dev/pytest/issues/4843
23+
if "pytest" not in modules:
24+
stdin.reconfigure(errors="ignore") # type: ignore
25+
26+
for line in file_input(encoding="ascii", errors="replace"):
27+
stdout.write(stdisplay(line).rstrip() + "\n")
28+
29+
stdout.flush()
30+
31+
32+
if __name__ == "__main__":
33+
main()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
3+
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
4+
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
5+
##
6+
## SPDX-License-Identifier: AGPL-3.0-or-later
7+
8+
"""Safely print argument to stdout with echo's formatting."""
9+
10+
from sys import argv, stdout
11+
from stdisplay.stdisplay import stdisplay
12+
13+
14+
def main() -> None:
15+
"""Safely print argument to stdout with echo's formatting."""
16+
if len(argv) > 1:
17+
untrusted_text = " ".join(argv[1:])
18+
stdout.write(stdisplay(untrusted_text))
19+
stdout.write("\n")
20+
stdout.flush()
21+
22+
23+
if __name__ == "__main__":
24+
main()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
3+
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
4+
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
5+
##
6+
## SPDX-License-Identifier: AGPL-3.0-or-later
7+
8+
"""Safely print argument to stdout."""
9+
10+
from sys import argv, stdout
11+
from stdisplay.stdisplay import stdisplay
12+
13+
14+
def main() -> None:
15+
"""Safely print argument to stdout."""
16+
if len(argv) > 1:
17+
untrusted_text = "".join(argv[1:])
18+
stdout.write(stdisplay(untrusted_text))
19+
stdout.flush()
20+
21+
22+
if __name__ == "__main__":
23+
main()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
## SPDX-FileCopyrightText: 2025 Benjamin Grande M. S. <[email protected]>
4+
## SPDX-FileCopyrightText: 2025 ENCRYPTED SUPPORT LLC <[email protected]>
5+
##
6+
## SPDX-License-Identifier: AGPL-3.0-or-later
7+
8+
"""Safely print stdin to stdout or file."""
9+
10+
from sys import argv, stdin, stdout, modules
11+
import shutil
12+
from tempfile import NamedTemporaryFile
13+
from stdisplay.stdisplay import stdisplay
14+
15+
16+
def main() -> None:
17+
"""Safely print stdin to stdout or file."""
18+
# https://github.com/pytest-dev/pytest/issues/4843
19+
if "pytest" not in modules:
20+
stdin.reconfigure(errors="ignore") # type: ignore
21+
untrusted_text_list = []
22+
for untrusted_text in stdin:
23+
untrusted_text_list.append(untrusted_text)
24+
if len(argv) == 1:
25+
stdout.write(stdisplay("".join(untrusted_text_list)))
26+
stdout.flush()
27+
else:
28+
with NamedTemporaryFile(mode="w", delete=False) as temp_file:
29+
temp_file.write(stdisplay("".join(untrusted_text_list)))
30+
temp_file.flush()
31+
for file in argv[1:]:
32+
shutil.copy2(temp_file.name, file)
33+
temp_file.close()
34+
35+
36+
if __name__ == "__main__":
37+
main()

0 commit comments

Comments
 (0)