diff mbox series

[1/1] support/testing: add ed runtime test

Message ID 20240331201423.174954-1-ju.o@free.fr
State Accepted
Headers show
Series [1/1] support/testing: add ed runtime test | expand

Commit Message

Julien Olivain March 31, 2024, 8:14 p.m. UTC
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
 DEVELOPERS                               |  1 +
 support/testing/tests/package/test_ed.py | 98 ++++++++++++++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 support/testing/tests/package/test_ed.py

Comments

Yann E. MORIN April 1, 2024, 2:28 p.m. UTC | #1
Julien, All,

On 2024-03-31 22:14 +0200, Julien Olivain spake thusly:
> Signed-off-by: Julien Olivain <ju.o@free.fr>

Applied to master, thanks.

Regards,
Yann E. MORIN.

> ---
>  DEVELOPERS                               |  1 +
>  support/testing/tests/package/test_ed.py | 98 ++++++++++++++++++++++++
>  2 files changed, 99 insertions(+)
>  create mode 100644 support/testing/tests/package/test_ed.py
> 
> diff --git a/DEVELOPERS b/DEVELOPERS
> index 313fc16b9d7..288a3ce0e68 100644
> --- a/DEVELOPERS
> +++ b/DEVELOPERS
> @@ -1780,6 +1780,7 @@ F:	support/testing/tests/package/test_cryptsetup/
>  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_ed.py
>  F:	support/testing/tests/package/test_file.py
>  F:	support/testing/tests/package/test_file/
>  F:	support/testing/tests/package/test_fluidsynth.py
> diff --git a/support/testing/tests/package/test_ed.py b/support/testing/tests/package/test_ed.py
> new file mode 100644
> index 00000000000..eee5f8c4fc6
> --- /dev/null
> +++ b/support/testing/tests/package/test_ed.py
> @@ -0,0 +1,98 @@
> +import os
> +
> +import infra.basetest
> +
> +
> +class TestEd(infra.basetest.BRTest):
> +    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
> +        """
> +        BR2_PACKAGE_ED=y
> +        BR2_TARGET_ROOTFS_CPIO=y
> +        # BR2_TARGET_ROOTFS_TAR is not set
> +        """
> +
> +    def run_ed_cmds(self, ed_cmds):
> +        cmd = "ed <<EOF\n"
> +        cmd += "\n".join(ed_cmds)
> +        cmd += "\nEOF"
> +        self.assertRunOk(cmd)
> +
> +    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()
> +
> +        # We check the program can run. This also check we have the
> +        # actual GNU ed, rather than the Busybox ed, which does not
> +        # recognize the --version option.
> +        self.assertRunOk("ed --version")
> +
> +        test_fname = "test.txt"
> +        input_text_lines = [
> +            "Hello World",
> +            "Embedded Linux is Hard."
> +        ]
> +        output_expected_text = [
> +            "Hello Buildroot",
> +            "---------------",
> +            "Making Embedded Linux Easy."
> +        ]
> +
> +        # We define few "ed" command sequences, creating and editing a
> +        # text file. The final output of this sequence is expected to
> +        # match the expected text previously defined.
> +        create_file = ["a"]
> +        create_file += input_text_lines
> +        create_file += [
> +            ".",
> +            f"w {test_fname}",
> +            "q"
> +        ]
> +
> +        edit_file = [
> +            f"r {test_fname}",
> +            "1",
> +            "s/World/Buildroot/",
> +            "2",
> +            "s/is Hard/Easy/",
> +            "s/^/Making /",
> +            "w",
> +            "q"
> +        ]
> +
> +        insert_txt = [
> +            f"r {test_fname}",
> +            "2",
> +            "i",
> +            "This is a new line",
> +            ".",
> +            "w",
> +            "q"
> +        ]
> +
> +        change_txt = [
> +            f"r {test_fname}",
> +            "2",
> +            "c",
> +            "---------------",
> +            ".",
> +            "w"
> +            "q"
> +        ]
> +
> +        # We execute all "ed" command batches.
> +        ed_cmd_batches = [
> +            create_file,
> +            edit_file,
> +            insert_txt,
> +            change_txt
> +        ]
> +        for ed_cmd_batch in ed_cmd_batches:
> +            self.run_ed_cmds(ed_cmd_batch)
> +
> +        # The final test file should contain the expected text.
> +        out, ret = self.emulator.run(f"cat {test_fname}")
> +        self.assertEqual(ret, 0)
> +        self.assertEqual(out, output_expected_text)
> -- 
> 2.44.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Peter Korsgaard April 28, 2024, 7:42 p.m. UTC | #2
>>>>> "Julien" == Julien Olivain <ju.o@free.fr> writes:

 > Signed-off-by: Julien Olivain <ju.o@free.fr>

Committed to 2024.02.x, thanks.
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 313fc16b9d7..288a3ce0e68 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1780,6 +1780,7 @@  F:	support/testing/tests/package/test_cryptsetup/
 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_ed.py
 F:	support/testing/tests/package/test_file.py
 F:	support/testing/tests/package/test_file/
 F:	support/testing/tests/package/test_fluidsynth.py
diff --git a/support/testing/tests/package/test_ed.py b/support/testing/tests/package/test_ed.py
new file mode 100644
index 00000000000..eee5f8c4fc6
--- /dev/null
+++ b/support/testing/tests/package/test_ed.py
@@ -0,0 +1,98 @@ 
+import os
+
+import infra.basetest
+
+
+class TestEd(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_PACKAGE_ED=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def run_ed_cmds(self, ed_cmds):
+        cmd = "ed <<EOF\n"
+        cmd += "\n".join(ed_cmds)
+        cmd += "\nEOF"
+        self.assertRunOk(cmd)
+
+    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()
+
+        # We check the program can run. This also check we have the
+        # actual GNU ed, rather than the Busybox ed, which does not
+        # recognize the --version option.
+        self.assertRunOk("ed --version")
+
+        test_fname = "test.txt"
+        input_text_lines = [
+            "Hello World",
+            "Embedded Linux is Hard."
+        ]
+        output_expected_text = [
+            "Hello Buildroot",
+            "---------------",
+            "Making Embedded Linux Easy."
+        ]
+
+        # We define few "ed" command sequences, creating and editing a
+        # text file. The final output of this sequence is expected to
+        # match the expected text previously defined.
+        create_file = ["a"]
+        create_file += input_text_lines
+        create_file += [
+            ".",
+            f"w {test_fname}",
+            "q"
+        ]
+
+        edit_file = [
+            f"r {test_fname}",
+            "1",
+            "s/World/Buildroot/",
+            "2",
+            "s/is Hard/Easy/",
+            "s/^/Making /",
+            "w",
+            "q"
+        ]
+
+        insert_txt = [
+            f"r {test_fname}",
+            "2",
+            "i",
+            "This is a new line",
+            ".",
+            "w",
+            "q"
+        ]
+
+        change_txt = [
+            f"r {test_fname}",
+            "2",
+            "c",
+            "---------------",
+            ".",
+            "w"
+            "q"
+        ]
+
+        # We execute all "ed" command batches.
+        ed_cmd_batches = [
+            create_file,
+            edit_file,
+            insert_txt,
+            change_txt
+        ]
+        for ed_cmd_batch in ed_cmd_batches:
+            self.run_ed_cmds(ed_cmd_batch)
+
+        # The final test file should contain the expected text.
+        out, ret = self.emulator.run(f"cat {test_fname}")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out, output_expected_text)