Message ID | 20230308131554.642965-3-sebastian.weyer@smile.fr |
---|---|
State | Accepted |
Headers | show |
Series | [v6,1/3] package/nushell: new package | expand |
On Wed, 8 Mar 2023 14:15:53 +0100 Sebastian Weyer <sebastian.weyer@smile.fr> wrote: > +class TestNuBase(infra.basetest.BRTest): > + # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it doesn't > + # support a host rustc which is necessary for nushell > + config = \ > + """ > + BR2_arm=y > + BR2_cortex_a9=y > + BR2_ARM_ENABLE_NEON=y > + BR2_ARM_ENABLE_VFP=y > + BR2_TOOLCHAIN_EXTERNAL=y > + BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" > + BR2_SYSTEM_DHCP="eth0" > + BR2_PACKAGE_NUSHELL=y > + BR2_TARGET_ROOTFS_CPIO=y > + """ > + > + def login(self): > + img = os.path.join(self.builddir, "images", "rootfs.cpio") > + self.emulator.boot(arch="armv7", > + kernel="builtin", > + options=["-initrd",img]) > + self.emulator.login() > + > +# load a script on the target and check if it is executed correctly by nu > +class TestNu(TestNuBase): > + config_sample_scripts = \ > + """ > + BR2_ROOTFS_POST_BUILD_SCRIPT="{}" > + BR2_ROOTFS_POST_SCRIPT_ARGS="{}" > + """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"), > + "{sample_scripts}") > + > + #simple hello world script found in the nushell doc > + sample_scripts = ["tests/package/sample_nu.nu"] > + > + def __init__(self, names): > + """Add the scripts to the target in build time.""" > + super(TestNuBase, self).__init__(names) > + scripts = [infra.filepath(s) for s in self.sample_scripts] > + self.config += self.config_sample_scripts.format(sample_scripts=" ".join(scripts)) > + > + def check_sample_scripts_exist(self): > + """Check the scripts were really added to the image.""" > + scripts = [os.path.basename(s) for s in self.sample_scripts] > + cmd = "md5sum " + " ".join(scripts) > + _, exit_code = self.emulator.run(cmd) > + self.assertEqual(exit_code, 0) > + > + def run_sample_scripts(self): > + """Run each script previously added to the image.""" > + for script in self.sample_scripts: > + cmd = "nu " + os.path.basename(script) > + self.assertRunOk(cmd) > + > + def test_run(self): > + self.login() > + self.check_sample_scripts_exist() > + self.run_sample_scripts() This was way too complicated, because you based it on the Python testing infrastructure that aims at being generic. Here we don't need to be generic, so it can be as simple as: import os import infra.basetest class TestNu(infra.basetest.BRTest): # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it doesn't # support a host rustc which is necessary for nushell config = \ """ BR2_arm=y BR2_cortex_a9=y BR2_ARM_ENABLE_NEON=y BR2_ARM_ENABLE_VFP=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" BR2_SYSTEM_DHCP="eth0" BR2_PACKAGE_NUSHELL=y BR2_TARGET_ROOTFS_CPIO=y BR2_ROOTFS_POST_BUILD_SCRIPT="{}" BR2_ROOTFS_POST_SCRIPT_ARGS="{}" """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"), infra.filepath("tests/package/sample_nu.nu")) def test_run(self): img = os.path.join(self.builddir, "images", "rootfs.cpio") self.emulator.boot(arch="armv7", kernel="builtin", options=["-initrd", img]) self.emulator.login() cmd = "nu sample_nu.nu" self.assertRunOk(cmd) So I adjusted your patch like this and applied to next. Thanks a lot! Thomas
diff --git a/DEVELOPERS b/DEVELOPERS index 9e3855423e..9a7257c4b2 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -2552,6 +2552,8 @@ F: package/ripgrep/ N: Sebastian Weyer <sebastian.weyer@smile.fr> F: package/nushell/ +F: support/testing/tests/package/test_nu.py +F: support/testing/tests/package/sample_nu.nu N: Sébastien Szymanski <sebastien.szymanski@armadeus.com> F: package/mmc-utils/ diff --git a/support/testing/tests/package/sample_nu.nu b/support/testing/tests/package/sample_nu.nu new file mode 100644 index 0000000000..5287862cf1 --- /dev/null +++ b/support/testing/tests/package/sample_nu.nu @@ -0,0 +1,6 @@ +#! /usr/bin/nu +def greet [name] { + ["hello" $name] +} + +greet "world" diff --git a/support/testing/tests/package/test_nu.py b/support/testing/tests/package/test_nu.py new file mode 100644 index 0000000000..ba2ddb9851 --- /dev/null +++ b/support/testing/tests/package/test_nu.py @@ -0,0 +1,62 @@ +import os + +import infra.basetest + +class TestNuBase(infra.basetest.BRTest): + # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it doesn't + # support a host rustc which is necessary for nushell + config = \ + """ + BR2_arm=y + BR2_cortex_a9=y + BR2_ARM_ENABLE_NEON=y + BR2_ARM_ENABLE_VFP=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" + BR2_SYSTEM_DHCP="eth0" + BR2_PACKAGE_NUSHELL=y + BR2_TARGET_ROOTFS_CPIO=y + """ + + def login(self): + img = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot(arch="armv7", + kernel="builtin", + options=["-initrd",img]) + self.emulator.login() + +# load a script on the target and check if it is executed correctly by nu +class TestNu(TestNuBase): + config_sample_scripts = \ + """ + BR2_ROOTFS_POST_BUILD_SCRIPT="{}" + BR2_ROOTFS_POST_SCRIPT_ARGS="{}" + """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"), + "{sample_scripts}") + + #simple hello world script found in the nushell doc + sample_scripts = ["tests/package/sample_nu.nu"] + + def __init__(self, names): + """Add the scripts to the target in build time.""" + super(TestNuBase, self).__init__(names) + scripts = [infra.filepath(s) for s in self.sample_scripts] + self.config += self.config_sample_scripts.format(sample_scripts=" ".join(scripts)) + + def check_sample_scripts_exist(self): + """Check the scripts were really added to the image.""" + scripts = [os.path.basename(s) for s in self.sample_scripts] + cmd = "md5sum " + " ".join(scripts) + _, exit_code = self.emulator.run(cmd) + self.assertEqual(exit_code, 0) + + def run_sample_scripts(self): + """Run each script previously added to the image.""" + for script in self.sample_scripts: + cmd = "nu " + os.path.basename(script) + self.assertRunOk(cmd) + + def test_run(self): + self.login() + self.check_sample_scripts_exist() + self.run_sample_scripts()
Load sample script support/testing/tests/package/sample_nu.nu onto the target and verify proper execution by nushell Signed-off-by: Sebastian Weyer <sebastian.weyer@smile.fr> --- DEVELOPERS | 2 + support/testing/tests/package/sample_nu.nu | 6 +++ support/testing/tests/package/test_nu.py | 62 ++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 support/testing/tests/package/sample_nu.nu create mode 100644 support/testing/tests/package/test_nu.py