Skip to content

Commit

Permalink
Merge pull request ged#503 from larskanis/find-initdb
Browse files Browse the repository at this point in the history
Try to determine the path of PostgreSQL server commands from `pg_config`
  • Loading branch information
larskanis authored Feb 28, 2023
2 parents 1e8dc14 + f56f7fc commit cf93cc8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
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

0 comments on commit cf93cc8

Please sign in to comment.