Need help passing arguments via Buildr - buildr

I am a newbie to Buildr(Apache Buildr), I am trying to run a junit test using buildr but I am not sure how to pass the arguments like -Djava.awt.headless=true etc..
I tried something like below, but doesn't seem to work
test.using( :java_args => ['-Djava.awt.headless:true'])
I am not sure if I need to pass this to system properties or JVM arguments, can someone help?

This is the right way but there's a small typo in your :java_args, it should be:
test.using :java_args => [ '-Djava.awt.headless=true' ]
(notice the equal sign after headless versus a colon in your question.)
There is also a more concise/foolproof way of passing properties using a hash of property names and values,
test.using :properties => { "java.awt.headless" => "true" }

Related

How can I pass string slices into Kingpin?

Here's the minimal example:
import "gopkg.in/alecthomas/kingpin.v2"
...
fooCodes = kingpin.Flag("foo_codes", "List of codes").Default().Strings()
and I tried passing --foo_codes=AA,BB,CC that didn't work unfortunately so I had to use
--foo_codes=AA
--foo_codes=BB
--foo_codes=CC
instead as a workaround (I'm passing those args in a yaml file. Is there a better option that I can configure via kingpin?
I guess you can use HintOptions or HintAction, for more details see these examples: https://github.com/alecthomas/kingpin/blob/master/_examples/completion/main.go

inspec - i want to output structured data to be parsed by another function

I have a inspec test, this is great:
inspec exec scratchpad/profiles/forum_profile --reporter yaml
Trouble is I want to run this in a script and output this to an array
I cannot find the documentation that indicated what method i need to use to simulate the same
I do this
def my_func
http_checker = Inspec::Runner.new()
http_checker.add_target('scratchpad/profiles/forum_profile')
http_checker.run
puts http_checker.report
So the report method seems to give me load of the equivalent type and much more - does anyone have any documentation or advice on returning the same output as the --reporter yaml type response but in a script? I want to parse the response so I can share output with another function
I've never touched inspec, so take the following with a grain of salt, but according to https://github.com/inspec/inspec/blob/master/lib/inspec/runner.rb#L140, you can provide reporter option while instantiating the runner. Looking at https://github.com/inspec/inspec/blob/master/lib/inspec/reporters.rb#L11 I think it should be smth. like ["yaml", {}]. So, could you please try
# ...
http_checker = Inspec::Runner.new(reporter: ["yaml", {}])
# ...
(chances are it will give you the desired output)

perl package statement and perl module locations

I am writing my first real Perl modules using Moo. But I am getting confused about package locations and package statements and "use".
I have a simple program in c:/temp:
use Roadmap::a;
print a->new->aa->[0] . "\n";
I have a simple module C:/bin/perl/perl/site/lib/Roadmap/a.pm, #INC has:
#INC:
C:/bin/perl/perl/site/lib
C:/bin/perl/perl/vendor/lib
C:/bin/perl/perl/lib
.
If a.pm is this:
package Roadmap::a;
use Moo;
use Types::Standard qw(ArrayRef);
has aa => (is => 'rw', isa => ArrayRef, default => sub{ [3] });
1;
It returns an error:
Can't locate object method "new" via package "a"
(perhaps you forgot to load "a"?) at e.pl line 2.
But if a.pm is this:
package a;
use Moo;
use Types::Standard qw(ArrayRef);
has aa => (is => 'rw', isa => ArrayRef, default => sub{ [3] });
1;
It succeeds and returns the answer '3'. What am I doing wrong? Shouldn't all modules have names of Somedir::Module ?? Thanks!
Update: this is module is simple enough that all I did was create the directory site/lib/Roadmap and place the a.pm file within it. Should I have instead tried to do some kind of perl module install on this simple module? For this simple example, it didn't seem like I needed to.
Update: if I replace "a->new()" with "Roadmap::a->new()" then my original example works. But I was hoping that with a package Somedir::Module, after doing the "use Somedir::Module" in my script, I could then just do Module->new() instead of Somedir::Module->new().
Update: continuing the conversation with myself, if I change the script to this format, it all works the way I want it to. (Of course I would never use a lowercase module name in practice, this is just for testing.)
use aliased 'Roadmap::a';
print a->new->aa->[0] . "\n";
So I guess I have now answered my own question.
"use aliased" solves the problem nicely.

JSON Parser Acts Differently

I am trying to parse the following string called result:
{
"status":0,
"id":"faxxxxx-1",
"hypotheses":[
{"utterance":"skateboard","confidence":0.90466744},
{"utterance":"skate board"},
{"utterance":"skateboarding"},
{"utterance":"skateboards"},
{"utterance":"skate bored"}
]
}
Using obj = JSON.parse(result) in Ruby 1.8 with the json gem.
The command in question is:
puts "#{obj['hypotheses'][0]}"
My old workstation (whose harddrive died) gave me:
{"utterance" => "skateboard", "confidence" => 0.90466744}
My current workstation gives me:
confidence0.90466744utteranceskateboard
The old workstation was not set up by me, so I don't know what kind of packages were installed, while this current one was.
Why is there a difference in the output of the exact same script?
How can I make the current one look like the old one?
I am completely new to this btw.
In Ruby 1.8, Hash#to_s simply joins all of the elements together without spaces, equivalent to to_a.flatten.join('').
In Ruby 1.9, Hash#to_s is an alias to inspect and produces well-formatted output.
To get the equivalent thing in both cases:
puts obj['hypotheses'][0].inspect
The same thing applies to Array.

How to pass parameters to MiniTest::Unit::TestCase suite?

I'm using an external API that takes a key string, and would like to pass this key string to the test suite. Something like:
rake test [key=api_key]
The code together with the tests will be open sourced, but I'm not allowed to distribute my key string to other users, so I cannot put it in the test file. Can I pass it as a parameter?
You have two options. Pass it as an environment variable:
API_KEY='key' rake test
You can then access this through the ENV object in your test:
key = ENV['API_KEY']
Second option is to put this key in a file (e.g. key.txt) and you read it from that. To ensure that you don't distribute that file with your code, add it to your .gitignore file (or whatever is the ignore file used by your SCM)
Thank you very much!
I actually was thinking of putting it into a file and gitignoring it, but ended up passing a parameter to rake. May be, I will combine both (it's a long key).
Modify the Rakefile code for the :test task, such as adding a
parameter to it.
task :test, :key do |t, k|
result = system("ruby -Ilib -Itest -e 'ARGV.each { |f| load(f) if File.exists?(f)}' test/unit/* '#{k[:key]}'")
exit(result ? 0 : 1)
end
Call rake test['blah-blah']
It may take more then one key if needed.

Resources