From ec460173eb8d75208c8dbfceb70533dfdb46f49b Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Fri, 3 May 2013 13:51:10 -0500 Subject: [PATCH] Use rake instead of guard for erb compilation --- Guardfile | 48 ---------------------------- README.md | 9 +++--- Rakefile | 14 ++++++++ connection_select_column_test.go | 2 ++ connection_select_column_test.go.erb | 2 -- connection_select_value_test.go | 2 ++ connection_select_value_test.go.erb | 2 -- data_row_reader_test.go | 2 ++ data_row_reader_test.go.erb | 2 -- 9 files changed, 24 insertions(+), 59 deletions(-) delete mode 100644 Guardfile create mode 100644 Rakefile diff --git a/Guardfile b/Guardfile deleted file mode 100644 index 4a1dc4de..00000000 --- a/Guardfile +++ /dev/null @@ -1,48 +0,0 @@ -# A sample Guardfile -# More info at https://github.com/guard/guard#readme - -context = Struct.new(:path) # default -=begin Context Object -context = Class.new do - def initialize(path) - end - # custom behaviour -end -=end - -locals = Hash.new({}) # default -=begin Local Variables -require 'yaml' -locals, path = {}, 'locals.yml' -def locals.reload - update YAML.load_file(path) -end -locals.reload -=end - -guard 'tilt', :context => context, :locals => locals do - # watch files with two extnames like index.html.erb - watch %r'.+go.erb' -end - -# Guard::Tilt.root = Dir.getwd # (default: Dir.getwd) - -=begin Output Path -class OuputPath < Guard::Tilt::OutputPath - - BASE = File.expand_path 'views' - ROOT = File.expand_path 'public' - - # By default Path#sanitize only strips an extname from itself. - # - # If you want to write the rendered output to another folder you can - # overwrite this method to return another Path object, like this: - def sanitize - super.sub BASE, ROOT - end - - # ... then set the OutputPath class. - Guard::Tilt.output_path = self - -end -=end diff --git a/README.md b/README.md index 86757757..73b580cc 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,16 @@ Development ERB Templating -------------- -Sometimes Go code can be repetitive especially with dealing with functions that only differ in the type (e.g. ReadInt16, ReadInt32, ReadInt64). Some of this repetition can be eliminated by using a template preprocessor. pgx uses Ruby erb templates. Files that end in .go.erb are used to produce the corresponding .go files. These files can be automatically processed with guard -- a Ruby file and directory watcher. +Sometimes Go code can be repetitive especially with dealing with functions that only differ in the type (e.g. ReadInt16, ReadInt32, ReadInt64). Some of this repetition can be eliminated by using a template preprocessor. pgx uses Ruby erb templates. Files that end in .go.erb are used to produce the corresponding .go files. These files are automatically automatically processed with [rake](https://github.com/jimweirich/rake). Prerequisites: * Ruby -* guard -* guard-tilt +* Rake -To automatically process .go.erb files open a shell in the pgx directory and run: +To automatically process .go.erb files and run the tests: - jack@hk-47~/dev/pgx$ guard + jack@hk-47~/dev/pgx$ rake test Testing ------- diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..0796d83f --- /dev/null +++ b/Rakefile @@ -0,0 +1,14 @@ +require 'rake/clean' + +ERB = FileList['*.go.erb'] +GO = ERB.ext +CLEAN.include(GO) + +rule '.go' => '.go.erb' do |t| + sh "erb #{t.source} > #{t.name}" +end + +desc "Run tests" +task :test => GO do + sh "go test" +end diff --git a/connection_select_column_test.go b/connection_select_column_test.go index 679151cd..ebfc2c08 100644 --- a/connection_select_column_test.go +++ b/connection_select_column_test.go @@ -23,6 +23,7 @@ func TestSelectAllString(t *testing.T) { } } + func TestSelectAllInt64(t *testing.T) { conn := getSharedConnection() @@ -108,6 +109,7 @@ func TestSelectAllInt16(t *testing.T) { } + func TestSelectAllFloat64(t *testing.T) { conn := getSharedConnection() diff --git a/connection_select_column_test.go.erb b/connection_select_column_test.go.erb index d048cf97..cdb7d1ac 100644 --- a/connection_select_column_test.go.erb +++ b/connection_select_column_test.go.erb @@ -51,7 +51,6 @@ func TestSelectAllInt<%= size %>(t *testing.T) { t.Error("Should have received error on null") } } - <% end %> <% [64, 32].each do |size| %> @@ -72,5 +71,4 @@ func TestSelectAllFloat<%= size %>(t *testing.T) { t.Error("Should have received error on null") } } - <% end %> diff --git a/connection_select_value_test.go b/connection_select_value_test.go index 0eb43502..5dfc3ee2 100644 --- a/connection_select_value_test.go +++ b/connection_select_value_test.go @@ -21,6 +21,7 @@ func TestSelectString(t *testing.T) { } } + func TestSelectInt64(t *testing.T) { conn := getSharedConnection() @@ -106,6 +107,7 @@ func TestSelectInt16(t *testing.T) { } + func TestSelectFloat64(t *testing.T) { conn := getSharedConnection() diff --git a/connection_select_value_test.go.erb b/connection_select_value_test.go.erb index 4c34bcec..20f8f1de 100644 --- a/connection_select_value_test.go.erb +++ b/connection_select_value_test.go.erb @@ -49,7 +49,6 @@ func TestSelectInt<%= size %>(t *testing.T) { t.Error("Should have received error on null") } } - <% end %> <% [64, 32].each do |size| %> @@ -70,5 +69,4 @@ func TestSelectFloat<%= size %>(t *testing.T) { t.Error("Should have received error on null") } } - <% end %> diff --git a/data_row_reader_test.go b/data_row_reader_test.go index 8c91d992..c4ee6600 100644 --- a/data_row_reader_test.go +++ b/data_row_reader_test.go @@ -22,6 +22,7 @@ func TestDataRowReaderReadString(t *testing.T) { } } + func TestDataRowReaderReadInt64(t *testing.T) { conn := getSharedConnection() @@ -77,6 +78,7 @@ func TestDataRowReaderReadInt16(t *testing.T) { } + func TestDataRowReaderReadFloat64(t *testing.T) { conn := getSharedConnection() diff --git a/data_row_reader_test.go.erb b/data_row_reader_test.go.erb index 28778660..f5d75a4b 100644 --- a/data_row_reader_test.go.erb +++ b/data_row_reader_test.go.erb @@ -40,7 +40,6 @@ func TestDataRowReaderReadInt<%= size %>(t *testing.T) { t.Error("Wrong value returned") } } - <% end %> <% [64, 32].each do |size| %> @@ -61,5 +60,4 @@ func TestDataRowReaderReadFloat<%= size %>(t *testing.T) { t.Error("Wrong value returned") } } - <% end %>