# frozen_string_literal: true # Copyright (c) 2024 Yegor Bugayenko # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the 'Software'), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. require 'tmpdir' require 'net/ping' require 'English' Before do @cwd = Dir.pwd end After do unless @tmp.nil? Dir.chdir(@cwd) FileUtils.rm_rf(@tmp) end end Given(/^We are online$/) do pending unless Net::Ping::External.new('8.8.8.8').ping? end Given(/^I make a temp directory$/) do @tmp = Dir.mktmpdir('test') FileUtils.mkdir_p(@tmp) Dir.chdir(@tmp) end Given(/^I have a "([^"]*)" file with content:$/) do |file, text| FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file) File.write(file, text.gsub('\\xFF', 0xFF.chr)) end When(%r{^I run bin/judges with "([^"]*)"$}) do |arg| home = File.join(File.dirname(__FILE__), '../..') cmd = "ruby -I#{home}/lib #{home}/bin/judges #{arg}" cmd = "GLI_DEBUG=true #{cmd}" unless Gem.win_platform? @stdout = `#{cmd} 2>&1` @exitstatus = $CHILD_STATUS.exitstatus end When(/^I run bash with "([^"]*)"$/) do |text| FileUtils.copy_entry(@cwd, File.join(@tmp, 'judges')) @stdout = `#{text}` @exitstatus = $CHILD_STATUS.exitstatus end When(/^I run bash with:$/) do |text| FileUtils.copy_entry(@cwd, File.join(@tmp, 'judges')) @stdout = `#{text}` @exitstatus = $CHILD_STATUS.exitstatus end Then(/^Stdout contains "([^"]*)"$/) do |txt| raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}" unless @stdout.include?(txt) end Then(/^Stdout is empty$/) do raise "STDOUT is not empty:\n#{@stdout}" unless @stdout == '' end Then(/^Exit code is zero$/) do raise "Non-zero exit #{@exitstatus}:\n#{@stdout}" unless @exitstatus.zero? end Then(/^Exit code is not zero$/) do raise 'Zero exit code' if @exitstatus.zero? end