-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Minitest - all", | ||
"type": "Ruby", | ||
"request": "launch", | ||
"useBundler": true, | ||
"cwd": "${workspaceRoot}", | ||
"program": "/usr/bin/rake", | ||
"args": ["test"] | ||
}, | ||
{ | ||
"name": "Minitest - active tasks only", | ||
"type": "Ruby", | ||
"request": "launch", | ||
"useBundler": true, | ||
"cwd": "${workspaceRoot}", | ||
"program": "${file}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'autoproj/cli/inspection_tool' | ||
module Autoproj | ||
module CLI | ||
class Which < InspectionTool | ||
def run(cmd) | ||
initialize_and_load | ||
finalize_setup(Array.new) | ||
|
||
# Resolve the command using the PATH if present | ||
env = ws.full_env | ||
absolute = | ||
if Pathname.new(cmd).absolute? | ||
File.expand_path(cmd) | ||
else | ||
env.find_in_path(cmd) | ||
end | ||
|
||
if absolute | ||
if !File.file?(absolute) | ||
Autoproj.error "given command `#{absolute}` does not exist" | ||
exit 1 | ||
else | ||
puts absolute | ||
end | ||
else | ||
Autoproj.error "cannot resolve `#{cmd}` in the workspace" | ||
exit 1 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'autoproj/test' | ||
require 'autoproj/cli/which' | ||
|
||
module Autoproj | ||
module CLI | ||
describe Which do | ||
include Autoproj::SelfTest; | ||
before do | ||
ws_create | ||
@cli = Which.new(ws) | ||
flexmock(@cli).should_receive(:initialize_and_load) | ||
end | ||
|
||
it "displays a given full path if it exists, regardless of PATH" do | ||
ws.env.clear 'PATH' | ||
path = File.join(ws.root_dir, 'test') | ||
FileUtils.touch path | ||
out, err = capture_io do | ||
@cli.run path | ||
end | ||
assert_equal "#{path}\n", out | ||
end | ||
|
||
it "displays an error if a given full path does not exist, and exits with error" do | ||
path = File.join(ws.root_dir, 'test') | ||
flexmock(Autoproj).should_receive(:error).with("given command `#{path}` does not exist"). | ||
once | ||
assert_raises(SystemExit) do | ||
@cli.run path | ||
end | ||
end | ||
|
||
it "displays the resolved full path if found" do | ||
ws.env.set 'PATH', ws.root_dir | ||
path = File.join(ws.root_dir, 'test') | ||
FileUtils.touch path | ||
out, err = capture_io do | ||
@cli.run 'test' | ||
end | ||
assert_equal "#{path}\n", out | ||
end | ||
|
||
it "displays an error if the path cannot be resolved, and exits with error" do | ||
flexmock(Autoproj).should_receive(:error).with("cannot resolve `test` in the workspace"). | ||
once | ||
assert_raises(SystemExit) do | ||
@cli.run 'test' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|