Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env ruby
- #
- # ACSL Tester
- # version 0.1.1
- # by Sam Craig
- #
- # Given a file in the current directory `test.config`,
- # this program will run the first line with the next few
- # lines as inputs. It will then compare those outputs to
- # the final few lines, to show you if tests succeeded.
- #
- # Requires the additional gem "colorize" to be installed.
- require "colorize"
- require "open3"
- config_path = File.join(Dir.pwd, "test.config")
- unless File.exist?(config_path)
- abort "No config file found!"
- end
- # Get all of the components out of the configuration file.
- command = nil
- inputs = []
- expected = []
- adding_to_inputs = true
- File.readlines(config_path).each do |line|
- line.chomp!
- # Check for our input and expected separator.
- if line == ""
- adding_to_inputs = false
- next
- end
- # Add the line to the necessary location.
- if command
- if adding_to_inputs
- inputs << line
- else
- expected << line
- end
- else
- command = line
- end
- end
- # Run the program and get outputs.
- output, status = Open3.capture2(command, stdin_data: inputs.join("\n"))
- unless status.success?
- abort "Program did not return exit code 0!"
- end
- # Show if tests succeeded.
- outputs = output.split("\n")
- expected.each_with_index do |value, index|
- if value == outputs[index]
- puts value.green
- else
- puts "#{outputs[index].red} expected #{value}"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement