From 93dd73600e91eb19e11f5ca57f9429a85cf0150f Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 24 Nov 2021 15:53:00 +0100 Subject: improve unit testing approach Unit tests were moved to their own subdirectory. Fixtures common to many unit tests were moved to test/unit/conftest.py. A facility to execute scripts in page's global scope was added. A workaround was employed to present information about errors in injected scripts. Sample unit tests for regexes in common/patterns.js were added. --- compute_scripts.awk | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'compute_scripts.awk') diff --git a/compute_scripts.awk b/compute_scripts.awk index 2bad3c5..1f3b11e 100644 --- a/compute_scripts.awk +++ b/compute_scripts.awk @@ -105,8 +105,7 @@ function print_exports_code(filename, i, count, export_name) { } } -function wrap_file(filename) { - print "\"use strict\";\n\n({fun: (function() {\n" +function partially_wrap_file(filename) { print_imports_code(filename) printf "\n\n" @@ -114,6 +113,13 @@ function wrap_file(filename) { printf "\n\n" print_exports_code(filename) +} + +function wrap_file(filename) { + print "\"use strict\";\n\n({fun: (function() {\n" + + partially_wrap_file(filename) + print "\n})}).fun();" } @@ -151,7 +157,7 @@ function compute_dependencies(filename, i, count, import_name, next_file) { } function print_usage() { - printf "usage: %2 compute_scripts.awk script_dependencies|wrapped_code FILENAME[...]\n", + printf "usage: %2 compute_scripts.awk script_dependencies|wrapped_code|partially_wrapped_code FILENAME[...]\n", ARGV[0] > "/dev/stderr" exit 1 } @@ -189,6 +195,8 @@ BEGIN { print("exports_init.js") if (compute_dependencies(root_filename) > 0) exit 1 + } else if (operation == "partially_wrapped_code") { + partially_wrap_file(root_filename) } else if (operation == "wrapped_code") { wrap_file(root_filename) } else { -- cgit v1.2.3