Skip to content

Commit

Permalink
fix: produce tebako runtime with default output name #273
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Mar 3, 2025
1 parent 067b48c commit d66e867
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/tebako/options_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def output_folder

def package
package = if @options["output"].nil?
File.join(Dir.pwd, File.basename(fs_entrance, ".*"))
File.join(Dir.pwd, mode == "runtime" ? "tebako-runtime" : File.basename(fs_entrance, ".*"))
else
@options["output"]&.gsub("\\", "/")
end
Expand Down
101 changes: 70 additions & 31 deletions spec/options_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@
end
end

describe "#deps_lib_dir" do
let(:options_manager) { Tebako::OptionsManager.new({}) }
it "returns the correct lib directory path" do
allow(options_manager).to receive(:prefix).and_return("/fake/prefix")
expect(options_manager.deps_lib_dir).to eq("/fake/prefix/deps/lib")
end
end

describe "#data_bundle_file" do
let(:options_manager) { Tebako::OptionsManager.new({}) }
it "returns the correct data bundle file path" do
Expand All @@ -97,6 +89,14 @@
end
end

describe "#deps_lib_dir" do
let(:options_manager) { Tebako::OptionsManager.new({}) }
it "returns the correct lib directory path" do
allow(options_manager).to receive(:prefix).and_return("/fake/prefix")
expect(options_manager.deps_lib_dir).to eq("/fake/prefix/deps/lib")
end
end

describe "#fs_current" do
let(:options_manager) { Tebako::OptionsManager.new({}) }
context "when the platform is Windows (msys, mingw, cygwin)" do
Expand Down Expand Up @@ -209,24 +209,62 @@
end

describe "#package" do
let(:options_manager) { OptionsManager.new(options) }

context 'when @options["output"] is set' do
let(:options) { { "output" => "custom_package" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }

it "returns the package option" do
expect(options_manager.package).to eq(File.expand_path("custom_package"))
end

context "with Windows-style paths" do
let(:options) { { "output" => "C:/path/to/package" } }

it "converts backslashes to forward slashes" do
expect(options_manager.package).to eq("C:/path/to/package")
end
end
end

context 'when @options["output"] is not set' do
let(:options) { { "entry-point" => "app.rb" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }
context 'when mode is "runtime"' do
let(:options) { { "mode" => "runtime" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }

it "returns the default package name based on entry-point" do
expected_package = File.join(Dir.pwd, "app")
expect(options_manager.package).to eq(expected_package)
it "returns tebako-runtime in current directory" do
expected_package = File.join(Dir.pwd, "tebako-runtime")
expect(options_manager.package).to eq(expected_package)
end
end

context 'when mode is "bundle" or not set' do
let(:options) { { "entry-point" => "app.rb" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }

it "returns package name based on entry-point without extension" do
expected_package = File.join(Dir.pwd, "app")
expect(options_manager.package).to eq(expected_package)
end
end

context 'when mode is "application"' do
let(:options) { { "mode" => "application", "entry-point" => "app.rb" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }

it "returns package name based on entry-point without extension" do
expected_package = File.join(Dir.pwd, "app")
expect(options_manager.package).to eq(expected_package)
end
end

context 'when mode is "both"' do
let(:options) { { "mode" => "both", "entry-point" => "app.rb" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }

it "returns package name based on entry-point without extension" do
expected_package = File.join(Dir.pwd, "app")
expect(options_manager.package).to eq(expected_package)
end
end
end

Expand All @@ -239,7 +277,7 @@
allow(options_manager).to receive(:relative?).and_return(true)
end

it "returns the absolute package path" do
it "joins with fs_current to create absolute path" do
expected_package = File.join("/current/fs/path", "relative/path/to/package")
expect(options_manager.package).to eq(expected_package)
end
Expand All @@ -253,7 +291,7 @@
allow(options_manager).to receive(:relative?).and_return(false)
end

it "returns the absolute package path" do
it "uses the path as is" do
expect(options_manager.package).to eq("/absolute/path/to/package")
end
end
Expand Down Expand Up @@ -466,7 +504,7 @@
end
let(:options_manager) { Tebako::OptionsManager.new(options) }
let(:root) { File.join(Dir.pwd, options["root"]) }
let(:pckg) { File.join(Dir.pwd, "main") }
let(:pckg) { File.join(Dir.pwd, "tebako-runtime") }
let(:prefix) { File.expand_path("~/.tebako") }

it "returns the correct announcement with default cwd" do
Expand All @@ -492,19 +530,6 @@
end
end

describe "#ref" do
it "returns 'tebako-runtime' if no ref is specified" do
options_manager = described_class.new({})
expect(options_manager.ref).to eq("tebako-runtime")
end

it "returns the given ref, converting backslashes to forward slashes" do
options = { "ref" => "some\\path\\ref" }
options_manager = described_class.new(options)
expect(options_manager.ref).to eq("some/path/ref")
end
end

describe "#press_options" do
context 'when options["cwd"] is set' do
let(:options) do
Expand Down Expand Up @@ -572,6 +597,20 @@
end
end
end

describe "#ref" do
it "returns 'tebako-runtime' if no ref is specified" do
options_manager = described_class.new({})
expect(options_manager.ref).to eq("tebako-runtime")
end

it "returns the given ref, converting backslashes to forward slashes" do
options = { "ref" => "some\\path\\ref" }
options_manager = described_class.new(options)
expect(options_manager.ref).to eq("some/path/ref")
end
end

describe "#relative?" do
let(:options_manager) { Tebako::OptionsManager.new({}) }
it "returns true for a relative path" do
Expand Down

0 comments on commit d66e867

Please sign in to comment.