Skip to content

Commit 7d75320

Browse files
committed
Fix hung up on Windows
I think it is due to the fact that I run the `bundle gem` twice. That's why I changed it so that one test executes `bundle gem` exactly once.
1 parent 7567136 commit 7d75320

File tree

1 file changed

+107
-102
lines changed

1 file changed

+107
-102
lines changed

bundler/spec/commands/newgem_spec.rb

Lines changed: 107 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,66 @@ def bundle_exec_standardrb
309309
end
310310
end
311311

312+
shared_examples_for "--ext=go" do
313+
it "is not deprecated" do
314+
expect(err).not_to include "[DEPRECATED] Option `--ext` without explicit value is deprecated."
315+
end
316+
317+
it "builds ext skeleton" do
318+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.c")).to exist
319+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.go")).to exist
320+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.h")).to exist
321+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb")).to exist
322+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod")).to exist
323+
end
324+
325+
it "includes extconf.rb in gem_name.gemspec" do
326+
expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include(%(spec.extensions = ["ext/#{gem_name}/extconf.rb"]))
327+
end
328+
329+
it "includes go_gem in gem_name.gemspec" do
330+
expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include('spec.add_dependency "go_gem", "~> 0.2"')
331+
end
332+
333+
it "includes go_gem extension in extconf.rb" do
334+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb").read).to include(<<~RUBY)
335+
require "mkmf"
336+
require "go_gem/mkmf"
337+
RUBY
338+
339+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb").read).to include(%(create_go_makefile("#{gem_name}/#{gem_name}")))
340+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb").read).not_to include("create_makefile")
341+
end
342+
343+
it "includes go_gem extension in gem_name.c" do
344+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.c").read).to eq(<<~C)
345+
#include "#{gem_name}.h"
346+
#include "_cgo_export.h"
347+
C
348+
end
349+
350+
it "includes skeleton code in gem_name.go" do
351+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.go").read).to include(<<~GO)
352+
/*
353+
#include "#{gem_name}.h"
354+
355+
VALUE rb_#{gem_name}_sum(VALUE self, VALUE a, VALUE b);
356+
*/
357+
import "C"
358+
GO
359+
360+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.go").read).to include(<<~GO)
361+
//export rb_#{gem_name}_sum
362+
func rb_#{gem_name}_sum(_ C.VALUE, a C.VALUE, b C.VALUE) C.VALUE {
363+
GO
364+
365+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.go").read).to include(<<~GO)
366+
//export Init_#{gem_name}
367+
func Init_#{gem_name}() {
368+
GO
369+
end
370+
end
371+
312372
it "has no rubocop offenses when using --linter=rubocop flag" do
313373
skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core?
314374
bundle "gem #{gem_name} --linter=rubocop"
@@ -1607,155 +1667,100 @@ def create_temporary_dir(dir)
16071667
context "--ext parameter set with go" do
16081668
let(:flags) { "--ext=go" }
16091669

1610-
before do
1611-
bundle ["gem", gem_name, flags].compact.join(" ")
1612-
end
1613-
1614-
it "is not deprecated" do
1615-
expect(err).not_to include "[DEPRECATED] Option `--ext` without explicit value is deprecated."
1616-
end
1617-
1618-
it "builds ext skeleton" do
1619-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.c")).to exist
1620-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.go")).to exist
1621-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.h")).to exist
1622-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb")).to exist
1623-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod")).to exist
1624-
end
1625-
1626-
it "includes extconf.rb in gem_name.gemspec" do
1627-
expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include(%(spec.extensions = ["ext/#{gem_name}/extconf.rb"]))
1628-
end
1629-
1630-
it "includes go_gem in gem_name.gemspec" do
1631-
expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include('spec.add_dependency "go_gem", "~> 0.2"')
1632-
end
1633-
1634-
it "includes go_gem extension in extconf.rb" do
1635-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb").read).to include(<<~RUBY)
1636-
require "mkmf"
1637-
require "go_gem/mkmf"
1638-
RUBY
1639-
1640-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb").read).to include(%(create_go_makefile("#{gem_name}/#{gem_name}")))
1641-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb").read).not_to include("create_makefile")
1642-
end
1643-
1644-
it "includes go_gem extension in gem_name.c" do
1645-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.c").read).to eq(<<~C)
1646-
#include "#{gem_name}.h"
1647-
#include "_cgo_export.h"
1648-
C
1649-
end
1650-
1651-
it "includes skeleton code in gem_name.go" do
1652-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.go").read).to include(<<~GO)
1653-
/*
1654-
#include "#{gem_name}.h"
1655-
1656-
VALUE rb_#{gem_name}_sum(VALUE self, VALUE a, VALUE b);
1657-
*/
1658-
import "C"
1659-
GO
1660-
1661-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.go").read).to include(<<~GO)
1662-
//export rb_#{gem_name}_sum
1663-
func rb_#{gem_name}_sum(_ C.VALUE, a C.VALUE, b C.VALUE) C.VALUE {
1664-
GO
1670+
context "with github.user" do
1671+
before do
1672+
bundle ["gem", gem_name, flags].compact.join(" ")
1673+
end
16651674

1666-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.go").read).to include(<<~GO)
1667-
//export Init_#{gem_name}
1668-
func Init_#{gem_name}() {
1669-
GO
1670-
end
1675+
it_behaves_like "--ext=go"
16711676

1672-
it "includes valid module name in go.mod" do
1673-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod").read).to include("module github.com/bundleuser/#{gem_name}")
1674-
end
1677+
it "includes github.user in go.mod" do
1678+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod").read).to include("module github.com/bundleuser/#{gem_name}")
1679+
end
16751680

1676-
context "with --no-ci" do
1677-
let(:flags) { "--ext=go --no-ci" }
1681+
context "with --no-ci" do
1682+
let(:flags) { "--ext=go --no-ci" }
16781683

1679-
it_behaves_like "CI config is absent"
1680-
end
1684+
it_behaves_like "CI config is absent"
1685+
end
16811686

1682-
context "--ci set to github" do
1683-
let(:flags) { "--ext=go --ci=github" }
1687+
context "--ci set to github" do
1688+
let(:flags) { "--ext=go --ci=github" }
16841689

1685-
it "generates .github/workflows/main.yml" do
1686-
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to exist
1687-
expect(bundled_app("#{gem_name}/.github/workflows/main.yml").read).to include("go-version-file: ext/#{gem_name}/go.mod")
1690+
it "generates .github/workflows/main.yml" do
1691+
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to exist
1692+
expect(bundled_app("#{gem_name}/.github/workflows/main.yml").read).to include("go-version-file: ext/#{gem_name}/go.mod")
1693+
end
16881694
end
1689-
end
16901695

1691-
context "--ci set to circle" do
1692-
let(:flags) { "--ext=go --ci=circle" }
1696+
context "--ci set to circle" do
1697+
let(:flags) { "--ext=go --ci=circle" }
16931698

1694-
it "generates a .circleci/config.yml" do
1695-
expect(bundled_app("#{gem_name}/.circleci/config.yml")).to exist
1699+
it "generates a .circleci/config.yml" do
1700+
expect(bundled_app("#{gem_name}/.circleci/config.yml")).to exist
16961701

1697-
expect(bundled_app("#{gem_name}/.circleci/config.yml").read).to include(<<-YAML.strip)
1702+
expect(bundled_app("#{gem_name}/.circleci/config.yml").read).to include(<<-YAML.strip)
16981703
environment:
16991704
GO_VERSION:
17001705
YAML
17011706

1702-
expect(bundled_app("#{gem_name}/.circleci/config.yml").read).to include(<<-YAML)
1707+
expect(bundled_app("#{gem_name}/.circleci/config.yml").read).to include(<<-YAML)
17031708
- run:
17041709
name: Install Go
17051710
command: |
17061711
wget https://go.dev/dl/go$GO_VERSION.linux-amd64.tar.gz -O /tmp/go.tar.gz
17071712
tar -C /usr/local -xzf /tmp/go.tar.gz
17081713
echo 'export PATH=/usr/local/go/bin:"$PATH"' >> "$BASH_ENV"
17091714
YAML
1715+
end
17101716
end
1711-
end
17121717

1713-
context "--ci set to gitlab" do
1714-
let(:flags) { "--ext=go --ci=gitlab" }
1718+
context "--ci set to gitlab" do
1719+
let(:flags) { "--ext=go --ci=gitlab" }
17151720

1716-
it "generates a .gitlab-ci.yml" do
1717-
expect(bundled_app("#{gem_name}/.gitlab-ci.yml")).to exist
1721+
it "generates a .gitlab-ci.yml" do
1722+
expect(bundled_app("#{gem_name}/.gitlab-ci.yml")).to exist
17181723

1719-
expect(bundled_app("#{gem_name}/.gitlab-ci.yml").read).to include(<<-YAML)
1724+
expect(bundled_app("#{gem_name}/.gitlab-ci.yml").read).to include(<<-YAML)
17201725
- wget https://go.dev/dl/go$GO_VERSION.linux-amd64.tar.gz -O /tmp/go.tar.gz
17211726
- tar -C /usr/local -xzf /tmp/go.tar.gz
17221727
- export PATH=/usr/local/go/bin:$PATH
17231728
YAML
17241729

1725-
expect(bundled_app("#{gem_name}/.gitlab-ci.yml").read).to include(<<-YAML.strip)
1730+
expect(bundled_app("#{gem_name}/.gitlab-ci.yml").read).to include(<<-YAML.strip)
17261731
variables:
17271732
GO_VERSION:
17281733
YAML
1734+
end
17291735
end
1730-
end
17311736

1732-
context "when Go is installed" do
1733-
before do
1734-
skip "Go isn't installed" unless system("go version")
1735-
end
1737+
context "when Go is installed" do
1738+
before do
1739+
skip "Go isn't installed" unless system("go version")
1740+
end
17361741

1737-
let(:go_version) do
1738-
/go version go([.\d]+)/.match(`go version`)[1]
1739-
end
1742+
let(:go_version) do
1743+
/go version go([.\d]+)/.match(`go version`)[1]
1744+
end
17401745

1741-
it "includes go version in go.mod" do
1742-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod").read).to include("go #{go_version}")
1743-
end
1746+
it "includes go version in go.mod" do
1747+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod").read).to include("go #{go_version}")
1748+
end
17441749

1745-
it "go.sum is generated" do
1746-
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.sum")).to exist
1750+
it "go.sum is generated" do
1751+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.sum")).to exist
1752+
end
17471753
end
17481754
end
17491755

17501756
context "without github.user" do
17511757
before do
1752-
# FIXME: GitHub Actions Windows Runner hang up here for some reason...
1753-
skip "Workaround for hung up" if Gem.win_platform?
1754-
17551758
git("config --global --unset github.user")
17561759
bundle ["gem", gem_name, flags].compact.join(" ")
17571760
end
17581761

1762+
it_behaves_like "--ext=go"
1763+
17591764
it "includes valid module name in go.mod" do
17601765
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod").read).to include("module github.com/username/#{gem_name}")
17611766
end

0 commit comments

Comments
 (0)