-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trying again to get the tests to pass predictably on linux. (#383)
* Got travis tests to pass every time. Ended up being an issue of timestamp resolution on files for linux. * trying again 😢 * Update environment_loader.cr * changed timestamp to milliseconds * one last push to make sure travis still passes 4 times in a row Former-commit-id: b808127
- Loading branch information
Showing
6 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# {% if flag?(:run_build_tests) %} | ||
require "../../../spec_helper" | ||
require "../../../support/helpers/cli_helper" | ||
|
||
include CLIHelper | ||
|
||
module Amber::CLI | ||
describe "amber exec" do | ||
context "within project" do | ||
cleanup | ||
scaffold_app(TESTING_APP) | ||
`shards` | ||
|
||
it "executes one-liners from the first command-line argument" do | ||
expected_result = "[:a, :b, :c, :d]\n" | ||
MainCommand.run(["exec", "[:a, :b, :c] + [:d]"]) | ||
logs = `ls tmp/*_console_result.log`.strip.split(/\s/).sort | ||
File.read(logs.last?.to_s).should eq expected_result | ||
end | ||
|
||
it "executes a .cr file from the first command-line argument" do | ||
File.write "amber_exec_spec_test.cr", "puts([:a] + [:b])" | ||
MainCommand.run(["exec", "amber_exec_spec_test.cr", "-e", "tail"]) | ||
logs = `ls tmp/*_console_result.log`.strip.split(/\s/).sort | ||
File.read(logs.last?.to_s).should eq "[:a, :b]\n" | ||
File.delete("amber_exec_spec_test.cr") | ||
end | ||
|
||
it "opens editor and executes .cr file on close" do | ||
MainCommand.run(["exec", "-e", "echo 'puts 1000' > "]) | ||
logs = `ls tmp/*_console_result.log`.strip.split(/\s/).sort | ||
File.read(logs.last?.to_s).should eq "1000\n" | ||
end | ||
|
||
it "copies previous run into new file for editing and runs it returning results" do | ||
MainCommand.run(["exec", "1337"]) | ||
MainCommand.run(["exec", "-e", "tail", "-b", "1"]) | ||
logs = `ls tmp/*_console_result.log`.strip.split(/\s/).sort | ||
File.read(logs.last?.to_s).should eq "1337\n" | ||
end | ||
|
||
cleanup | ||
end | ||
|
||
context "outside of project" do | ||
it "complains if not in the root of a project" do | ||
expected_result = "Error: 'amber exec' can only be used from the root of a valid amber project" | ||
MainCommand.run(["exec", ":hello"]) | ||
logs = `ls tmp/*_console_result.log`.strip.split(/\s/).sort | ||
File.read(logs.last?.to_s).should eq expected_result | ||
end | ||
|
||
cleanup | ||
end | ||
end | ||
end | ||
# {% end %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require "cli" | ||
|
||
module Amber::CLI | ||
class MainCommand < ::Cli::Supercommand | ||
command "x", aliased: "exec" | ||
|
||
class Exec < ::Cli::Command | ||
command_name "exec" | ||
@filename = "./tmp/#{Time.now.epoch_ms}_console.cr" | ||
|
||
class Options | ||
arg "code", desc: "Crystal code or .cr file to execute within the application scope", default: "" | ||
string ["-e", "--editor"], desc: "Prefered editor: [vim, nano, pico, etc], only used when no code or .cr file is specified", default: "vim" | ||
string ["-b", "--back"], desc: "Runs prevous command files: 'amber exec -b [times_ago]'", default: "0" | ||
end | ||
|
||
class Help | ||
caption "# It runs Crystal code within the application scope" | ||
end | ||
|
||
def prepare_file | ||
_filename = if File.exists?(args.code) | ||
args.code | ||
elsif options.back.to_i(strict: false) > 0 | ||
Dir.glob("./tmp/*_console.cr").sort.reverse[options.back.to_i(strict: false) - 1]? | ||
end | ||
|
||
system("cp #{_filename} #{@filename}") if _filename | ||
end | ||
|
||
def run | ||
Dir.mkdir("tmp") unless Dir.exists?("tmp") | ||
|
||
unless args.code.blank? || File.exists?(args.code) | ||
File.write(@filename, "puts (#{args.code}).inspect") | ||
else | ||
prepare_file | ||
system("#{options.editor} #{@filename}") | ||
end | ||
|
||
result = "" | ||
result = `crystal eval 'require "./config/*"; require "#{@filename}"'` if File.exists?(@filename) | ||
|
||
if result.includes?("while requiring \"./config/*\": can't find file './config/*' relative to '.'") | ||
result = "Error: 'amber exec' can only be used from the root of a valid amber project" | ||
end | ||
|
||
File.write(@filename.sub("console.cr", "console_result.log"), result) unless result.blank? | ||
puts result | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
/.crystal/ | ||
/.shards/ | ||
/.vscode/ | ||
/tmp/ | ||
.env | ||
.amber_secret_key | ||
production.yml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters