[gjs/esm/static-imports: 62/63] esm: Add basic static import tests.
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/esm/static-imports: 62/63] esm: Add basic static import tests.
- Date: Mon, 23 Nov 2020 21:04:43 +0000 (UTC)
commit 71c9795e88b69d92ce21616ac0d97aa6be0f21fa
Author: Evan Welsh <noreply evanwelsh com>
Date: Mon Jun 22 20:14:39 2020 -0500
esm: Add basic static import tests.
installed-tests/esm-test.sh | 25 ++++++++++++++++++
installed-tests/esm.test.in | 4 +++
installed-tests/esm/.eslintrc.yml | 5 ++++
installed-tests/esm/default-import.js | 3 +++
installed-tests/esm/default-import.js.output | 1 +
installed-tests/esm/exports.js | 3 +++
installed-tests/esm/gi-import.js | 3 +++
installed-tests/esm/gi-import.js.output | 1 +
installed-tests/esm/named-import.js | 3 +++
installed-tests/esm/named-import.js.output | 1 +
installed-tests/esm/system-import.js | 3 +++
installed-tests/esm/system-import.js.output | 3 +++
installed-tests/meson.build | 39 ++++++++++++++++++++++++++++
13 files changed, 94 insertions(+)
---
diff --git a/installed-tests/esm-test.sh b/installed-tests/esm-test.sh
new file mode 100755
index 00000000..f19b3657
--- /dev/null
+++ b/installed-tests/esm-test.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+if test "$GJS_USE_UNINSTALLED_FILES" = "1"; then
+ gjs="$TOP_BUILDDIR/gjs-console"
+else
+ gjs=gjs-console
+fi
+
+echo 1..1
+
+JS_SCRIPT="$1"
+EXPECTED_OUTPUT="$1.output"
+THE_DIFF=$("$gjs" -m "$JS_SCRIPT" \
+ | diff -u "$EXPECTED_OUTPUT" -)
+if test $? -ne 0; then
+ echo "not ok 1 - $1 # command failed"
+ exit 1
+fi
+
+if test -n "$THE_DIFF"; then
+ echo "not ok 1 - $1"
+ echo "$THE_DIFF" | while read line; do echo "#$line"; done
+else
+ echo "ok 1 - $1"
+fi
diff --git a/installed-tests/esm.test.in b/installed-tests/esm.test.in
new file mode 100644
index 00000000..763091fd
--- /dev/null
+++ b/installed-tests/esm.test.in
@@ -0,0 +1,4 @@
+[Test]
+Type=session
+Exec=@installed_tests_execdir@/esm-test.sh @installed_tests_execdir@/esm/@name@
+Output=TAP
diff --git a/installed-tests/esm/.eslintrc.yml b/installed-tests/esm/.eslintrc.yml
new file mode 100644
index 00000000..0b3bc0a2
--- /dev/null
+++ b/installed-tests/esm/.eslintrc.yml
@@ -0,0 +1,5 @@
+---
+extends: '../../.eslintrc.yml'
+parserOptions:
+ sourceType: 'module'
+ ecmaVersion: 2020
diff --git a/installed-tests/esm/default-import.js b/installed-tests/esm/default-import.js
new file mode 100644
index 00000000..f572ab57
--- /dev/null
+++ b/installed-tests/esm/default-import.js
@@ -0,0 +1,3 @@
+import $ from './exports.js';
+
+print($);
diff --git a/installed-tests/esm/default-import.js.output b/installed-tests/esm/default-import.js.output
new file mode 100644
index 00000000..7ed6ff82
--- /dev/null
+++ b/installed-tests/esm/default-import.js.output
@@ -0,0 +1 @@
+5
diff --git a/installed-tests/esm/exports.js b/installed-tests/esm/exports.js
new file mode 100644
index 00000000..c846291d
--- /dev/null
+++ b/installed-tests/esm/exports.js
@@ -0,0 +1,3 @@
+export default 5;
+
+export const NamedExport = 'Hello, World';
diff --git a/installed-tests/esm/gi-import.js b/installed-tests/esm/gi-import.js
new file mode 100644
index 00000000..734b1658
--- /dev/null
+++ b/installed-tests/esm/gi-import.js
@@ -0,0 +1,3 @@
+import gi from 'gi';
+
+print(gi.require('GObject'));
diff --git a/installed-tests/esm/gi-import.js.output b/installed-tests/esm/gi-import.js.output
new file mode 100644
index 00000000..12a2890d
--- /dev/null
+++ b/installed-tests/esm/gi-import.js.output
@@ -0,0 +1 @@
+[object GIRepositoryNamespace]
diff --git a/installed-tests/esm/named-import.js b/installed-tests/esm/named-import.js
new file mode 100644
index 00000000..73e3ea0f
--- /dev/null
+++ b/installed-tests/esm/named-import.js
@@ -0,0 +1,3 @@
+import {NamedExport} from './exports.js';
+
+print(NamedExport);
diff --git a/installed-tests/esm/named-import.js.output b/installed-tests/esm/named-import.js.output
new file mode 100644
index 00000000..3fa0d4b9
--- /dev/null
+++ b/installed-tests/esm/named-import.js.output
@@ -0,0 +1 @@
+Hello, World
diff --git a/installed-tests/esm/system-import.js b/installed-tests/esm/system-import.js
new file mode 100644
index 00000000..756c0725
--- /dev/null
+++ b/installed-tests/esm/system-import.js
@@ -0,0 +1,3 @@
+import system from 'system';
+
+print(system.exit);
diff --git a/installed-tests/esm/system-import.js.output b/installed-tests/esm/system-import.js.output
new file mode 100644
index 00000000..06e7382b
--- /dev/null
+++ b/installed-tests/esm/system-import.js.output
@@ -0,0 +1,3 @@
+function exit() {
+ [native code]
+}
diff --git a/installed-tests/meson.build b/installed-tests/meson.build
index 3d328b53..abf3213a 100644
--- a/installed-tests/meson.build
+++ b/installed-tests/meson.build
@@ -42,6 +42,45 @@ endforeach
subdir('js')
+# esm script tests #
+
+esm_tests = [
+ 'default-import',
+ 'named-import',
+ 'gi-import',
+ 'system-import'
+]
+
+esm_test_driver = find_program(files('esm-test.sh'))
+if get_option('installed_tests')
+ install_data('esm-test.sh', install_dir: installed_tests_execdir)
+endif
+
+foreach test : esm_tests
+ test_file = files('esm' / '@0@.js'.format(test))
+
+ test('@0@ command'.format(test), esm_test_driver,
+ args: test_file, env: tests_environment, protocol: 'tap',
+ suite: 'ESM')
+
+ test_description_subst = {
+ 'name': '@0@.js'.format(test),
+ 'installed_tests_execdir': installed_tests_execdir,
+ }
+ test_description = configure_file(configuration: test_description_subst,
+ input: 'esm.test.in',
+ output: '@0@.test'.format(test),
+ install: get_option('installed_tests'),
+ install_dir: installed_tests_metadir)
+
+ if get_option('installed_tests')
+ install_data(test_file, install_dir: installed_tests_execdir / 'esm')
+ install_data('esm' / '@0@.js'.format(test),
+ 'esm' / '@0@.js.output'.format(test),
+ install_dir: installed_tests_execdir / 'esm')
+ endif
+endforeach
+
# Debugger script tests #
debugger_tests = [
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]