From 3435d52bab9c04d8ee214f3958be3bccd6ec83d1 Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Mon, 26 Jun 2023 22:05:50 +0200 Subject: [PATCH] support/testing/tests/package/test_dos2unix.py: new runtime test Signed-off-by: Julien Olivain Signed-off-by: Thomas Petazzoni --- DEVELOPERS | 1 + .../testing/tests/package/test_dos2unix.py | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 support/testing/tests/package/test_dos2unix.py diff --git a/DEVELOPERS b/DEVELOPERS index 086e0478eb..c1819954ae 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1729,6 +1729,7 @@ F: support/testing/tests/package/sample_python_pyalsa.py F: support/testing/tests/package/sample_python_spake2.py F: support/testing/tests/package/test_ddrescue.py F: support/testing/tests/package/test_ddrescue/ +F: support/testing/tests/package/test_dos2unix.py F: support/testing/tests/package/test_gnupg2.py F: support/testing/tests/package/test_highway.py F: support/testing/tests/package/test_hwloc.py diff --git a/support/testing/tests/package/test_dos2unix.py b/support/testing/tests/package/test_dos2unix.py new file mode 100644 index 0000000000..af5850ae3e --- /dev/null +++ b/support/testing/tests/package/test_dos2unix.py @@ -0,0 +1,45 @@ +import os + +import infra.basetest + + +class TestDos2Unix(infra.basetest.BRTest): + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y + BR2_PACKAGE_DOS2UNIX=y + BR2_TARGET_ROOTFS_CPIO=y + # BR2_TARGET_ROOTFS_TAR is not set + """ + + def test_run(self): + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot(arch="armv5", + kernel="builtin", + options=["-initrd", cpio_file]) + self.emulator.login() + + # Check the program can run. This test also checks that we're + # using the real "dos2unix" rather than the applet provided in + # BusyBox, since the "--version" option is recognized by the + # real dos2unix and return an error in BusyBox. + self.assertRunOk("dos2unix --version") + + # Create a text file with UNIX new-lines + self.assertRunOk("echo -e 'Hello\\nBuildroot' > original.txt") + + # Convert the original UNIX file to DOS + self.assertRunOk("unix2dos -n original.txt dos.txt") + + # DOS file is expected to be different than the UNIX file + _, exit_code = self.emulator.run("cmp original.txt dos.txt") + self.assertNotEqual(exit_code, 0) + + # The "cat -A" command should print '^M$' for CR-LF + self.assertRunOk("cat -A dos.txt | grep -Fq '^M$'") + + # Convert back DOS file to UNIX + self.assertRunOk("dos2unix -n dos.txt unix.txt") + + # "unix.txt" should be identical to "original.txt" + self.assertRunOk("cmp original.txt unix.txt")