Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to determine the path of PostgreSQL server commands from pg_config #503

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,24 @@ PgはRuby-3.0で導入された`Fiber.scheduler`に完全に対応していま

$ bundle install

拡張ファイル、パッケージファイル、テストデータベースを一掃するには次のようにします。
Cleanup extension files, packaging files, test databases. Run this to
change between PostgreSQL versions:

$ rake clean

拡張をコンパイルするには次のようにします。

$ rake compile

パスにある`initdb`といったPostgreSQLのツールを使ってテストやスペックを走らせるには次のようにします。
Run tests/specs on the PostgreSQL version that `pg_config --bindir` points
to:

$ PATH=$PATH:/usr/lib/postgresql/14/bin rake test
$ rake test

あるいは行番号を使って特定のテストを走らせるには次のようにします。
Or run a specific test per file and line number on a specific PostgreSQL
version:

$ PATH=$PATH:/usr/lib/postgresql/14/bin rspec -Ilib -fd spec/pg/connection_spec.rb:455
$ PATH=/usr/lib/postgresql/14/bin:$PATH rspec -Ilib -fd spec/pg/connection_spec.rb:455

APIドキュメントを生成するには次のようにします。

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,22 @@ After checking out the source, install all dependencies:

$ bundle install

Cleanup extension files, packaging files, test databases:
Cleanup extension files, packaging files, test databases.
Run this to change between PostgreSQL versions:

$ rake clean

Compile extension:

$ rake compile

Run tests/specs with PostgreSQL tools like `initdb` in the path:
Run tests/specs on the PostgreSQL version that `pg_config --bindir` points to:

$ PATH=$PATH:/usr/lib/postgresql/14/bin rake test
$ rake test

Or run a specific test with the line number:
Or run a specific test per file and line number on a specific PostgreSQL version:

$ PATH=$PATH:/usr/lib/postgresql/14/bin rspec -Ilib -fd spec/pg/connection_spec.rb:455
$ PATH=/usr/lib/postgresql/14/bin:$PATH rspec -Ilib -fd spec/pg/connection_spec.rb:455

Generate the API documentation:

Expand Down
20 changes: 15 additions & 5 deletions spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def initialize( name, port: 54321, postgresql_conf: '' )
@test_dir = TEST_DIRECTORY + "tmp_test_#{@name}"
@test_pgdata = @test_dir + 'data'
@test_pgdata.mkpath
@pg_bin_dir = nil

@logfile = @test_dir + 'setup.log'
trace "Command output logged to #{@logfile}"
Expand All @@ -260,7 +261,7 @@ def initialize( name, port: 54321, postgresql_conf: '' )
unless (@test_pgdata+"postgresql.conf").exist?
FileUtils.rm_rf( @test_pgdata, :verbose => $DEBUG )
trace "Running initdb"
log_and_run @logfile, 'initdb', '-E', 'UTF8', '--no-locale', '-D', @test_pgdata.to_s
log_and_run @logfile, pg_bin_path('initdb'), '-E', 'UTF8', '--no-locale', '-D', @test_pgdata.to_s
end

unless (@test_pgdata+"ruby-pg-server-cert").exist?
Expand Down Expand Up @@ -293,7 +294,7 @@ def initialize( name, port: 54321, postgresql_conf: '' )
trace "Starting postgres"
sopt = "-p #{@port}"
sopt += " -k #{@test_dir.to_s.dump}" unless RUBY_PLATFORM=~/mingw|mswin/i
log_and_run @logfile, 'pg_ctl', '-w', '-o', sopt,
log_and_run @logfile, pg_bin_path('pg_ctl'), '-w', '-o', sopt,
'-D', @test_pgdata.to_s, 'start'
sleep 2

Expand Down Expand Up @@ -328,8 +329,8 @@ def generate_ssl_certs(output_dir)

def create_test_db
trace "Creating the test DB"
log_and_run @logfile, 'psql', '-p', @port.to_s, '-e', '-c', 'DROP DATABASE IF EXISTS test', 'postgres'
log_and_run @logfile, 'createdb', '-p', @port.to_s, '-e', 'test'
log_and_run @logfile, pg_bin_path('psql'), '-p', @port.to_s, '-e', '-c', 'DROP DATABASE IF EXISTS test', 'postgres'
log_and_run @logfile, pg_bin_path('createdb'), '-p', @port.to_s, '-e', 'test'
end

def connect
Expand All @@ -344,7 +345,16 @@ def connect
def teardown
trace "Tearing down test database for #{@name}"

log_and_run @logfile, 'pg_ctl', '-D', @test_pgdata.to_s, 'stop'
log_and_run @logfile, pg_bin_path('pg_ctl'), '-D', @test_pgdata.to_s, 'stop'
end

def pg_bin_path(cmd)
@pg_bin_dir ||= begin
`pg_config --bindir`.strip
rescue
nil
end
[@pg_bin_dir&.empty? ? nil : @pg_bin_dir, cmd].compact.join("/")
end
end

Expand Down
4 changes: 3 additions & 1 deletion translation/po4a.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
--localized-charset UTF-8 \
--master-language en \
--option markdown \
--keep 0
--keep 0 \
--msgmerge-opt='--no-wrap' \
--wrap-po=newlines

[type:text] ../README.md ja:../README.ja.md