From 2f83f3665926f8d4b26d82604a3e13aca95105b8 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 10 Sep 2018 20:35:00 -0400 Subject: [PATCH] start adding subcommand interface to Cli module --- lib/rscons/cli.rb | 54 ++++-- spec/build_tests_spec.rb | 343 +++++++++++++++++++++------------------ 2 files changed, 226 insertions(+), 171 deletions(-) diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index bcdbb73..1280fd8 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -1,6 +1,31 @@ require "rscons" require "optparse" +USAGE = < :bar})).to be_truthy @@ -602,19 +623,19 @@ EOF it "considers deep dependencies when deciding whether to rerun Preprocess builder" do test_dir("preprocess") - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(result.stdout).to eq("Preprocess pp\n") expect(File.read("pp")).to match(%r{xyz42abc}m) - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(result.stdout).to eq "" File.open("bar.h", "w") do |fh| fh.puts "#define BAR abc88xyz" end - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(result.stdout).to eq("Preprocess pp\n") expect(File.read("pp")).to match(%r{abc88xyz}m) @@ -622,7 +643,7 @@ EOF it "allows construction variable references which expand to arrays in sources of a build target" do test_dir("simple") - result = run_test(rsconsfile: "cvar_array.rb") + result = run_rscons(rsconsfile: "cvar_array.rb") expect(result.stderr).to eq "" expect(File.exists?("build/simple.o")).to be_truthy expect(`./simple.exe`).to eq "This is a simple C program\n" @@ -630,7 +651,7 @@ EOF it "supports registering multiple build targets with the same target path" do test_dir("build_dir") - result = run_test(rsconsfile: "multiple_targets_same_name.rb") + result = run_rscons(rsconsfile: "multiple_targets_same_name.rb") expect(result.stderr).to eq "" expect(File.exists?("one.o")).to be_truthy expect(lines(result.stdout)).to eq([ @@ -641,7 +662,7 @@ EOF it "expands target and source paths when builders are registered in build hooks" do test_dir("build_dir") - result = run_test(rsconsfile: "post_build_hook_expansion.rb") + result = run_rscons(rsconsfile: "post_build_hook_expansion.rb") expect(result.stderr).to eq "" expect(File.exists?("one.o")).to be_truthy expect(File.exists?("two.o")).to be_truthy @@ -656,14 +677,14 @@ EOF File.open("two.c", "w") do |fh| fh.puts("FOO") end - result = run_test(rsconsfile: "cache_successful_builds_when_one_fails.rb", + result = run_rscons(rsconsfile: "cache_successful_builds_when_one_fails.rb", rscons_args: %w[-j1]) expect(result.stderr).to match /FOO/ expect(File.exists?("simple.o")).to be_truthy expect(File.exists?("two.o")).to be_falsey File.open("two.c", "w") {|fh|} - result = run_test(rsconsfile: "cache_successful_builds_when_one_fails.rb", + result = run_rscons(rsconsfile: "cache_successful_builds_when_one_fails.rb", rscons_args: %w[-j1]) expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ @@ -673,7 +694,7 @@ EOF it "allows overriding PROGSUFFIX" do test_dir("simple") - result = run_test(rsconsfile: "progsuffix.rb") + result = run_rscons(rsconsfile: "progsuffix.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC build/simple.o", @@ -683,7 +704,7 @@ EOF it "does not use PROGSUFFIX when the Program target name expands to a value already containing an extension" do test_dir("simple") - result = run_test(rsconsfile: "progsuffix2.rb") + result = run_rscons(rsconsfile: "progsuffix2.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC build/simple.o", @@ -693,7 +714,7 @@ EOF it "allows overriding PROGSUFFIX from extra vars passed in to the builder" do test_dir("simple") - result = run_test(rsconsfile: "progsuffix3.rb") + result = run_rscons(rsconsfile: "progsuffix3.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC build/simple.o", @@ -703,7 +724,7 @@ EOF it "creates object files under the build root for absolute source paths" do test_dir("simple") - result = run_test(rsconsfile: "absolute_source_path.rb") + result = run_rscons(rsconsfile: "absolute_source_path.rb") expect(result.stderr).to eq "" slines = lines(result.stdout) expect(slines[0]).to match(%r{^CC build/.*/abs\.o$}) @@ -713,7 +734,7 @@ EOF it "creates shared libraries" do test_dir("shared_library") - result = run_test + result = run_rscons expect(result.stderr).to eq "" slines = lines(result.stdout) if RUBY_PLATFORM =~ /mingw/ @@ -724,7 +745,7 @@ EOF expect(File.exists?("libmine.so")).to be_truthy end - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -736,7 +757,7 @@ EOF it "creates shared libraries using C++" do test_dir("shared_library") - result = run_test(rsconsfile: "shared_library_cxx.rb") + result = run_rscons(rsconsfile: "shared_library_cxx.rb") expect(result.stderr).to eq "" slines = lines(result.stdout) if RUBY_PLATFORM =~ /mingw/ @@ -745,7 +766,7 @@ EOF expect(slines).to include("SHLD libmine.so") end - result = run_test(rsconsfile: "shared_library_cxx.rb") + result = run_rscons(rsconsfile: "shared_library_cxx.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -756,27 +777,27 @@ EOF it "raises an error for a circular dependency" do test_dir("simple") - result = run_test(rsconsfile: "error_circular_dependency.rb") + result = run_rscons(rsconsfile: "error_circular_dependency.rb") expect(result.stderr).to match /Possible circular dependency for (foo|bar|baz)/ expect(result.status).to_not eq 0 end it "raises an error for a circular dependency where a build target contains itself in its source list" do test_dir("simple") - result = run_test(rsconsfile: "error_circular_dependency2.rb") + result = run_rscons(rsconsfile: "error_circular_dependency2.rb") expect(result.stderr).to match /Possible circular dependency for foo/ expect(result.status).to_not eq 0 end it "orders builds to respect user dependencies" do test_dir("simple") - result = run_test(rsconsfile: "user_dep_build_order.rb", rscons_args: %w[-j4]) + result = run_rscons(rsconsfile: "user_dep_build_order.rb", rscons_args: %w[-j4]) expect(result.stderr).to eq "" end it "waits for all parallelized builds to complete if one fails" do test_dir("simple") - result = run_test(rsconsfile: "wait_for_builds_on_failure.rb", rscons_args: %w[-j4]) + result = run_rscons(rsconsfile: "wait_for_builds_on_failure.rb", rscons_args: %w[-j4]) expect(result.status).to_not eq 0 expect(result.stderr).to match /Failed to build foo_1/ expect(result.stderr).to match /Failed to build foo_2/ @@ -786,7 +807,7 @@ EOF it "clones n_threads attribute when cloning an Environment" do test_dir("simple") - result = run_test(rsconsfile: "clone_n_threads.rb") + result = run_rscons(rsconsfile: "clone_n_threads.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["165"] end @@ -794,7 +815,7 @@ EOF it "prints a builder's short description with 'command' echo mode if there is no command" do test_dir("build_dir") - result = run_test(rsconsfile: "echo_command_ruby_builder.rb") + result = run_rscons(rsconsfile: "echo_command_ruby_builder.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["Install inst.exe"] end @@ -802,7 +823,7 @@ EOF it "supports a string for a builder's echoed 'command' with Environment#print_builder_run_message" do test_dir("build_dir") - result = run_test(rsconsfile: "echo_command_string.rb") + result = run_rscons(rsconsfile: "echo_command_string.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["MyBuilder foo command"] end @@ -810,7 +831,7 @@ EOF context "colored output" do it "does not output in color with --color=off" do test_dir("simple") - result = run_test(rscons_args: %w[--color=off]) + result = run_rscons(rscons_args: %w[--color=off]) expect(result.stderr).to eq "" expect(result.stdout).to_not match(/\e\[/) end @@ -818,14 +839,14 @@ EOF it "displays output in color with --color=force" do test_dir("simple") - result = run_test(rscons_args: %w[--color=force]) + result = run_rscons(rscons_args: %w[--color=force]) expect(result.stderr).to eq "" expect(result.stdout).to match(/\e\[/) File.open("simple.c", "wb") do |fh| fh.write("foobar") end - result = run_test(rscons_args: %w[--color=force]) + result = run_rscons(rscons_args: %w[--color=force]) expect(result.stderr).to match(/\e\[/) end end @@ -833,7 +854,7 @@ EOF context "backward compatibility" do it "allows a builder to call Environment#run_builder in a non-threaded manner" do test_dir("simple") - result = run_test(rsconsfile: "run_builder.rb") + result = run_rscons(rsconsfile: "run_builder.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC simple.o", @@ -843,7 +864,7 @@ EOF it "allows a builder to call Environment#build_sources in a non-threaded manner" do test_dir("simple") - result = run_test(rsconsfile: "build_sources.rb") + result = run_rscons(rsconsfile: "build_sources.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC simple.o", @@ -861,7 +882,7 @@ void one() } EOF end - result = run_test(rsconsfile: "build_sources.rb") + result = run_rscons(rsconsfile: "build_sources.rb") expect(result.status).to_not eq 0 expect(result.stderr).to match /main/ expect(result.stdout).to match /Failed command was: gcc/ @@ -872,27 +893,27 @@ EOF File.open("simple.c", "wb") do |fh| fh.write("FOOBAR") end - result = run_test(rsconsfile: "run_builder.rb") + result = run_rscons(rsconsfile: "run_builder.rb") expect(result.stderr).to match /Failed to build/ expect(result.stdout).to match /Failed command was: gcc/ end it "supports builders that call Builder#standard_build" do test_dir("simple") - result = run_test(rsconsfile: "standard_build.rb") + result = run_rscons(rsconsfile: "standard_build.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["MyCommand simple.o"] end it "supports the old 3-parameter signature to Builder#produces?" do test_dir("simple") - result = run_test(rsconsfile: "bc_produces.rb") + result = run_rscons(rsconsfile: "bc_produces.rb") expect(result.stderr).to eq "" end it 'supports build hooks to override construction variables' do test_dir("build_dir") - result = run_test(rsconsfile: "backward_compatible_build_hooks.rb") + result = run_rscons(rsconsfile: "backward_compatible_build_hooks.rb") expect(result.stderr).to eq "" expect(Set[*lines(result.stdout)]).to eq Set[ 'gcc -c -o one.o -MMD -MF one.mf -MT TARGET -Isrc -Isrc/one -Isrc/two -O1 src/two/two.c', @@ -907,21 +928,21 @@ EOF it "builds a .c file using flex and bison" do test_dir("cfile") - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(Set[*lines(result.stdout)]).to eq Set[ "LEX lexer.c", "YACC parser.c", ] - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(result.stdout).to eq "" end it "raises an error when an unknown source file is specified" do test_dir("cfile") - result = run_test(rsconsfile: "error_unknown_extension.rb") + result = run_rscons(rsconsfile: "error_unknown_extension.rb") expect(result.stderr).to match /Unknown source file .foo.bar. for CFile builder/ expect(result.status).to_not eq 0 end @@ -931,12 +952,12 @@ EOF it "allows executing an arbitrary command" do test_dir('simple') - result = run_test(rsconsfile: "command_builder.rb") + result = run_rscons(rsconsfile: "command_builder.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["BuildIt simple.exe"] expect(`./simple.exe`).to eq "This is a simple C program\n" - result = run_test(rsconsfile: "command_builder.rb") + result = run_rscons(rsconsfile: "command_builder.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" end @@ -944,7 +965,7 @@ EOF it "allows redirecting standard output to a file" do test_dir("simple") - result = run_test(rsconsfile: "command_redirect.rb") + result = run_rscons(rsconsfile: "command_redirect.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC simple.o", @@ -957,7 +978,7 @@ EOF context "Directory builder" do it "creates the requested directory" do test_dir("simple") - result = run_test(rsconsfile: "directory.rb") + result = run_rscons(rsconsfile: "directory.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq(["Directory teh_dir"]) expect(File.directory?("teh_dir")).to be_truthy @@ -966,7 +987,7 @@ EOF it "succeeds when the requested directory already exists" do test_dir("simple") FileUtils.mkdir("teh_dir") - result = run_test(rsconsfile: "directory.rb") + result = run_rscons(rsconsfile: "directory.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" expect(File.directory?("teh_dir")).to be_truthy @@ -975,7 +996,7 @@ EOF it "fails when the target path is a file" do test_dir("simple") FileUtils.touch("teh_dir") - result = run_test(rsconsfile: "directory.rb") + result = run_rscons(rsconsfile: "directory.rb") expect(result.stderr).to match %r{Error: `teh_dir' already exists and is not a directory} end end @@ -984,11 +1005,11 @@ EOF it "copies a file to the target file name" do test_dir("build_dir") - result = run_test(rsconsfile: "install.rb") + result = run_rscons(rsconsfile: "install.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["Install inst.exe"] - result = run_test(rsconsfile: "install.rb") + result = run_rscons(rsconsfile: "install.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -996,7 +1017,7 @@ EOF expect(File.read("inst.exe", mode: "rb")).to eq(File.read("install.rb", mode: "rb")) FileUtils.rm("inst.exe") - result = run_test(rsconsfile: "install.rb") + result = run_rscons(rsconsfile: "install.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["Install inst.exe"] end @@ -1004,11 +1025,11 @@ EOF it "operates the same as a Copy builder" do test_dir("build_dir") - result = run_test(rsconsfile: "copy.rb") + result = run_rscons(rsconsfile: "copy.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["Copy inst.exe"] - result = run_test(rsconsfile: "copy.rb") + result = run_rscons(rsconsfile: "copy.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -1016,7 +1037,7 @@ EOF expect(File.read("inst.exe", mode: "rb")).to eq(File.read("copy.rb", mode: "rb")) FileUtils.rm("inst.exe") - result = run_test(rsconsfile: "copy.rb") + result = run_rscons(rsconsfile: "copy.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["Copy inst.exe"] end @@ -1024,20 +1045,20 @@ EOF it "copies a file to the target directory name" do test_dir "build_dir" - result = run_test(rsconsfile: "install_directory.rb") + result = run_rscons(rsconsfile: "install_directory.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to include("Install inst") expect(File.exists?("inst/install_directory.rb")).to be_truthy expect(File.read("inst/install_directory.rb", mode: "rb")).to eq(File.read("install_directory.rb", mode: "rb")) - result = run_test(rsconsfile: "install_directory.rb") + result = run_rscons(rsconsfile: "install_directory.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" end it "copies a directory to the non-existent target directory name" do test_dir "build_dir" - result = run_test(rsconsfile: "install_directory.rb") + result = run_rscons(rsconsfile: "install_directory.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to include("Install noexist/src") %w[src/one/one.c src/two/two.c src/two/two.h].each do |f| @@ -1048,7 +1069,7 @@ EOF it "copies a directory to the existent target directory name" do test_dir "build_dir" - result = run_test(rsconsfile: "install_directory.rb") + result = run_rscons(rsconsfile: "install_directory.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to include("Install exist/src") %w[src/one/one.c src/two/two.c src/two/two.h].each do |f| @@ -1062,7 +1083,7 @@ EOF it "allows specifying a Symbol as a target name and reruns the builder if the sources or command have changed" do test_dir("simple") - result = run_test(rsconsfile: "phony_target.rb") + result = run_rscons(rsconsfile: "phony_target.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq([ "CC build/simple.o", @@ -1070,7 +1091,7 @@ EOF "Checker simple.exe", ]) - result = run_test(rsconsfile: "phony_target.rb") + result = run_rscons(rsconsfile: "phony_target.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -1079,7 +1100,7 @@ EOF File.open("simple.exe", "w") do |fh| fh.puts "Changed simple.exe" end - result = run_test(rsconsfile: "phony_target2.rb") + result = run_rscons(rsconsfile: "phony_target2.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq([ "Checker simple.exe", @@ -1090,7 +1111,7 @@ EOF context "Environment#clear_targets" do it "clears registered targets" do test_dir("simple") - result = run_test(rsconsfile: "clear_targets.rb") + result = run_rscons(rsconsfile: "clear_targets.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" end @@ -1102,16 +1123,16 @@ EOF File.open(Rscons::Cache::CACHE_FILE, "w") do |fh| fh.puts("[1]") end - result = run_test + result = run_rscons expect(result.stderr).to match /Warning.*was corrupt. Contents:/ end it "removes the cache file on a clean operation" do test_dir("simple") - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(File.exists?(Rscons::Cache::CACHE_FILE)).to be_truthy - result = run_test(rscons_args: %w[-c]) + result = run_rscons(op: %w[clean]) expect(result.stderr).to eq "" expect(File.exists?(Rscons::Cache::CACHE_FILE)).to be_falsey end @@ -1119,7 +1140,7 @@ EOF it "forces a build when the target file does not exist and is not in the cache" do test_dir("simple") expect(File.exists?("simple.exe")).to be_falsey - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(File.exists?("simple.exe")).to be_truthy end @@ -1129,7 +1150,7 @@ EOF File.open("simple.exe", "wb") do |fh| fh.write("hi") end - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(File.exists?("simple.exe")).to be_truthy expect(File.read("simple.exe", mode: "rb")).to_not eq "hi" @@ -1137,13 +1158,13 @@ EOF it "forces a build when the target file exists and is in the cache but has changed since cached" do test_dir("simple") - result = run_test + result = run_rscons expect(result.stderr).to eq "" File.open("simple.exe", "wb") do |fh| fh.write("hi") end test_dir("simple") - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(File.exists?("simple.exe")).to be_truthy expect(File.read("simple.exe", mode: "rb")).to_not eq "hi" @@ -1152,14 +1173,14 @@ EOF it "forces a build when the command changes" do test_dir("simple") - result = run_test + result = run_rscons expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC build/simple.o", "LD simple.exe", ] - result = run_test(rsconsfile: "cache_command_change.rb") + result = run_rscons(rsconsfile: "cache_command_change.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "LD simple.exe", @@ -1169,14 +1190,14 @@ EOF it "forces a build when there is a new dependency" do test_dir("simple") - result = run_test(rsconsfile: "cache_new_dep1.rb") + result = run_rscons(rsconsfile: "cache_new_dep1.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC simple.o", "LD simple.exe", ] - result = run_test(rsconsfile: "cache_new_dep2.rb") + result = run_rscons(rsconsfile: "cache_new_dep2.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "LD simple.exe", @@ -1186,14 +1207,14 @@ EOF it "forces a build when a dependency's checksum has changed" do test_dir("simple") - result = run_test(rsconsfile: "cache_dep_checksum_change.rb") + result = run_rscons(rsconsfile: "cache_dep_checksum_change.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["Copy simple.copy"] File.open("simple.c", "wb") do |fh| fh.write("hi") end - result = run_test(rsconsfile: "cache_dep_checksum_change.rb") + result = run_rscons(rsconsfile: "cache_dep_checksum_change.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq ["Copy simple.copy"] end @@ -1204,18 +1225,18 @@ EOF File.open("sources", "wb") do |fh| fh.write("one.o two.o") end - result = run_test(rsconsfile: "cache_strict_deps.rb") + result = run_rscons(rsconsfile: "cache_strict_deps.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to include "gcc -o program.exe one.o two.o" - result = run_test(rsconsfile: "cache_strict_deps.rb") + result = run_rscons(rsconsfile: "cache_strict_deps.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" File.open("sources", "wb") do |fh| fh.write("two.o one.o") end - result = run_test(rsconsfile: "cache_strict_deps.rb") + result = run_rscons(rsconsfile: "cache_strict_deps.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to include "gcc -o program.exe one.o two.o" end @@ -1225,7 +1246,7 @@ EOF File.open("foo", "wb") {|fh| fh.write("hi")} File.open("user_deps", "wb") {|fh| fh.write("")} - result = run_test(rsconsfile: "cache_user_dep.rb") + result = run_rscons(rsconsfile: "cache_user_dep.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC build/simple.o", @@ -1233,7 +1254,7 @@ EOF ] File.open("user_deps", "wb") {|fh| fh.write("foo")} - result = run_test(rsconsfile: "cache_user_dep.rb") + result = run_rscons(rsconsfile: "cache_user_dep.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "LD simple.exe", @@ -1245,19 +1266,19 @@ EOF File.open("foo", "wb") {|fh| fh.write("hi")} File.open("user_deps", "wb") {|fh| fh.write("foo")} - result = run_test(rsconsfile: "cache_user_dep.rb") + result = run_rscons(rsconsfile: "cache_user_dep.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "CC build/simple.o", "LD simple.exe", ] - result = run_test(rsconsfile: "cache_user_dep.rb") + result = run_rscons(rsconsfile: "cache_user_dep.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" File.open("foo", "wb") {|fh| fh.write("hi2")} - result = run_test(rsconsfile: "cache_user_dep.rb") + result = run_rscons(rsconsfile: "cache_user_dep.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "LD simple.exe", @@ -1266,12 +1287,12 @@ EOF it "allows a VarSet to be passed in as the command parameter" do test_dir("simple") - result = run_test(rsconsfile: "cache_varset.rb") + result = run_rscons(rsconsfile: "cache_varset.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "TestBuilder foo", ] - result = run_test(rsconsfile: "cache_varset.rb") + result = run_rscons(rsconsfile: "cache_varset.rb") expect(result.stderr).to eq "" expect(result.stdout).to eq "" end @@ -1279,62 +1300,62 @@ EOF context "debugging" do it "prints a message when the target does not exist" do test_dir("simple") - result = run_test(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb") expect(result.stdout).to match /Target foo\.o needs rebuilding because it does not exist on disk/ end it "prints a message when there is no cached build information for the target" do test_dir("simple") FileUtils.touch("foo.o") - result = run_test(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb") expect(result.stdout).to match /Target foo\.o needs rebuilding because there is no cached build information for it/ end it "prints a message when the target file has changed on disk" do test_dir("simple") - result = run_test(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb") File.open("foo.o", "wb") {|fh| fh.puts "hi"} - result = run_test(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb") expect(result.stdout).to match /Target foo\.o needs rebuilding because it has been changed on disk since being built last/ end it "prints a message when the command has changed" do test_dir("simple") - result = run_test(rsconsfile: "cache_debugging.rb") - result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[command_change=yes]) + result = run_rscons(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb", op: %w[build command_change=yes]) expect(result.stdout).to match /Target foo\.o needs rebuilding because the command used to build it has changed/ end it "prints a message when strict_deps is in use and the set of dependencies does not match" do test_dir("simple") - result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[strict_deps1=yes]) - result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[strict_deps2=yes]) + result = run_rscons(rsconsfile: "cache_debugging.rb", op: %w[build strict_deps1=yes]) + result = run_rscons(rsconsfile: "cache_debugging.rb", op: %w[build strict_deps2=yes]) expect(result.stdout).to match /Target foo\.o needs rebuilding because the :strict_deps option is given and the set of dependencies does not match the previous set of dependencies/ end it "prints a message when there is a new dependency" do test_dir("simple") - result = run_test(rsconsfile: "cache_debugging.rb") - result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[new_dep=yes]) + result = run_rscons(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb", op: %w[build new_dep=yes]) expect(result.stdout).to match /Target foo\.o needs rebuilding because there are new dependencies/ end it "prints a message when there is a new user-specified dependency" do test_dir("simple") - result = run_test(rsconsfile: "cache_debugging.rb") - result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[new_user_dep=yes]) + result = run_rscons(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb", op: %w[build new_user_dep=yes]) expect(result.stdout).to match /Target foo\.o needs rebuilding because the set of user-specified dependency files has changed/ end it "prints a message when a dependency file has changed" do test_dir("simple") - result = run_test(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb") f = File.read("simple.c", mode: "rb") f += "\n" File.open("simple.c", "wb") do |fh| fh.write(f) end - result = run_test(rsconsfile: "cache_debugging.rb") + result = run_rscons(rsconsfile: "cache_debugging.rb") expect(result.stdout).to match /Target foo\.o needs rebuilding because dependency file simple\.c has changed/ end end @@ -1343,7 +1364,7 @@ EOF context "Object builder" do it "allows overriding CCCMD construction variable" do test_dir("simple") - result = run_test(rsconsfile: "override_cccmd.rb") + result = run_rscons(rsconsfile: "override_cccmd.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "gcc -c -o simple.o -Dfoobar simple.c", @@ -1352,7 +1373,7 @@ EOF it "allows overriding DEPFILESUFFIX construction variable" do test_dir("simple") - result = run_test(rsconsfile: "override_depfilesuffix.rb") + result = run_rscons(rsconsfile: "override_depfilesuffix.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to eq [ "gcc -c -o simple.o -MMD -MF simple.deppy -MT TARGET simple.c", @@ -1361,7 +1382,7 @@ EOF it "raises an error when given a source file with an unknown suffix" do test_dir("simple") - result = run_test(rsconsfile: "error_unknown_suffix.rb") + result = run_rscons(rsconsfile: "error_unknown_suffix.rb") expect(result.stderr).to match /unknown input file type: "foo.xyz"/ end end @@ -1369,7 +1390,7 @@ EOF context "SharedObject builder" do it "raises an error when given a source file with an unknown suffix" do test_dir("shared_library") - result = run_test(rsconsfile: "error_unknown_suffix.rb") + result = run_rscons(rsconsfile: "error_unknown_suffix.rb") expect(result.stderr).to match /unknown input file type: "foo.xyz"/ end end @@ -1377,7 +1398,7 @@ EOF context "Library builder" do it "allows overriding ARCMD construction variable" do test_dir("library") - result = run_test(rsconsfile: "override_arcmd.rb") + result = run_rscons(rsconsfile: "override_arcmd.rb") expect(result.stderr).to eq "" expect(lines(result.stdout)).to include "ar rcf lib.a build/one.o build/three.o build/two.o" end @@ -1387,7 +1408,7 @@ EOF it "allows explicitly specifying SHLD construction variable value" do test_dir("shared_library") - result = run_test(rsconsfile: "shared_library_set_shld.rb") + result = run_rscons(rsconsfile: "shared_library_set_shld.rb") expect(result.stderr).to eq "" slines = lines(result.stdout) if RUBY_PLATFORM =~ /mingw/ @@ -1402,7 +1423,7 @@ EOF it "waits for subcommands in threads for builders that support threaded commands" do test_dir("simple") start_time = Time.new - result = run_test(rsconsfile: "threading.rb", rscons_args: %w[-j 4]) + result = run_rscons(rsconsfile: "threading.rb", rscons_args: %w[-j 4]) expect(result.stderr).to eq "" expect(Set[*lines(result.stdout)]).to eq Set[ "ThreadedTestBuilder a", @@ -1416,13 +1437,13 @@ EOF it "allows the user to specify that a target be built after another" do test_dir("custom_builder") - result = run_test(rsconsfile: "build_after.rb", rscons_args: %w[-j 4]) + result = run_rscons(rsconsfile: "build_after.rb", rscons_args: %w[-j 4]) expect(result.stderr).to eq "" end it "allows the user to specify side-effect files produced by another builder" do test_dir("custom_builder") - result = run_test(rsconsfile: "produces.rb", rscons_args: %w[-j 4]) + result = run_rscons(rsconsfile: "produces.rb", rscons_args: %w[-j 4]) expect(result.stderr).to eq "" expect(File.exists?("copy_inc.h")).to be_truthy end @@ -1431,7 +1452,7 @@ EOF context "CLI" do it "shows the version number and exits with --version argument" do test_dir("simple") - result = run_test(rscons_args: %w[--version]) + result = run_rscons(rscons_args: %w[--version]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /version #{Rscons::VERSION}/ @@ -1439,7 +1460,7 @@ EOF it "shows CLI help and exits with --help argument" do test_dir("simple") - result = run_test(rscons_args: %w[--help]) + result = run_rscons(rscons_args: %w[--help]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Usage:/ @@ -1448,14 +1469,14 @@ EOF it "prints an error and exits with an error status when a default Rsconsfile cannot be found" do test_dir("simple") FileUtils.rm_f("Rsconsfile") - result = run_test + result = run_rscons expect(result.stderr).to match /Could not find the Rsconsfile to execute/ expect(result.status).to_not eq 0 end it "prints an error and exits with an error status when the given Rsconsfile cannot be read" do test_dir("simple") - result = run_test(rsconsfile: "nonexistent") + result = run_rscons(rsconsfile: "nonexistent") expect(result.stderr).to match /Cannot read nonexistent/ expect(result.status).to_not eq 0 end