Skip to content

Commit

Permalink
Fixed Windows temp path (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx authored Mar 29, 2024
1 parent 1ff370f commit 738e620
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/tebako-runtime/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
# POSSIBILITY OF SUCH DAMAGE.

module TebakoRuntime
VERSION = "0.3.0"
VERSION = "0.3.1"
end
25 changes: 18 additions & 7 deletions spec/runtime_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2023 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2023-2024 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand Down Expand Up @@ -33,25 +33,35 @@
expect(TebakoRuntime::VERSION).not_to be nil
end

# Temporary directory
def tmpdir_name
tdm = RUBY_PLATFORM =~ /msys|mingw|cygwin|mswin/ ? ENV.fetch("TEMP", nil) : "/tmp"
File.join(tdm, "tebako-test-#{$PROCESS_ID}-#{rand 2**32}").tr("\\", "/")
end

it "extracts single file from memfs" do
tmpd = tmpdir_name
test_file = File.join(__dir__, "fixtures", "files", "test1.file")
expect(FileUtils).to receive(:cp_r).with([test_file], "/tmp")
expect(FileUtils).to receive(:cp_r).with([test_file], tmpd)

TebakoRuntime.extract(test_file, false, "/tmp")
TebakoRuntime.extract(test_file, false, tmpd)
end

it "extracts files from memfs by wildcard" do
tmpd = tmpdir_name

test1_file = File.join(__dir__, "fixtures", "files", "test1.file")
test2_file = File.join(__dir__, "fixtures", "files", "test2.file")
test_files = File.join(__dir__, "fixtures", "files", "*.file")

expect(FileUtils).to receive(:cp_r).with(array_including(test1_file, test2_file), "/tmp")
expect(FileUtils).to receive(:cp_r).with(array_including(test1_file, test2_file), tmpd)

TebakoRuntime.extract(test_files, true, "/tmp")
TebakoRuntime.extract(test_files, true, tmpd)
end

it "returns unchanged reference to non-memfs file" do
expect(TebakoRuntime.extract_memfs("/tmp/test.file")).to eq("/tmp/test.file")
tmpd = tmpdir_name
expect(TebakoRuntime.extract_memfs("#{tmpd}/test.file")).to eq("#{tmpd}/test.file")
end

it "processes a memfs file with default settings" do
Expand Down Expand Up @@ -91,7 +101,8 @@
end

it "returns unchanged reference to non-memfs file with quoted name" do
expect(TebakoRuntime.extract_memfs("\"/tmp/test.file\"")).to eq("\"/tmp/test.file\"")
tmpd = tmpdir_name
expect(TebakoRuntime.extract_memfs("\"#{tmpd}/test.file\"")).to eq("\"#{tmpd}/test.file\"")
end

it "processes a memfs file with quoted name" do
Expand Down

0 comments on commit 738e620

Please sign in to comment.