135375f98Sopenharmony_ci 235375f98Sopenharmony_cirequire '../auto/generate_module.rb' 335375f98Sopenharmony_cirequire 'fileutils' 435375f98Sopenharmony_ci 535375f98Sopenharmony_cidef touch_src(file) 635375f98Sopenharmony_ci FileUtils.touch "sandbox/src/#{file}" 735375f98Sopenharmony_ciend 835375f98Sopenharmony_ci 935375f98Sopenharmony_cidef touch_test(file) 1035375f98Sopenharmony_ci FileUtils.touch "sandbox/test/#{file}" 1135375f98Sopenharmony_ciend 1235375f98Sopenharmony_ci 1335375f98Sopenharmony_cidef create_src_with_known_content(file) 1435375f98Sopenharmony_ci File.open("sandbox/src/#{file}", "w") {|f| f.write("the original #{file}")} 1535375f98Sopenharmony_ciend 1635375f98Sopenharmony_ci 1735375f98Sopenharmony_cidef create_test_with_known_content(file) 1835375f98Sopenharmony_ci File.open("sandbox/test/#{file}", "w") {|f| f.write("the original #{file}")} 1935375f98Sopenharmony_ciend 2035375f98Sopenharmony_ci 2135375f98Sopenharmony_cidef expect_src_content_didnt_change(file) 2235375f98Sopenharmony_ci expect(File.read("sandbox/src/#{file}")).to eq("the original #{file}") 2335375f98Sopenharmony_ciend 2435375f98Sopenharmony_ci 2535375f98Sopenharmony_cidef expect_test_content_didnt_change(file) 2635375f98Sopenharmony_ci expect(File.read("sandbox/test/#{file}")).to eq("the original #{file}") 2735375f98Sopenharmony_ciend 2835375f98Sopenharmony_ci 2935375f98Sopenharmony_cidef expect_src_file_to_exist(file) 3035375f98Sopenharmony_ci expect(File.exist?("sandbox/src/#{file}")).to be true 3135375f98Sopenharmony_ciend 3235375f98Sopenharmony_ci 3335375f98Sopenharmony_cidef expect_test_file_to_exist(file) 3435375f98Sopenharmony_ci expect(File.exist?("sandbox/test/#{file}")).to be true 3535375f98Sopenharmony_ciend 3635375f98Sopenharmony_ci 3735375f98Sopenharmony_cidescribe "UnityModuleGenerator" do 3835375f98Sopenharmony_ci 3935375f98Sopenharmony_ci before do 4035375f98Sopenharmony_ci # clean sandbox and setup our "project" folders 4135375f98Sopenharmony_ci FileUtils.rm_rf "sandbox" 4235375f98Sopenharmony_ci FileUtils.mkdir_p "sandbox" 4335375f98Sopenharmony_ci FileUtils.mkdir_p "sandbox/src" 4435375f98Sopenharmony_ci FileUtils.mkdir_p "sandbox/test" 4535375f98Sopenharmony_ci 4635375f98Sopenharmony_ci @options = { 4735375f98Sopenharmony_ci :path_src => "sandbox/src", 4835375f98Sopenharmony_ci :path_tst => "sandbox/test", 4935375f98Sopenharmony_ci } 5035375f98Sopenharmony_ci end 5135375f98Sopenharmony_ci 5235375f98Sopenharmony_ci context "with src pattern" do 5335375f98Sopenharmony_ci before do 5435375f98Sopenharmony_ci @options[:pattern] = "src" 5535375f98Sopenharmony_ci end 5635375f98Sopenharmony_ci 5735375f98Sopenharmony_ci it "fails when all files already exist" do 5835375f98Sopenharmony_ci # create an existing triad of files 5935375f98Sopenharmony_ci touch_src "meh.c" 6035375f98Sopenharmony_ci touch_src "meh.h" 6135375f98Sopenharmony_ci touch_test "Testmeh.c" 6235375f98Sopenharmony_ci expect { 6335375f98Sopenharmony_ci UnityModuleGenerator.new(@options).generate("meh") 6435375f98Sopenharmony_ci }.to raise_error("ERROR: File meh already exists. Exiting.") 6535375f98Sopenharmony_ci end 6635375f98Sopenharmony_ci 6735375f98Sopenharmony_ci it "creates the test file if the source and header files exist" do 6835375f98Sopenharmony_ci # Create the existing files. 6935375f98Sopenharmony_ci touch_src "meh.c" 7035375f98Sopenharmony_ci touch_src "meh.h" 7135375f98Sopenharmony_ci 7235375f98Sopenharmony_ci UnityModuleGenerator.new(@options).generate("meh") 7335375f98Sopenharmony_ci 7435375f98Sopenharmony_ci expect_test_file_to_exist "Testmeh.c" 7535375f98Sopenharmony_ci end 7635375f98Sopenharmony_ci 7735375f98Sopenharmony_ci it "does not alter existing files" do 7835375f98Sopenharmony_ci # Create some files with known content. 7935375f98Sopenharmony_ci create_src_with_known_content "meh.c" 8035375f98Sopenharmony_ci create_src_with_known_content "meh.h" 8135375f98Sopenharmony_ci 8235375f98Sopenharmony_ci UnityModuleGenerator.new(@options).generate("meh") 8335375f98Sopenharmony_ci 8435375f98Sopenharmony_ci expect_src_content_didnt_change "meh.c" 8535375f98Sopenharmony_ci expect_src_content_didnt_change "meh.c" 8635375f98Sopenharmony_ci end 8735375f98Sopenharmony_ci 8835375f98Sopenharmony_ci it "does not alter existing test files" do 8935375f98Sopenharmony_ci # Create some files with known content. 9035375f98Sopenharmony_ci create_test_with_known_content "Testmeh.c" 9135375f98Sopenharmony_ci 9235375f98Sopenharmony_ci UnityModuleGenerator.new(@options).generate("meh") 9335375f98Sopenharmony_ci 9435375f98Sopenharmony_ci expect_test_content_didnt_change "Testmeh.c" 9535375f98Sopenharmony_ci end 9635375f98Sopenharmony_ci 9735375f98Sopenharmony_ci end 9835375f98Sopenharmony_ci 9935375f98Sopenharmony_ci context "with mch pattern" do 10035375f98Sopenharmony_ci before do 10135375f98Sopenharmony_ci @options[:pattern] = "mch" 10235375f98Sopenharmony_ci end 10335375f98Sopenharmony_ci 10435375f98Sopenharmony_ci it "fails when all files exist" do 10535375f98Sopenharmony_ci touch_src "meh_model.c" 10635375f98Sopenharmony_ci touch_src "meh_conductor.c" 10735375f98Sopenharmony_ci touch_src "meh_hardware.c" 10835375f98Sopenharmony_ci touch_src "meh_model.h" 10935375f98Sopenharmony_ci touch_src "meh_conductor.h" 11035375f98Sopenharmony_ci touch_src "meh_hardware.h" 11135375f98Sopenharmony_ci touch_test "Testmeh_model.c" 11235375f98Sopenharmony_ci touch_test "Testmeh_conductor.c" 11335375f98Sopenharmony_ci touch_test "Testmeh_hardware.c" 11435375f98Sopenharmony_ci expect { 11535375f98Sopenharmony_ci UnityModuleGenerator.new(@options).generate("meh") 11635375f98Sopenharmony_ci }.to raise_error("ERROR: File meh_model already exists. Exiting.") 11735375f98Sopenharmony_ci end 11835375f98Sopenharmony_ci 11935375f98Sopenharmony_ci it "creates files that don't exist" do 12035375f98Sopenharmony_ci touch_src "meh_model.c" 12135375f98Sopenharmony_ci touch_src "meh_conductor.c" 12235375f98Sopenharmony_ci touch_src "meh_hardware.c" 12335375f98Sopenharmony_ci touch_src "meh_model.h" 12435375f98Sopenharmony_ci touch_src "meh_conductor.h" 12535375f98Sopenharmony_ci 12635375f98Sopenharmony_ci UnityModuleGenerator.new(@options).generate("meh") 12735375f98Sopenharmony_ci 12835375f98Sopenharmony_ci expect_src_file_to_exist "meh_hardware.h" 12935375f98Sopenharmony_ci expect_test_file_to_exist "Testmeh_model.c" 13035375f98Sopenharmony_ci expect_test_file_to_exist "Testmeh_conductor.c" 13135375f98Sopenharmony_ci expect_test_file_to_exist "Testmeh_hardware.c" 13235375f98Sopenharmony_ci end 13335375f98Sopenharmony_ci 13435375f98Sopenharmony_ci it "does not alter existing source files" do 13535375f98Sopenharmony_ci create_src_with_known_content "meh_model.c" 13635375f98Sopenharmony_ci create_src_with_known_content "meh_model.c" 13735375f98Sopenharmony_ci create_src_with_known_content "meh_model.c" 13835375f98Sopenharmony_ci create_src_with_known_content "meh_model.h" 13935375f98Sopenharmony_ci create_src_with_known_content "meh_model.c" 14035375f98Sopenharmony_ci 14135375f98Sopenharmony_ci UnityModuleGenerator.new(@options).generate("meh") 14235375f98Sopenharmony_ci 14335375f98Sopenharmony_ci expect_src_content_didnt_change "meh_model.c" 14435375f98Sopenharmony_ci expect_src_content_didnt_change "meh_model.c" 14535375f98Sopenharmony_ci expect_src_content_didnt_change "meh_model.c" 14635375f98Sopenharmony_ci expect_src_content_didnt_change "meh_model.c" 14735375f98Sopenharmony_ci end 14835375f98Sopenharmony_ci 14935375f98Sopenharmony_ci it "does not alter existing test files" do 15035375f98Sopenharmony_ci create_test_with_known_content "Testmeh_model.c" 15135375f98Sopenharmony_ci 15235375f98Sopenharmony_ci UnityModuleGenerator.new(@options).generate("meh") 15335375f98Sopenharmony_ci 15435375f98Sopenharmony_ci expect_test_content_didnt_change "Testmeh_model.c" 15535375f98Sopenharmony_ci end 15635375f98Sopenharmony_ci 15735375f98Sopenharmony_ci end 15835375f98Sopenharmony_ciend 159