tebako 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/CMakeLists.txt +694 -0
  3. data/Gemfile +35 -0
  4. data/README.adoc +389 -0
  5. data/Rakefile +33 -0
  6. data/bin/console +15 -0
  7. data/bin/setup +8 -0
  8. data/cmake/copy_dir.cmake +29 -0
  9. data/cmake/def_tty_colours.cmake +19 -0
  10. data/common.env +6 -0
  11. data/exe/tebako +31 -0
  12. data/include/tebako/tebako-fs.h +40 -0
  13. data/include/tebako/tebako-main.h +40 -0
  14. data/lib/cli.rb +28 -0
  15. data/lib/tebako/cli.rb +137 -0
  16. data/lib/tebako/cli_helpers.rb +147 -0
  17. data/lib/tebako/error.rb +39 -0
  18. data/lib/tebako/packager/pass1.rb +155 -0
  19. data/lib/tebako/packager/pass2.rb +374 -0
  20. data/lib/tebako/packager.rb +210 -0
  21. data/lib/tebako/version.rb +30 -0
  22. data/resources/tebako-fs.cpp.in +37 -0
  23. data/resources/tebako-version.h.in +37 -0
  24. data/src/tebako-main.cpp +188 -0
  25. data/tebako.gemspec +63 -0
  26. data/tests/scripts/cross-tests.sh +34 -0
  27. data/tests/scripts/functional-tests.sh +335 -0
  28. data/tests/test-00/test.rb +4 -0
  29. data/tests/test-01/tebako-test-run.rb +5 -0
  30. data/tests/test-09/tebako-test-0.0.1.gem +0 -0
  31. data/tests/test-11/bin/tebako-test-run.rb +10 -0
  32. data/tests/test-11/lib/tebako-test.rb +20 -0
  33. data/tests/test-11/tebako-test.gemspec +15 -0
  34. data/tests/test-12/tebako-test-a.gemspec +15 -0
  35. data/tests/test-12/tebako-test-b.gemspec +15 -0
  36. data/tests/test-13/bin/tebako-test-run.rb +10 -0
  37. data/tests/test-13/lib/tebako-test.rb +20 -0
  38. data/tests/test-13/tebako-test.gemspec +15 -0
  39. data/tests/test-15/Gemfile +8 -0
  40. data/tests/test-15/Rakefile +4 -0
  41. data/tests/test-15/bin/tebako-test-run.rb +10 -0
  42. data/tests/test-15/lib/tebako/bundle/test/version.rb +9 -0
  43. data/tests/test-15/lib/tebako/bundle/test.rb +29 -0
  44. data/tests/test-15/tebako-bundle-test.gemspec +30 -0
  45. data/tests/test-16/Gemfile +8 -0
  46. data/tests/test-16/Rakefile +4 -0
  47. data/tests/test-16/bin/tebako-test-run.rb +10 -0
  48. data/tests/test-16/lib/tebako/bundle/test/version.rb +9 -0
  49. data/tests/test-16/lib/tebako/bundle/test.rb +29 -0
  50. data/tests/test-16/tebako-bundle-test.gemspec +24 -0
  51. data/tests/test-18/Gemfile +5 -0
  52. data/tests/test-18/tebako-test-run.rb +12 -0
  53. data/tests/test-19/Gemfile +6 -0
  54. data/tests/test-19/tebako-test-run.rb +11 -0
  55. data/tests-2/fixtures/gems-bundler/Gemfile +4 -0
  56. data/tests-2/fixtures/gems-bundler/gems-bundler.rb +34 -0
  57. data/tests-2/fixtures/gems-byebug/Gemfile +5 -0
  58. data/tests-2/fixtures/gems-byebug/gems-byebug.rb +31 -0
  59. data/tests-2/fixtures/gems-expressir/Gemfile +7 -0
  60. data/tests-2/fixtures/gems-expressir/gems-expressir.rb +33 -0
  61. data/tests-2/fixtures/gems-libmspack/Gemfile +5 -0
  62. data/tests-2/fixtures/gems-libmspack/gems-libmspack.rb +91 -0
  63. data/tests-2/fixtures/gems-sassc/Gemfile +6 -0
  64. data/tests-2/fixtures/gems-sassc/base_style/all.scss +1 -0
  65. data/tests-2/fixtures/gems-sassc/base_style/reset.scss +100 -0
  66. data/tests-2/fixtures/gems-sassc/gems-sassc.rb +129 -0
  67. data/tests-2/fixtures/gems-seven-zip/Gemfile +7 -0
  68. data/tests-2/fixtures/gems-seven-zip/gems-seven-zip.rb +53 -0
  69. data/tests-2/fixtures/launcher-coreincl/launcher-coreincl.rb +29 -0
  70. data/tests-2/fixtures/launcher-package/launcher-package.rb +29 -0
  71. data/tests-2/fixtures/launcher-pwd/launcher-pwd.rb +28 -0
  72. data/tests-2/fixtures/launcher-stdinredir/input.txt +1 -0
  73. data/tests-2/fixtures/launcher-stdinredir/launcher-stdinredir.rb +31 -0
  74. data/tests-2/fixtures/launcher-stdoutredir/launcher-stdoutredir.rb +28 -0
  75. data/tests-2/fixtures/patches-dir/level-1/level-2/file-1.txt +1 -0
  76. data/tests-2/fixtures/patches-dir/level-1/level-2/file-2.txt +1 -0
  77. data/tests-2/fixtures/patches-dir/level-1/level-2/file-3.txt +1 -0
  78. data/tests-2/fixtures/patches-dir/patches-dir.rb +154 -0
  79. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-1.txt +1 -0
  80. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-2.txt +2 -0
  81. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-3.txt +1 -0
  82. data/tests-2/fixtures/patches-io-and-file/level-1/link-3 +1 -0
  83. data/tests-2/fixtures/patches-io-and-file/patches-io-and-file.rb +87 -0
  84. data/tests-2/fixtures/patches-main/patches-main.rb +6 -0
  85. data/tests-2/tebako-test.rb +312 -0
  86. metadata +170 -0
@@ -0,0 +1,188 @@
1
+ /**
2
+ *
3
+ * Copyright (c) 2021-2022 [Ribose Inc](https://www.ribose.com).
4
+ * All rights reserved.
5
+ * This file is a part of tebako
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions
9
+ * are met:
10
+ * 1. Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * 2. Redistributions in binary form must reproduce the above copyright
13
+ * notice, this list of conditions and the following disclaimer in the
14
+ * documentation and/or other materials provided with the distribution.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
20
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ * POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ */
29
+
30
+ #include <stdlib.h>
31
+ #include <stdio.h>
32
+ #include <string.h>
33
+ #include <memory.h>
34
+ #include <sys/stat.h>
35
+ #include <fcntl.h>
36
+
37
+ #include <string>
38
+
39
+ #ifdef _WIN32
40
+ #include <winsock2.h>
41
+ #include <windows.h>
42
+ #endif
43
+
44
+
45
+ #include <tebako/tebako-config.h>
46
+ #include <tebako/tebako-io.h>
47
+
48
+ #include <tebako/tebako-version.h>
49
+ #include <tebako/tebako-main.h>
50
+ #include <tebako/tebako-fs.h>
51
+
52
+ extern "C" int tebako_main(int* argc, char*** argv) {
53
+ int ret = -1, fsret = -1;
54
+ char** new_argv = NULL;
55
+ char* argv_memory = NULL;
56
+
57
+ if (strstr((*argv)[0], "miniruby") != NULL) {
58
+ // Ruby build script is designed in such a way that this patch is also applied towards miniruby
59
+ // Just pass through in such case
60
+ ret = 0;
61
+ }
62
+ else {
63
+ try {
64
+ fsret = load_fs(&gfsData[0],
65
+ gfsSize,
66
+ tebako::fs_log_level,
67
+ NULL /* cachesize*/,
68
+ NULL /* workers */,
69
+ NULL /* mlock */,
70
+ NULL /* decompress_ratio*/,
71
+ NULL /* image_offset */
72
+ );
73
+
74
+ if (fsret == 0) {
75
+ if ((*argc > 1) && strcmp((*argv)[1], "--tebako-extract")==0) {
76
+ // ruby -e "require 'fileutils'; FileUtils.copy_entry '<tebako::fs_mount_point>',argv[2] || 'source_filesystem'"
77
+ std::string dest = std::string(((*argc) < 3 ? "source_filesystem" : (*argv)[2]));
78
+ std::string cmd = std::string("require 'fileutils'; FileUtils.copy_entry '") + (tebako::fs_mount_point) + "', '" + dest + "'";
79
+ printf("Extracting tebako image to '%s' \n", dest.c_str());
80
+ size_t new_argv_size = 3 + cmd.size() + 1 + strlen((*argv)[0]) + 1;
81
+ char** new_argv = new char* [3];
82
+ char* argv_memory = new char[new_argv_size];
83
+ if (new_argv != NULL && argv_memory != NULL) {
84
+ strcpy(argv_memory, (*argv)[0]);
85
+ new_argv[0] = argv_memory;
86
+ argv_memory += (strlen((*argv)[0]) + 1);
87
+ strcpy(argv_memory, "-e");
88
+ new_argv[1] = argv_memory;
89
+ argv_memory += 3;
90
+ strcpy(argv_memory, cmd.c_str());
91
+ new_argv[2] = argv_memory;
92
+ ret = 0;
93
+ *argv = new_argv;
94
+ (*argc) = 3;
95
+ }
96
+ }
97
+ else {
98
+ size_t new_argv_size = strlen(tebako::fs_mount_point) + strlen(tebako::fs_entry_point) + 1;
99
+ for (int i = 0; i < (*argc); i++) {
100
+ new_argv_size += (strlen((*argv)[i]) + 1);
101
+ }
102
+ /* argv memory should be adjacent */
103
+ char** new_argv = new char* [(*argc) + 1];
104
+ char* argv_memory = new char[new_argv_size];
105
+ if (new_argv != NULL && argv_memory != NULL) {
106
+ memcpy(argv_memory, (*argv)[0], strlen((*argv)[0]) + 1);
107
+ new_argv[0] = argv_memory;
108
+ argv_memory += (strlen((*argv)[0]) + 1);
109
+ memcpy(argv_memory, tebako::fs_mount_point, strlen(tebako::fs_mount_point));
110
+ new_argv[1] = argv_memory;
111
+ argv_memory += strlen(tebako::fs_mount_point);
112
+ memcpy(argv_memory, tebako::fs_entry_point, strlen(tebako::fs_entry_point) + 1);
113
+ argv_memory += (strlen(tebako::fs_entry_point) + 1);
114
+ for (int i = 1; i < (*argc); i++) {
115
+ memcpy(argv_memory, (*argv)[i], strlen((*argv)[i]) + 1);
116
+ new_argv[i+1] = argv_memory;
117
+ argv_memory += (strlen((*argv)[i]) + 1);
118
+ }
119
+ *argv = new_argv;
120
+ (*argc) += 1;
121
+ ret = 0;
122
+ }
123
+ }
124
+ atexit(drop_fs);
125
+ }
126
+ }
127
+ catch (...) {
128
+
129
+ }
130
+
131
+ if (ret != 0) {
132
+ try {
133
+ printf("Tebako initialization failed\n");
134
+ if (new_argv) delete new_argv;
135
+ if (argv_memory) delete argv_memory;
136
+ if (fsret == 0) {
137
+ drop_fs();
138
+ }
139
+ }
140
+ catch (...) {
141
+ // Nested error, no recovery :(
142
+ }
143
+ }
144
+ }
145
+ return ret;
146
+ }
147
+
148
+ extern "C" const char* tebako_mount_point(void) {
149
+ return tebako::fs_mount_point;
150
+ }
151
+
152
+ #ifdef RB_W32
153
+
154
+ #if !defined(RUBY_WIN32_H)
155
+ struct stati128 {
156
+ _dev_t st_dev;
157
+ unsigned __int64 st_ino;
158
+ __int64 st_inohigh;
159
+ unsigned short st_mode;
160
+ short st_nlink;
161
+ short st_uid;
162
+ short st_gid;
163
+ _dev_t st_rdev;
164
+ __int64 st_size;
165
+ __time64_t st_atime;
166
+ long st_atimensec;
167
+ __time64_t st_mtime;
168
+ long st_mtimensec;
169
+ __time64_t st_ctime;
170
+ long st_ctimensec;
171
+ };
172
+ #endif
173
+
174
+ extern "C" int tebako_file_load_ok(const char *path) {
175
+ int ret = 0;
176
+
177
+ if (within_tebako_memfs(path)) {
178
+ int fd = tebako_open(2, path, O_RDONLY);
179
+ if (fd != -1) {
180
+ struct STAT_TYPE st;
181
+ ret = (tebako_fstat(fd, &st)==0) ? 1:0;
182
+ tebako_close(fd);
183
+ }
184
+ }
185
+ return ret;
186
+ }
187
+
188
+ #endif
data/tebako.gemspec ADDED
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2023 [Ribose Inc](https://www.ribose.com).
4
+ # All rights reserved.
5
+ # This file is a part of tebako
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions
9
+ # are met:
10
+ # 1. Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ # 2. Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
20
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ # POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ require_relative "lib/tebako/version"
29
+
30
+ Gem::Specification.new do |spec|
31
+ spec.name = "tebako"
32
+ spec.version = Tebako::VERSION
33
+ spec.authors = ["Ribose Inc."]
34
+ spec.email = ["open.source@ribose.com"]
35
+ spec.license = "BSD-2-Clause"
36
+
37
+ spec.summary = "Packager for Ruby executables"
38
+ spec.description = <<~SUM
39
+ Tebako is an executable packager. It packages a set of files into a single
40
+ executable binary that allows a user to run a selected file from the
41
+ packaged software as if it is a mounted filesystem.
42
+ SUM
43
+ spec.homepage = "https://github.com/tamatebako/tebako"
44
+ spec.required_ruby_version = ">= 2.7.0"
45
+
46
+ spec.metadata["homepage_uri"] = spec.homepage
47
+ spec.metadata["source_code_uri"] = "https://github.com/tamatebako/tebako"
48
+
49
+ # Specify which files should be added to the gem when it is released.
50
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
51
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
52
+ `git ls-files --recurse-submodules -z`.split("\x0").reject do |f|
53
+ (f == __FILE__) ||
54
+ f.match(%r{\A(?:(?:test|spec|features|deps|output|common\.env)/|\.(?:git|cirrus|tebako|rubocop))})
55
+ end
56
+ end
57
+ spec.bindir = "exe"
58
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
59
+ spec.require_paths = %w[cmake exe ext include lib resources src tools/ci-scripts tools/cmake-scripts tools/includes]
60
+
61
+ spec.add_dependency "thor", "~> 1.2"
62
+ spec.add_dependency "yaml", "~> 0.2.1"
63
+ end
@@ -0,0 +1,34 @@
1
+ #! /bin/bash
2
+ #
3
+ # Copyright (c) 2021, [Ribose Inc](https://www.ribose.com).
4
+ # All rights reserved.
5
+ # This file is a part of tebako
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions
9
+ # are met:
10
+ # 1. Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ # 2. Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
20
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ # POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ # More safety, by turning some bugs into errors.
29
+ # Without `errexit` you don’t need ! and can replace
30
+ # PIPESTATUS with a simple $?
31
+ set -o errexit -o pipefail -o noclobber -o nounset
32
+
33
+ chmod +x test-*-package
34
+ for TP in test-*-package; do "./$TP"; done
@@ -0,0 +1,335 @@
1
+ #! /bin/bash
2
+ #
3
+ # Copyright (c) 2021, [Ribose Inc](https://www.ribose.com).
4
+ # All rights reserved.
5
+ # This file is a part of tebako
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions
9
+ # are met:
10
+ # 1. Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ # 2. Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
20
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ # POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ # ......................................................................
29
+ # Helper functions
30
+ press_runner() {
31
+ # Runs 'tabako press'
32
+ # Parameters:
33
+ # $1 -- project root
34
+ # $2 -- entry point
35
+ # $3 -- tebako package name
36
+ if [ "${VERBOSE}" == "yes" ]; then
37
+ "$DIR_BIN"/tebako press -R "$RUBY_VER" --root="$1" --entry-point="$2" --output="$3" 2>&1 | tee tebako_test.log
38
+ assertEquals 0 "${PIPESTATUS[0]}"
39
+ result="$( cat tebako_test.log )"
40
+ else
41
+ result=$( "$DIR_BIN"/tebako press -R "$RUBY_VER" --root="$1" --entry-point="$2" --output="$3" 2>&1 )
42
+ assertEquals 0 $?
43
+ fi
44
+
45
+ # Check the first and the last messages expected from CMake script
46
+ assertContains "$result" "Running tebako press script"
47
+ assertContains "$result" "packaging has completed"
48
+ }
49
+
50
+ package_runner() {
51
+ # Runs a package built by tebako
52
+ # Parameters:
53
+ # $1 -- file name
54
+ # $2 -- expected output
55
+ if [ "${VERBOSE}" == "yes" ]; then
56
+ $1 | tee tebako_test.log
57
+ assertEquals 0 "${PIPESTATUS[0]}"
58
+ result="$( cat tebako_test.log )"
59
+ else
60
+ result="$( $1 )"
61
+ assertEquals 0 $?
62
+ fi
63
+
64
+ assertContains "$result" "$2"
65
+ }
66
+
67
+ press_runner_with_error() {
68
+ # Runs 'tabako press' expecting failure
69
+ # Parameters:
70
+ # $1 -- project root
71
+ # $2 -- entry point
72
+ # $3 -- tebako package name
73
+ # $4 -- expected error code
74
+ # $5 -- expected error message
75
+ if [ "${VERBOSE}" == "yes" ]; then
76
+ "$DIR_BIN"/tebako press -R "$RUBY_VER" --root="$1" --entry-point="$2" --output="$3" 2>&1 | tee tebako_test.log
77
+ assertEquals "$4" "${PIPESTATUS[0]}"
78
+ result="$( cat tebako_test.log )"
79
+ else
80
+ result=$( "$DIR_BIN"/tebako press -R "$RUBY_VER" --root="$1" --entry-point="$2" --output="$3" 2>&1 )
81
+ assertEquals "$4" "${PIPESTATUS[0]}"
82
+ fi
83
+
84
+ assertContains "$result" "Running tebako press script"
85
+ assertContains "$result" "$5"
86
+ }
87
+
88
+ # ......................................................................
89
+ # Tests
90
+ # 00. Basic tebako CLI tests (error handling)
91
+ # -- tebako setup [commented out, redundant]
92
+ # AU. Check that it is possible to extract image content (--tebako-extract option)
93
+ # 01. Simple Ruby script, absolute path to root, relative path to entry point
94
+ # 02. Simple Ruby script, absolute path to root, relative path to entry point, entry point does not exist [Expected error at build step]
95
+ # 03. Simple Ruby script, absolute path to root, absolute path to entry point
96
+ # 04. Simple Ruby script, relative path to root, relative path to entry point
97
+ # 05. Simple Ruby script, absolute path to root absolute path to entry point, entry point not within root [Expected error at configure step]
98
+ # 09. Ruby gem (xxx.gem, no gemspec, no gemfile)
99
+ # 10. Ruby gem (xxx.gem, no gemspec, no gemfile), entry point does not exist [Expected error at build step]
100
+ # 11. Ruby gem (no gemfile, with gemspec)
101
+ # 12. Ruby gem (no gemfile, with gemspec), multiple gemspecs [Expected error at configure step]
102
+ # 13. Ruby gem (no gemfile, with gemspec), gemspec error [Expected error at build step]
103
+ # 14. Ruby gem (no gemfile, with gemspec), entry point does not exist [Expected error at build step]
104
+ # 15. Ruby gem (with gemspec, with gemfile)
105
+ # 16. Ruby gem (with gemspec, with gemfile), gemfile with error [Expected error at build step]
106
+ # 17. Ruby gem (with gemspec, with gemfile), entry point does not exist [Expected error at build step]
107
+ # 18. Ruby project (no gemspec, with gemfile)
108
+ # 19. Ruby project (no gemspec, with gemfile, with native extension)
109
+
110
+ # ......................................................................
111
+ # 00. Very basic tebako CLI tests (error handling)
112
+ test_CLI_help() {
113
+ result=$( "$DIR_BIN"/tebako help )
114
+
115
+ assertEquals 0 "${PIPESTATUS[0]}"
116
+ assertContains "$result" "Tebako commands:"
117
+ }
118
+
119
+ test_CLI_missing_command() {
120
+ result=$( "$DIR_BIN"/tebako )
121
+
122
+ assertEquals 0 "${PIPESTATUS[0]}"
123
+ assertContains "$result" "Tebako commands:"
124
+ }
125
+
126
+ test_CLI_unknown_command() {
127
+ result=$( "$DIR_BIN"/tebako jump 2>&1)
128
+
129
+ assertEquals 1 "${PIPESTATUS[0]}"
130
+ assertContains "$result" "Could not find command"
131
+ }
132
+
133
+ test_CLI_no_root() {
134
+ result=$( "$DIR_BIN"/tebako press -R "$RUBY_VER" --entry-point=tebako-test-run.rb --output=test-00-package 2>&1 )
135
+
136
+ assertEquals 1 "${PIPESTATUS[0]}"
137
+ assertContains "$result" "No value provided for required options '--root'"
138
+ }
139
+
140
+ test_CLI_no_entry_point() {
141
+ result=$( "$DIR_BIN"/tebako press -R "$RUBY_VER" --root=tests/test-00 --output=test-00-package 2>&1 )
142
+
143
+ assertEquals 1 "${PIPESTATUS[0]}"
144
+ assertContains "$result" "No value provided for required options '--entry-point'"
145
+ }
146
+
147
+ test_CLI_invalid_Ruby_version() {
148
+ result=$( "$DIR_BIN"/tebako press --root=tests/test-00 --output=test-00-package --entry-point=tebako-test-run.rb --Ruby=1.9.3 2>&1 )
149
+
150
+ assertEquals 1 "${PIPESTATUS[0]}"
151
+ assertContains "$result" "Expected '--Ruby' to be one of"
152
+ }
153
+
154
+
155
+ # ......................................................................
156
+ # -- tebako setup
157
+ #test_tebako_setup() {
158
+ # echo "tebako setup ... patience, please, it may take up to 1 hour."
159
+ # if [ "${VERBOSE}" == "yes" ]; then
160
+ # "$DIR_BIN"/tebako setup -R "$RUBY_VER" 2>&1 | tee tebako_test.log
161
+ # assertEquals 0 "${PIPESTATUS[0]}"
162
+ # result="$( cat tebako_test.log )"
163
+ # else
164
+ # result=$( "$DIR_BIN"/tebako setup -R "$RUBY_VER" 2>&1 )
165
+ # assertEquals 0 "${PIPESTATUS[0]}"
166
+ # fi
167
+
168
+ # Check the first and the last messages expected from CMake script
169
+ # assertContains "$result" "Running tebako setup script"
170
+ # assertContains "$result" "Tebako setup has completed"
171
+ #}
172
+
173
+ # ......................................................................
174
+ # AU. Check that it is possible to extract image content (--tebako-extract option)
175
+ test_AUC_extract() {
176
+ echo "==> Check --tebako-extract option"
177
+ result=$( "$DIR_BIN"/tebako press -R "$RUBY_VER" --root=tests/test-01 --entry=tebako-test-run.rb --output=test-AUC-package 2>&1 )
178
+
179
+ assertEquals 0 "${PIPESTATUS[0]}"
180
+ assertContains "$result" "Running tebako press script"
181
+ assertContains "$result" "packaging has completed"
182
+
183
+ ./test-AUC-package --tebako-extract
184
+ assertEquals 0 "${PIPESTATUS[0]}"
185
+
186
+ diff -r source_filesystem output/source_filesystem
187
+ assertEquals 0 "${PIPESTATUS[0]}"
188
+
189
+ rm -rf source_filesystem
190
+
191
+ ./test-AUC-package --tebako-extract extract
192
+ assertEquals 0 "${PIPESTATUS[0]}"
193
+
194
+ diff -r extract output/source_filesystem
195
+ assertEquals 0 "${PIPESTATUS[0]}"
196
+
197
+ rm -rf extract
198
+ }
199
+
200
+ # ......................................................................
201
+ # 01. Simple Ruby script, absolute path to root, relative path to entry point
202
+ test_tebako_press_01() {
203
+ echo "==> simple Ruby script, absolute path to root, relative path to entry point"
204
+ press_runner "${DIR_TESTS}/test-01" "tebako-test-run.rb" "test-01-package"
205
+ package_runner "./test-01-package" "Hello! This is test-1 talking from inside DwarFS"
206
+ }
207
+
208
+ # ......................................................................
209
+ # 02. Simple Ruby script, absolute path to root, relative path to entry point, entry point does not exist
210
+ test_tebako_press_02() {
211
+ echo "==> simple Ruby script, absolute path to root, relative path to entry point, entry point does not exist"
212
+ press_runner_with_error "${DIR_TESTS}/test-01" "test-does-not-exist.rb" "test-02-package" 104 "'tebako press' build step failed"
213
+ }
214
+
215
+ # ......................................................................
216
+ # 03. Simple Ruby script, absolute path to root, absolute path to entry point
217
+ test_tebako_press_03() {
218
+ echo "==> simple Ruby script, absolute path to root, absolute path to entry point"
219
+ press_runner "${DIR_TESTS}/test-01" "${DIR_TESTS}/test-01/tebako-test-run.rb" "test-03-package"
220
+ package_runner "./test-03-package" "Hello! This is test-1 talking from inside DwarFS"
221
+ }
222
+
223
+ # ......................................................................
224
+ # 04. Simple Ruby script, relative path to root, relative path to entry point
225
+ test_tebako_press_04() {
226
+ echo "==> simple Ruby script, relative path to root, relative path to entry point"
227
+ pushd "${DIR_ROOT}" > /dev/null || fail "pushd ${DIR_ROOT} failed"
228
+ press_runner "tests/test-01" "tebako-test-run.rb" "test-04-package"
229
+ package_runner "./test-04-package" "Hello! This is test-1 talking from inside DwarFS"
230
+ popd > /dev/null || fail "popd failed"
231
+ }
232
+
233
+ # ......................................................................
234
+ # 05. Simple Ruby script, absolute path to root absolute path to entry point, entry point not within root
235
+ test_tebako_press_05() {
236
+ echo "==> simple Ruby script, absolute path to root absolute path to entry point, not within root"
237
+ press_runner_with_error "${DIR_TESTS}/test-01" "${DIR_TESTS}/test-00/test.rb" "test-05-package" 103 "'tebako press' configure step failed"
238
+ }
239
+
240
+ # ......................................................................
241
+ # 09. Ruby gem (xxx.gem, no gemspec, no gemfile)
242
+ test_tebako_press_09() {
243
+ echo "==> Ruby gem (xxx.gem, no gemspec, no gemfile)"
244
+ press_runner "${DIR_TESTS}/test-09" "tebako-test-run.rb" "test-09-package"
245
+ package_runner "./test-09-package" "| a1 | b1 |"
246
+ }
247
+
248
+ # ......................................................................
249
+ # 10. Ruby gem (xxx.gem, no gemspec, no gemfile), entry point does not exist
250
+ test_tebako_press_10() {
251
+ echo "==> Ruby gem (xxx.gem, no gemspec, no gemfile), entry point does not exist"
252
+ press_runner_with_error "${DIR_TESTS}/test-09" "test-does-not-exist.rb" "test-10-package" 104 "'tebako press' build step failed"
253
+ }
254
+
255
+ # ......................................................................
256
+ # 11. Ruby gem (no gemfile, with gemspec)
257
+ test_tebako_press_11() {
258
+ echo "==> Ruby gem (no gemfile, with gemspec)"
259
+ press_runner "${DIR_TESTS}/test-11" "tebako-test-run.rb" "test-11-package"
260
+ package_runner "./test-11-package" "| a1 | b1 |"
261
+ }
262
+
263
+ # ......................................................................
264
+ # 12. Ruby gem (no gemfile, with gemspec), multiple gemspecs
265
+ test_tebako_press_12() {
266
+ echo "==> Ruby gem (no gemfile, with gemspec), multiple gemspecs"
267
+ press_runner_with_error "${DIR_TESTS}/test-12" "tebako-test-run.rb" "test-12-package" 103 "'tebako press' configure step failed"
268
+ }
269
+
270
+ # ......................................................................
271
+ # 13. Ruby gem (no gemfile, with gemspec), gemspec error
272
+ test_tebako_press_13() {
273
+ echo "==> Ruby gem (no gemfile, with gemspec), gemspec error"
274
+ press_runner_with_error "${DIR_TESTS}/test-13" "tebako-test-run.rb" "test-13-package" 104 "'tebako press' build step failed"
275
+ }
276
+
277
+ # ......................................................................
278
+ # 14. Ruby gem (no gemfile, with gemspec), entry point does not exist
279
+ test_tebako_press_14() {
280
+ echo "==> Ruby gem (no gemfile, with gemspec), entry point does not exist"
281
+ press_runner_with_error "${DIR_TESTS}/test-14" "test-does-not-exist.rb" "test-14-package" 104 "'tebako press' build step failed"
282
+ }
283
+
284
+ # ......................................................................
285
+ # 15. Ruby gem (with gemspec, with gemfile)
286
+ test_tebako_press_15() {
287
+ echo "==> Ruby gem (with gemspec, with gemfile)"
288
+ press_runner "${DIR_TESTS}/test-15" "tebako-test-run.rb" "test-15-package"
289
+ package_runner "./test-15-package" "| a1 | b1 |"
290
+ }
291
+
292
+ # ......................................................................
293
+ # 16. Ruby gem (with gemspec, with gemfile), gemfile with error
294
+ test_tebako_press_16() {
295
+ echo "==> Ruby gem (with gemspec, with gemfile), gemfile with error"
296
+ press_runner_with_error "${DIR_TESTS}/test-16" "tebako-test-run.rb" "test-16-package" 104 "'tebako press' build step failed"
297
+ }
298
+
299
+ # ......................................................................
300
+ # 17. Ruby gem (with gemspec, with gemfile), entry point dows not exist
301
+ test_tebako_press_17() {
302
+ echo "==> Ruby gem (with gemspec, with gemfile), entry point does not exist"
303
+ press_runner_with_error "${DIR_TESTS}/test-15" "test-does-not-exist.rb" "test-17-package" 104 "'tebako press' build step failed"
304
+ }
305
+
306
+ # ......................................................................
307
+ # 18. Ruby project (no gemspec, with gemfile)
308
+ test_tebako_press_18() {
309
+ echo "==> Ruby project (no gemspec, with gemfile)"
310
+ press_runner "${DIR_TESTS}/test-18" "tebako-test-run.rb" "test-18-package"
311
+ package_runner "./test-18-package" "| a1 | b1 |"
312
+ }
313
+
314
+ # ......................................................................
315
+ # 19. Ruby project (no gemspec, with gemfile, with native extension)
316
+ test_tebako_press_19() {
317
+ if [[ "$OSTYPE" != "msys" ]]; then
318
+ echo "==> Ruby project (no gemspec, with gemfile, with native extension)"
319
+ press_runner "${DIR_TESTS}/test-19" "tebako-test-run.rb" "test-19-package"
320
+ package_runner "./test-19-package" "Hello, World via libc puts using FFI on tebako package"
321
+ fi
322
+ }
323
+
324
+ # ......................................................................
325
+ # main
326
+
327
+ DIR0=$( dirname "$0" )
328
+ DIR_ROOT=$( cd "$DIR0"/../.. && pwd )
329
+ DIR_BIN=$( cd "$DIR_ROOT"/exe && pwd )
330
+ DIR_TESTS=$( cd "$DIR_ROOT"/tests && pwd )
331
+ RUBY_VER=${RUBY_VER:-3.0.6}
332
+
333
+ echo "Running tebako tests"
334
+ # shellcheck source=/dev/null
335
+ . "$DIR_TESTS/shunit2/shunit2"
@@ -0,0 +1,4 @@
1
+ #!/home/tebako/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ puts "Hello! This is test-1 talking from inside DwarFS"
@@ -0,0 +1,5 @@
1
+ #!/home/tebako/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ puts "Hello! This is test-1 talking from inside DwarFS"
5
+ puts "Gem path: #{Gem.path}"
Binary file
@@ -0,0 +1,10 @@
1
+ #!/home/tebako/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
5
+ require "tebako-test"
6
+
7
+ begin
8
+ instance = TebakoTest.new
9
+ instance.run!
10
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "text-table"
4
+
5
+ # Tebako test class
6
+ class TebakoTest
7
+ def msg
8
+ table = Text::Table.new
9
+ table.head = %w[A B]
10
+ table.rows = [%w[a1 b1]]
11
+ table.rows << %w[a2 b2]
12
+ puts table
13
+ end
14
+
15
+ def run!
16
+ puts "Hello! This is test-11 talking from inside DwarFS"
17
+ puts "You will now see a nice table that will be drawn for you by text-table gem."
18
+ msg
19
+ end
20
+ end