Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #! /usr/bin/env ruby
  2. #
  3. # ACSL Tester
  4. # version 0.1.1
  5. # by Sam Craig
  6. #
  7. # Given a file in the current directory `test.config`,
  8. # this program will run the first line with the next few
  9. # lines as inputs. It will then compare those outputs to
  10. # the final few lines, to show you if tests succeeded.
  11. #
  12. # Requires the additional gem "colorize" to be installed.
  13.  
  14. require "colorize"
  15. require "open3"
  16.  
  17. config_path = File.join(Dir.pwd, "test.config")
  18.  
  19. unless File.exist?(config_path)
  20. abort "No config file found!"
  21. end
  22.  
  23. # Get all of the components out of the configuration file.
  24. command = nil
  25. inputs = []
  26. expected = []
  27. adding_to_inputs = true
  28. File.readlines(config_path).each do |line|
  29. line.chomp!
  30.  
  31. # Check for our input and expected separator.
  32. if line == ""
  33. adding_to_inputs = false
  34. next
  35. end
  36.  
  37. # Add the line to the necessary location.
  38. if command
  39. if adding_to_inputs
  40. inputs << line
  41. else
  42. expected << line
  43. end
  44. else
  45. command = line
  46. end
  47. end
  48.  
  49. # Run the program and get outputs.
  50. output, status = Open3.capture2(command, stdin_data: inputs.join("\n"))
  51. unless status.success?
  52. abort "Program did not return exit code 0!"
  53. end
  54.  
  55. # Show if tests succeeded.
  56. outputs = output.split("\n")
  57. expected.each_with_index do |value, index|
  58. if value == outputs[index]
  59. puts value.green
  60. else
  61. puts "#{outputs[index].red} expected #{value}"
  62. end
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement