From 047cc71b0d6d2f997b91f8e4197c50382cdbea21 Mon Sep 17 00:00:00 2001 From: Cooper Hammond Date: Sun, 8 Nov 2020 01:17:45 -0700 Subject: [PATCH] added a very simple test suite --- spec/irs_spec.cr | 32 +++++++++++++++++++++++++++++--- spec/spec_helper.cr | 10 +++++++++- src/bottle/cli.cr | 6 ------ src/search/youtube.cr | 2 +- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/spec/irs_spec.cr b/spec/irs_spec.cr index 9562b57..2d982d6 100755 --- a/spec/irs_spec.cr +++ b/spec/irs_spec.cr @@ -1,9 +1,35 @@ require "./spec_helper" -describe Irs do +describe CLI do # TODO: Write tests - it "works" do - false.should eq(true) + it "can show help" do + run_CLI_with_args(["--help"]) + end + + it "can show version" do + run_CLI_with_args(["--version"]) + end + + # !!TODO: make a long and short version of the test suite + # TODO: makes so this doesn't need user input + it "can install ytdl and ffmpeg binaries" do + # run_CLI_with_args(["--install"]) + end + + it "can show config file loc" do + run_CLI_with_args(["--config"]) + end + + it "can download a single song" do + run_CLI_with_args(["--song", "Bohemian Rhapsody", "--artist", "Queen"]) + end + + it "can download an album" do + run_CLI_with_args(["--artist", "Arctic Monkeys", "--album", "Da Frame 2R / Matador"]) + end + + it "can download a playlist" do + run_CLI_with_args(["--artist", "prakkillian", "--playlist", "IRS Testing"]) end end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 5c3c333..40ccf84 100755 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -1,2 +1,10 @@ require "spec" -require "../src/irs" + +# https://github.com/mosop/stdio + +require "../src/bottle/cli" + +def run_CLI_with_args(argv : Array(String)) + cli = CLI.new(argv) + cli.act_on_args +end \ No newline at end of file diff --git a/src/bottle/cli.cr b/src/bottle/cli.cr index 6709446..f774915 100755 --- a/src/bottle/cli.cr +++ b/src/bottle/cli.cr @@ -73,22 +73,17 @@ class CLI if @args["help"]? || @args.keys.size == 0 help - exit elsif @args["version"]? version - exit elsif @args["install"]? YdlBinaries.get_both(Config.binary_location) - exit elsif @args["config"]? puts ENV["IRS_CONFIG_LOCATION"]? - exit elsif @args["song"]? && @args["artist"]? s = Song.new(@args["song"], @args["artist"]) s.provide_client_keys(Config.client_key, Config.client_secret) s.grab_it(@args["url"]?) s.organize_it(Config.music_directory) - exit elsif @args["album"]? && @args["artist"]? a = Album.new(@args["album"], @args["artist"]) a.provide_client_keys(Config.client_key, Config.client_secret) @@ -108,7 +103,6 @@ class CLI else puts Style.red("Those arguments don't do anything when used that way.") puts "Type `irs -h` to see usage." - exit 1 end end diff --git a/src/search/youtube.cr b/src/search/youtube.cr index a42e4c7..e043583 100755 --- a/src/search/youtube.cr +++ b/src/search/youtube.cr @@ -206,7 +206,7 @@ module Youtube if yt_initial_data == JSON.parse("{}") puts "Youtube has changed the way it organizes its webpage, submit a bug" - puts "on https://github.com/cooperhammond/irs" + puts "saying it has done so on https://github.com/cooperhammond/irs" exit(1) end