Print usage on invalid task option; fix a couple more tests

This commit is contained in:
Josh Holtrop 2022-01-26 22:10:22 -05:00
parent 679c013eaa
commit 2a9ccc2346
3 changed files with 6 additions and 15 deletions

View File

@ -4,7 +4,7 @@ class DebugBuilder < Rscons::Builder
finalize_command finalize_command
else else
@command = %W[gcc -c -o #{@target} #{@sources.first}] @command = %W[gcc -c -o #{@target} #{@sources.first}]
if ENV["command_change"] == "command_change" if ENV["test"] == "command_change"
@command += %w[-Wall] @command += %w[-Wall]
end end
if ENV["test"] == "new_dep" if ENV["test"] == "new_dep"

View File

@ -41,6 +41,7 @@ module Rscons
end end
unless valid_arg unless valid_arg
$stderr.puts "Invalid task '#{task}' argument '#{argv[0].split("=").first}'" $stderr.puts "Invalid task '#{task}' argument '#{argv[0].split("=").first}'"
$stderr.puts usage
exit 2 exit 2
end end
else else

View File

@ -89,7 +89,7 @@ describe Rscons do
end end
def run_rscons(options = {}) def run_rscons(options = {})
args = options[:args] || [] args = Array(options[:args]) || []
if ENV["dist_specs"] if ENV["dist_specs"]
exe = "#{@owd}/test/rscons.rb" exe = "#{@owd}/test/rscons.rb"
else else
@ -1754,10 +1754,10 @@ EOF
expect(result.status).to_not eq 0 expect(result.status).to_not eq 0
end end
it "outputs an error for an unknown operation" do it "outputs an error for an unknown task" do
test_dir "simple" test_dir "simple"
result = run_rscons(args: "unknownop") result = run_rscons(args: "unknownop")
expect(result.stderr).to match /Unknown operation: unknownop/ expect(result.stderr).to match /Task 'unknownop' not found/
expect(result.status).to_not eq 0 expect(result.status).to_not eq 0
end end
@ -1774,7 +1774,7 @@ EOF
test_dir "simple" test_dir "simple"
result = run_rscons(args: %w[configure --xyz]) result = run_rscons(args: %w[configure --xyz])
expect(result.stderr).to_not match /Traceback/ expect(result.stderr).to_not match /Traceback/
expect(result.stderr).to match /invalid option.*--xyz/ expect(result.stderr).to match /Invalid task 'configure' argument.*--xyz/
expect(result.stderr).to match /Usage:/ expect(result.stderr).to match /Usage:/
expect(result.status).to_not eq 0 expect(result.status).to_not eq 0
end end
@ -2424,16 +2424,6 @@ EOF
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(result.stdout).to match /gcc.*-o.*simple/ expect(result.stdout).to match /gcc.*-o.*simple/
end end
it "prints operation start time" do
test_dir("simple")
result = run_rscons(args: %w[-v])
expect(result.stderr).to eq ""
expect(result.stdout).to match /Starting 'configure' at/
expect(result.stdout).to match /Starting 'build' at/
expect(result.stdout).to match /'build' complete at/
expect(result.stdout).to_not match /'configure' complete at/
end
end end
context "direct mode" do context "direct mode" do