diff --git a/.ameba.yml b/.ameba.yml new file mode 100644 index 0000000..862ab58 --- /dev/null +++ b/.ameba.yml @@ -0,0 +1,2 @@ +Performance/MinMaxAfterMap: + Enabled: false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d0745c..ba405fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,13 @@ jobs: test: strategy: fail-fast: false + matrix: + include: + - os: ubuntu-latest + lint: true + - os: windows-latest - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} env: TERM: xterm-256color @@ -23,12 +28,14 @@ jobs: uses: actions/checkout@v2 - name: Check formatting + if: ${{ matrix.lint }} run: crystal tool format --check - name: Install dependencies run: shards install - name: Run linter + if: ${{ matrix.lint }} run: ./bin/ameba - name: Setup environment diff --git a/examples/sam.cr b/examples/sam.cr index 4e6df6d..66ac1b7 100644 --- a/examples/sam.cr +++ b/examples/sam.cr @@ -87,16 +87,16 @@ end namespace "db" do namespace "schema" do desc "just test" - task "load" do |t, args| + task "load" do |task, args| puts args["f1"] - t.invoke("1") - t.invoke("schema:1") - t.invoke("db:migrate") - t.invoke("db:db:migrate") - t.invoke("db:ping") - t.invoke("din:dong") + task.invoke("1") + task.invoke("schema:1") + task.invoke("db:migrate") + task.invoke("db:db:migrate") + task.invoke("db:ping") + task.invoke("din:dong") puts "------" - t.invoke("2", {"f2" => 1}) + task.invoke("2", {"f2" => 1}) end desc "1" diff --git a/shard.yml b/shard.yml index 48fe251..2eb71b1 100644 --- a/shard.yml +++ b/shard.yml @@ -11,7 +11,7 @@ license: MIT development_dependencies: ameba: github: crystal-ameba/ameba - version: "= 1.4.3" + version: "= 1.6.1" scripts: postinstall: "false | [ -f ../../sam.cr ] && true || cp -i examples/sam.template ../../sam.cr 2>/dev/null" diff --git a/spec/sam_spec.cr b/spec/sam_spec.cr index e1fafe9..1bcb07e 100644 --- a/spec/sam_spec.cr +++ b/spec/sam_spec.cr @@ -1,5 +1,7 @@ require "./spec_helper" +executable = "crystal #{File.join("examples", "sam.cr")}" + describe Sam do describe ".namespace" do pending "add" do @@ -27,7 +29,7 @@ describe Sam do describe ".help" do it "with multiple tasks" do - res = execute("crystal examples/sam.cr", ["db:with_argument", "f1=a", "@", "db:ping"]) + res = execute(executable, ["db:with_argument", "f1=a", "@", "db:ping"]) res[1].should eq(<<-TEXT) a ping @@ -44,7 +46,7 @@ describe Sam do end it "without a specified task and without a default task defined" do - res = execute("crystal examples/sam.cr", %w[]) + res = execute(executable, %w[]) res[1].should eq(<<-TEXT) Hm, nothing to do... diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 57e5e5b..4d5fe66 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -25,7 +25,12 @@ end def execute(command, options) io = IO::Memory.new - status = Process.run("#{command} \"${@}\"", options, shell: true, output: io, error: io).exit_status + status = + {% if flag?(:win32) %} + Process.run("#{command} \"${@}\"", options, output: io, error: io) + {% else %} + Process.run("#{command} \"${@}\"", options, shell: true, output: io, error: io) + {% end %}.exit_status {status, io.to_s} end @@ -40,16 +45,16 @@ end namespace "db" do namespace "schema" do - task "load" do |t, args| + task "load" do |task, args| puts args["f1"] - t.invoke("1") - t.invoke("schema:1") - t.invoke("db:migrate") - t.invoke("db:db:migrate") - t.invoke("db:ping") - t.invoke("din:dong") - t.invoke("schema") - Container.add(t.path) + task.invoke("1") + task.invoke("schema:1") + task.invoke("db:migrate") + task.invoke("db:db:migrate") + task.invoke("db:ping") + task.invoke("din:dong") + task.invoke("schema") + Container.add(task.path) end task "1" do @@ -58,9 +63,9 @@ namespace "db" do end end - task "with_argument" do |t, args| + task "with_argument" do |task, args| puts args["f1"] - Container.add(t.path) + Container.add(task.path) end task "schema" do diff --git a/spec/task_spec.cr b/spec/task_spec.cr index 44a742a..2449dd2 100644 --- a/spec/task_spec.cr +++ b/spec/task_spec.cr @@ -116,7 +116,7 @@ describe Sam::Task do it "accepts arg object" do count = 0 namespace.task("t1") { |_, args| count += args["count"].as(Int32) } - namespace.task("t2") { |t, args| t.invoke("t1", args) }.call(Sam::Args.new({"count" => 2})) + namespace.task("t2") { |task, args| task.invoke("t1", args) }.call(Sam::Args.new({"count" => 2})) count.should eq(2) end @@ -160,7 +160,7 @@ describe Sam::Task do it "accepts arg object" do count = 0 namespace.task("t1") { |_, args| count += args["count"].as(Int32) } - namespace.task("t2") { |t, args| t.execute("t1", args) }.call(Sam::Args.new({"count" => 2})) + namespace.task("t2") { |task, args| task.execute("t1", args) }.call(Sam::Args.new({"count" => 2})) count.should eq(2) end