tebako 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CMakeLists.txt +694 -0
- data/Gemfile +35 -0
- data/README.adoc +389 -0
- data/Rakefile +33 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/cmake/copy_dir.cmake +29 -0
- data/cmake/def_tty_colours.cmake +19 -0
- data/common.env +6 -0
- data/exe/tebako +31 -0
- data/include/tebako/tebako-fs.h +40 -0
- data/include/tebako/tebako-main.h +40 -0
- data/lib/cli.rb +28 -0
- data/lib/tebako/cli.rb +137 -0
- data/lib/tebako/cli_helpers.rb +147 -0
- data/lib/tebako/error.rb +39 -0
- data/lib/tebako/packager/pass1.rb +155 -0
- data/lib/tebako/packager/pass2.rb +374 -0
- data/lib/tebako/packager.rb +210 -0
- data/lib/tebako/version.rb +30 -0
- data/resources/tebako-fs.cpp.in +37 -0
- data/resources/tebako-version.h.in +37 -0
- data/src/tebako-main.cpp +188 -0
- data/tebako.gemspec +63 -0
- data/tests/scripts/cross-tests.sh +34 -0
- data/tests/scripts/functional-tests.sh +335 -0
- data/tests/test-00/test.rb +4 -0
- data/tests/test-01/tebako-test-run.rb +5 -0
- data/tests/test-09/tebako-test-0.0.1.gem +0 -0
- data/tests/test-11/bin/tebako-test-run.rb +10 -0
- data/tests/test-11/lib/tebako-test.rb +20 -0
- data/tests/test-11/tebako-test.gemspec +15 -0
- data/tests/test-12/tebako-test-a.gemspec +15 -0
- data/tests/test-12/tebako-test-b.gemspec +15 -0
- data/tests/test-13/bin/tebako-test-run.rb +10 -0
- data/tests/test-13/lib/tebako-test.rb +20 -0
- data/tests/test-13/tebako-test.gemspec +15 -0
- data/tests/test-15/Gemfile +8 -0
- data/tests/test-15/Rakefile +4 -0
- data/tests/test-15/bin/tebako-test-run.rb +10 -0
- data/tests/test-15/lib/tebako/bundle/test/version.rb +9 -0
- data/tests/test-15/lib/tebako/bundle/test.rb +29 -0
- data/tests/test-15/tebako-bundle-test.gemspec +30 -0
- data/tests/test-16/Gemfile +8 -0
- data/tests/test-16/Rakefile +4 -0
- data/tests/test-16/bin/tebako-test-run.rb +10 -0
- data/tests/test-16/lib/tebako/bundle/test/version.rb +9 -0
- data/tests/test-16/lib/tebako/bundle/test.rb +29 -0
- data/tests/test-16/tebako-bundle-test.gemspec +24 -0
- data/tests/test-18/Gemfile +5 -0
- data/tests/test-18/tebako-test-run.rb +12 -0
- data/tests/test-19/Gemfile +6 -0
- data/tests/test-19/tebako-test-run.rb +11 -0
- data/tests-2/fixtures/gems-bundler/Gemfile +4 -0
- data/tests-2/fixtures/gems-bundler/gems-bundler.rb +34 -0
- data/tests-2/fixtures/gems-byebug/Gemfile +5 -0
- data/tests-2/fixtures/gems-byebug/gems-byebug.rb +31 -0
- data/tests-2/fixtures/gems-expressir/Gemfile +7 -0
- data/tests-2/fixtures/gems-expressir/gems-expressir.rb +33 -0
- data/tests-2/fixtures/gems-libmspack/Gemfile +5 -0
- data/tests-2/fixtures/gems-libmspack/gems-libmspack.rb +91 -0
- data/tests-2/fixtures/gems-sassc/Gemfile +6 -0
- data/tests-2/fixtures/gems-sassc/base_style/all.scss +1 -0
- data/tests-2/fixtures/gems-sassc/base_style/reset.scss +100 -0
- data/tests-2/fixtures/gems-sassc/gems-sassc.rb +129 -0
- data/tests-2/fixtures/gems-seven-zip/Gemfile +7 -0
- data/tests-2/fixtures/gems-seven-zip/gems-seven-zip.rb +53 -0
- data/tests-2/fixtures/launcher-coreincl/launcher-coreincl.rb +29 -0
- data/tests-2/fixtures/launcher-package/launcher-package.rb +29 -0
- data/tests-2/fixtures/launcher-pwd/launcher-pwd.rb +28 -0
- data/tests-2/fixtures/launcher-stdinredir/input.txt +1 -0
- data/tests-2/fixtures/launcher-stdinredir/launcher-stdinredir.rb +31 -0
- data/tests-2/fixtures/launcher-stdoutredir/launcher-stdoutredir.rb +28 -0
- data/tests-2/fixtures/patches-dir/level-1/level-2/file-1.txt +1 -0
- data/tests-2/fixtures/patches-dir/level-1/level-2/file-2.txt +1 -0
- data/tests-2/fixtures/patches-dir/level-1/level-2/file-3.txt +1 -0
- data/tests-2/fixtures/patches-dir/patches-dir.rb +154 -0
- data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-1.txt +1 -0
- data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-2.txt +2 -0
- data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-3.txt +1 -0
- data/tests-2/fixtures/patches-io-and-file/level-1/link-3 +1 -0
- data/tests-2/fixtures/patches-io-and-file/patches-io-and-file.rb +87 -0
- data/tests-2/fixtures/patches-main/patches-main.rb +6 -0
- data/tests-2/tebako-test.rb +312 -0
- metadata +170 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2021-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
|
+
# This test is inspired packed-mn
|
29
|
+
# https://github.com/metanorma/packed-mn
|
30
|
+
|
31
|
+
require "rubygems"
|
32
|
+
require "bundler/setup"
|
33
|
+
require "tempfile"
|
34
|
+
|
35
|
+
COMPILER_MEMFS = "/__tebako_memfs__"
|
36
|
+
|
37
|
+
# https://github.com/pmq20/ruby-packer/blob/master/lib/compiler/constants.rb#L10
|
38
|
+
COMPILER_MEMFS_LIB_CACHE = Pathname.new(Dir.mktmpdir("tebako-tests-"))
|
39
|
+
at_exit do
|
40
|
+
FileUtils.remove_dir(COMPILER_MEMFS_LIB_CACHE.to_path, true)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Extension for String class
|
44
|
+
# Operations with quotes
|
45
|
+
class String
|
46
|
+
def quoted?
|
47
|
+
start_with?('"') && end_with?('"')
|
48
|
+
end
|
49
|
+
|
50
|
+
def unquote
|
51
|
+
chomp('"').reverse.chomp('"').reverse
|
52
|
+
end
|
53
|
+
|
54
|
+
def quote
|
55
|
+
"\"#{self}\""
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def extract_memfs(file, wild: false, extract_path: COMPILER_MEMFS_LIB_CACHE)
|
60
|
+
is_quoted = file.quoted?
|
61
|
+
file = file.unquote if is_quoted
|
62
|
+
|
63
|
+
return file unless File.exist?(file) && file.start_with?(COMPILER_MEMFS)
|
64
|
+
|
65
|
+
memfs_extracted_file = extract_path + File.basename(file)
|
66
|
+
unless memfs_extracted_file.exist?
|
67
|
+
files = wild ? Dir.glob("#{File.dirname(file)}/*#{File.extname(file)}") : [file]
|
68
|
+
FileUtils.cp_r files, extract_path
|
69
|
+
end
|
70
|
+
|
71
|
+
is_quoted ? memfs_extracted_file.to_path.quote : memfs_extracted_file.to_path
|
72
|
+
end
|
73
|
+
|
74
|
+
require "ffi"
|
75
|
+
|
76
|
+
# HACK: extract temp libraries to use with ffi
|
77
|
+
# Wrapper for FFI.map_library_name method
|
78
|
+
module FFI
|
79
|
+
# https://stackoverflow.com/questions/29907157/how-to-alias-a-class-method-in-rails-model/29907207
|
80
|
+
singleton_class.send(:alias_method, :map_library_name_orig, :map_library_name)
|
81
|
+
|
82
|
+
# http://tech.tulentsev.com/2012/02/ruby-how-to-override-class-method-with-a-module/
|
83
|
+
def self.map_library_name(lib)
|
84
|
+
l = extract_memfs(lib)
|
85
|
+
ll = map_library_name_orig(l)
|
86
|
+
puts "#{lib} ==> #{ll}"
|
87
|
+
ll
|
88
|
+
end
|
89
|
+
end
|
90
|
+
# END of HACK
|
91
|
+
|
92
|
+
require "sassc"
|
93
|
+
|
94
|
+
module SassC
|
95
|
+
# SassC engine patch
|
96
|
+
# Scan through load paths; copy files from tebako memfs to
|
97
|
+
# tmp folders; add tmp folders to load paths
|
98
|
+
class Engine
|
99
|
+
alias load_paths_orig load_paths
|
100
|
+
|
101
|
+
def process_path(path)
|
102
|
+
if path.start_with?(COMPILER_MEMFS)
|
103
|
+
m = path.sub(COMPILER_MEMFS, COMPILER_MEMFS_LIB_CACHE.to_s)
|
104
|
+
FileUtils.cp_r(File.join(path, "."), m) if File.exist?(path)
|
105
|
+
m
|
106
|
+
else
|
107
|
+
path
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def load_paths
|
112
|
+
paths = (@options[:load_paths] || []) + SassC.load_paths
|
113
|
+
np = []
|
114
|
+
paths.each { |p| np << process_path(p) }
|
115
|
+
pp = np.join(File::PATH_SEPARATOR) unless np.empty?
|
116
|
+
puts "Using load_path @ '#{pp}'"
|
117
|
+
pp
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
name = File.join(File.dirname(__FILE__), "styles")
|
123
|
+
SassC.load_paths << File.dirname(__FILE__)
|
124
|
+
SassC.load_paths << name
|
125
|
+
SassC.load_paths << "/usr/local/fun"
|
126
|
+
|
127
|
+
SassC::Engine.new("@import 'base_style/all.scss'", style: :compressed).render
|
128
|
+
|
129
|
+
puts "Hello! SassC gem welcomes you to the magic world of ruby gems."
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2021-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
|
+
# This test is inspired packed-mn
|
29
|
+
# https://github.com/metanorma/packed-mn
|
30
|
+
|
31
|
+
require "rubygems"
|
32
|
+
require "bundler/setup"
|
33
|
+
require "tempfile"
|
34
|
+
|
35
|
+
COMPILER_MEMFS = "/__tebako_memfs__"
|
36
|
+
|
37
|
+
# https://github.com/pmq20/ruby-packer/blob/master/lib/compiler/constants.rb#L10
|
38
|
+
COMPILER_MEMFS_LIB_CACHE = Pathname.new(Dir.mktmpdir("tebako-tests-"))
|
39
|
+
at_exit do
|
40
|
+
FileUtils.remove_dir(COMPILER_MEMFS_LIB_CACHE.to_path, true)
|
41
|
+
end
|
42
|
+
|
43
|
+
# HACK: fix path for 7zip load
|
44
|
+
sevenz_lib = RUBY_PLATFORM.downcase.match(/mswin|mingw/) ? "7z*.dll" : "7z.so"
|
45
|
+
sevenz_path = File.join(Gem::Specification.find_by_name("seven-zip").full_gem_path, "lib", "seven_zip_ruby", sevenz_lib)
|
46
|
+
FileUtils.mkdir_p(COMPILER_MEMFS_LIB_CACHE / "seven_zip_ruby")
|
47
|
+
FileUtils.cp(sevenz_path, COMPILER_MEMFS_LIB_CACHE / "seven_zip_ruby")
|
48
|
+
$LOAD_PATH.unshift(COMPILER_MEMFS_LIB_CACHE)
|
49
|
+
# END of HACK
|
50
|
+
|
51
|
+
# Just make sure the constant exists
|
52
|
+
require "seven_zip_ruby"
|
53
|
+
puts "Hello! SevenZipRuby welcomes you to the magic world of ruby gems."
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2022-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 "cgi"
|
29
|
+
File.write("output.txt", CGI.escapeHTML("3 < 5"))
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2022-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
|
+
hello_world = "Hello, World!"
|
29
|
+
puts hello_world
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2021-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
|
+
File.write("output.txt", "output")
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello, World!
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2022-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
|
+
a = gets
|
29
|
+
exit 104 if a == "Hello, World!\r\n"
|
30
|
+
exit 104 if a == "Hello, World!\n"
|
31
|
+
exit 103
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 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
|
+
puts "Hello, World!"
|
@@ -0,0 +1 @@
|
|
1
|
+
This is file-1 txt
|
@@ -0,0 +1 @@
|
|
1
|
+
This is file-2.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
This is file-3.txt
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2021-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
|
+
puts "===== Dir test ====="
|
29
|
+
|
30
|
+
# test 1 chdir absolute - getwd
|
31
|
+
EXPECTED_CWD_1 = "/__tebako_memfs__/local/"
|
32
|
+
print "chdir '#{File.dirname(__FILE__)}' ... "
|
33
|
+
Dir.chdir(File.dirname(__FILE__))
|
34
|
+
cwd = Dir.getwd
|
35
|
+
raise "getwd returned #{cwd} while #{EXPECTED_CWD_1} was expected" unless cwd.eql? EXPECTED_CWD_1
|
36
|
+
|
37
|
+
print "OK(success)\n"
|
38
|
+
|
39
|
+
# test 2 chdir relative - getwd
|
40
|
+
EXPECTED_CWD_2 = "/__tebako_memfs__/local/level-1/"
|
41
|
+
print "chdir 'level-1' ... "
|
42
|
+
Dir.chdir("level-1")
|
43
|
+
cwd = Dir.getwd
|
44
|
+
raise "getwd returned #{cwd} while #{EXPECTED_CWD_2} was expected" unless cwd.eql? EXPECTED_CWD_2
|
45
|
+
|
46
|
+
print "OK(success)\n"
|
47
|
+
|
48
|
+
# test 3 chdir relative (does not exit) - getwd
|
49
|
+
print "chdir 'does-not-exists' ... "
|
50
|
+
begin
|
51
|
+
Dir.chdir("does-not-exist")
|
52
|
+
failed = false
|
53
|
+
rescue Errno::ENOENT
|
54
|
+
failed = true
|
55
|
+
end
|
56
|
+
raise "chdir succeeded while exception was expected" unless failed
|
57
|
+
|
58
|
+
cwd = Dir.getwd
|
59
|
+
raise "Getwd returned #{cwd} while #{EXPECTED_CWD_2} was expected" unless cwd.eql? EXPECTED_CWD_2
|
60
|
+
|
61
|
+
print "OK(failure)\n"
|
62
|
+
|
63
|
+
# test 4 chdir absolute (does not exit) - getwd
|
64
|
+
print "chdir '/bin/does-not-exists' ... "
|
65
|
+
begin
|
66
|
+
Dir.chdir("/bin/does-not-exist")
|
67
|
+
failed = false
|
68
|
+
rescue Errno::ENOENT
|
69
|
+
failed = true
|
70
|
+
end
|
71
|
+
raise "chdir succeeded while exception was expected" unless failed
|
72
|
+
|
73
|
+
cwd = Dir.getwd
|
74
|
+
raise "getwd returned #{cwd} while #{EXPECTED_CWD_2} was expected" unless cwd.eql? EXPECTED_CWD_2
|
75
|
+
|
76
|
+
print "OK(failure)\n"
|
77
|
+
|
78
|
+
# test 5 open - read - tell - seek - close - rewind
|
79
|
+
print "open - read - tell - seek - close @ '/__tebako_memfs__/local/level-1/level-2' ... "
|
80
|
+
a_dir = Dir.new("/__tebako_memfs__/local/level-1/level-2")
|
81
|
+
|
82
|
+
r = a_dir.read
|
83
|
+
p = a_dir.tell
|
84
|
+
raise "Dir.read returned #{r} while '.' was expected" unless r.eql? "."
|
85
|
+
raise "Dir.tell returned #{p} while 1 was expected" unless p.eql? 1
|
86
|
+
|
87
|
+
r = a_dir.read
|
88
|
+
p = a_dir.tell
|
89
|
+
raise "Dir.read returned #{r} while '..' was expected" unless r.eql? ".."
|
90
|
+
raise "Dir.tell returned #{p} while 2 was expected" unless p.eql? 2
|
91
|
+
|
92
|
+
re = Regexp.new("file-..txt").freeze
|
93
|
+
(3..5).each do |i|
|
94
|
+
r = a_dir.read
|
95
|
+
p = a_dir.tell
|
96
|
+
raise "Dir.read returned #{r} while 'file-?.txt' was expected" unless r =~ re
|
97
|
+
raise "Dir.tell returned #{p} while #{i} was expected" unless p.eql? i
|
98
|
+
end
|
99
|
+
|
100
|
+
a_dir.seek(1)
|
101
|
+
r = a_dir.read
|
102
|
+
p = a_dir.tell
|
103
|
+
raise "Dir.read returned #{r} while '..' was expected" unless r.eql? ".."
|
104
|
+
raise "Dir.tell returned #{p} while 2 was expected" unless p.eql? 2
|
105
|
+
|
106
|
+
a_dir.rewind
|
107
|
+
p = a_dir.tell
|
108
|
+
raise "Dir.tell returned #{p} while 1 was expected" unless p.eql? 0
|
109
|
+
|
110
|
+
r = a_dir.read
|
111
|
+
p = a_dir.tell
|
112
|
+
raise "Dir.read returned #{r} while '.' was expected" unless r.eql? "."
|
113
|
+
raise "Dir.tell returned #{p} while 1 was expected" unless p.eql? 1
|
114
|
+
|
115
|
+
p = a_dir.close
|
116
|
+
raise "Dir.close returned #{p} while nil was expected" unless p.nil?
|
117
|
+
|
118
|
+
print "OK(match)\n"
|
119
|
+
|
120
|
+
# test 7 glob
|
121
|
+
print "[\"**/*.txt\", base:\"/__tebako_memfs__/local/\"] ... "
|
122
|
+
fls = Dir["**/*.txt", base: "/__tebako_memfs__/local/"]
|
123
|
+
EXPECTED_1 = ["level-1/level-2/file-1.txt", "level-1/level-2/file-2.txt", "level-1/level-2/file-3.txt"].freeze
|
124
|
+
|
125
|
+
if fls.difference(EXPECTED_1).any? || EXPECTED_1.difference(fls).any?
|
126
|
+
raise "Dir[] returned #{fls} while #{EXPECTED_1} was expected"
|
127
|
+
end
|
128
|
+
|
129
|
+
print "OK(match)\n"
|
130
|
+
|
131
|
+
# test 8 glob
|
132
|
+
print "[\"/__tebako_memfs__/local/**/file-1.txt\"] ... "
|
133
|
+
fls = Dir["/__tebako_memfs__/local/**/file-1.txt"]
|
134
|
+
EXPECTED_2 = ["/__tebako_memfs__/local/level-1/level-2/file-1.txt"].freeze
|
135
|
+
|
136
|
+
if fls.difference(EXPECTED_2).any? || EXPECTED_2.difference(fls).any?
|
137
|
+
raise "Dir[] returned #{fls} while #{EXPECTED_2} was expected"
|
138
|
+
end
|
139
|
+
|
140
|
+
print "OK(match)\n"
|
141
|
+
|
142
|
+
# test 9 Dir.empty?
|
143
|
+
print "Dir.empty?(\"/__tebako_memfs__/local/level-1/level-2\") ..."
|
144
|
+
r = Dir.empty?("/__tebako_memfs__/local/level-1/level-2")
|
145
|
+
raise "Dir.empty? returned #{r} while 'false' was expected" if r
|
146
|
+
|
147
|
+
print "OK(match)\n"
|
148
|
+
|
149
|
+
# test 10 Dir.empty?
|
150
|
+
print "Dir.empty?(\"/__tebako_memfs__/local/level-1/level-2/level-3\") ..."
|
151
|
+
r = Dir.empty?("/__tebako_memfs__/local/level-1/level-2/level-3")
|
152
|
+
raise "Dir.empty? returned #{r} while 'true' was expected" unless r
|
153
|
+
|
154
|
+
print "OK(match)\n"
|
@@ -0,0 +1 @@
|
|
1
|
+
This is file-1.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
This is file-3.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
level-2/file-3.txt
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
+
puts "===== File tests ====="
|
29
|
+
|
30
|
+
# test 1 exist? (aka stat)
|
31
|
+
print "exist?(\"/__tebako_memfs__/local/level-1/level-2/file-1.txt\") ... "
|
32
|
+
r = File.exist?("/__tebako_memfs__/local/level-1/level-2/file-1.txt")
|
33
|
+
raise "exist? returned '#{r}' while 'true' was expected" unless r
|
34
|
+
|
35
|
+
print "OK(success)\n"
|
36
|
+
|
37
|
+
# test 2 executable_real? (aka access)
|
38
|
+
# print "executable_real?(\"/__tebako_memfs__/local/level-1/level-2/file-2.txt\") ... "
|
39
|
+
# r = File.executable_real?("/__tebako_memfs__/local/level-1/level-2/file-2.txt")
|
40
|
+
# raise "executable_real? returned '#{r}' while 'false' was expected" if r
|
41
|
+
# print "OK(failure)\n"
|
42
|
+
|
43
|
+
# test 3 open - read - seak - rewind - close
|
44
|
+
print "open - seek - read - rewind - close ... "
|
45
|
+
Dir.chdir("/__tebako_memfs__/local/level-1/level-2")
|
46
|
+
File.open("file-2.txt", "r") do |f|
|
47
|
+
r = f.read(18)
|
48
|
+
raise "read returned '#{r}' while 'This is file-2.txt' was expected" unless r.eql? "This is file-2.txt"
|
49
|
+
|
50
|
+
s = f.pos
|
51
|
+
raise "pos returned '#{s}' while '18' was expected" unless s.eql? 18
|
52
|
+
|
53
|
+
f.seek(5, :SET)
|
54
|
+
s = f.pos
|
55
|
+
raise "pos returned '#{s}' while '5' was expected" unless s.eql? 5
|
56
|
+
|
57
|
+
r = f.read(13)
|
58
|
+
raise "read returned '#{r}' while 'is file-2.txt' was expected" unless r.eql? "is file-2.txt"
|
59
|
+
|
60
|
+
f.rewind
|
61
|
+
s = f.pos
|
62
|
+
raise "pos returned '#{s}' while '5' was expected" unless s.eql? 0
|
63
|
+
|
64
|
+
r = f.read(4)
|
65
|
+
raise "read returned '#{r}' while 'This' was expected" unless r.eql? "This"
|
66
|
+
end
|
67
|
+
print "OK(match)\n"
|
68
|
+
|
69
|
+
# test 4 open - pread - close
|
70
|
+
print "open - pread - close ... "
|
71
|
+
Dir.chdir("/__tebako_memfs__/local/level-1/level-2")
|
72
|
+
File.open("file-1.txt", "r") do |f|
|
73
|
+
r = f.pread(13, 5)
|
74
|
+
raise "read returned '#{r}' while 'is file-1.txt' was expected" unless r.eql? "is file-1.txt"
|
75
|
+
end
|
76
|
+
print "OK(match)\n"
|
77
|
+
|
78
|
+
# test 5 lstat - readlink
|
79
|
+
print "readlink ... "
|
80
|
+
Dir.chdir("/__tebako_memfs__/local/level-1")
|
81
|
+
s = File.lstat("/__tebako_memfs__/local/level-1/link-3").size
|
82
|
+
raise "lstat returned '#{s}' while '18' was expected" unless s.eql? 18
|
83
|
+
|
84
|
+
r = File.readlink("link-3")
|
85
|
+
raise "readlink returned '#{r}' while 'level-2/file-3.txt' was expected" unless r.eql? "level-2/file-3.txt"
|
86
|
+
|
87
|
+
print "OK(match)\n"
|