ccu 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 430ad16d67956b3ced25df10beafd05811837a06
4
- data.tar.gz: e7498ff8d25d71a1280197792ccd9dc24934c904
3
+ metadata.gz: 6623afccf6a92ac93d097bf9cd793ecc39523a80
4
+ data.tar.gz: b97884414cbba53123358bd2339d4e5a67168c78
5
5
  SHA512:
6
- metadata.gz: d1a804a3240c3f2322f7aa10c644655113fc2bdafd3163f56793ce429795f2f556b4a26b1ca489425d7c380980c5610592bfd5c9691bcec1b4bed145763228e2
7
- data.tar.gz: 77ad0a37031b6bde88486e7bd04a8875d033055203f50311b413d9fb6858612a999311bd94cc2cc0d77eb5e79cf4394a5ae4c2caf226f523c03c636e9e14d51c
6
+ metadata.gz: 0512c4a6195e8ad924b9278a15eacd60f2f66e74051be8af7fac313e4c99a4b5cda59e3f2c76224623c6e9054de4dd887cfdf3d860e57cd0d0b60ad2abfe4530
7
+ data.tar.gz: a543db2c6e3e5109454050a623b3c154f871601b0a7d48bdc2c8e8821e7110351c650a6e65339cf97aa5bf9bf2dc66e3e6188f7d4dfe9222c020c8cf8b665767
data/.gitignore CHANGED
@@ -15,3 +15,4 @@
15
15
 
16
16
  /.travis.yml
17
17
  /spec/spec_helper.rb
18
+ .DS_Store
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.verbose = false
6
+ end
5
7
 
6
8
  task :default => :spec
7
9
 
data/bin/ccu CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ STDOUT.sync = true
4
+
3
5
  # TODO: to use http://ruby-doc.org/stdlib-2.2.0/libdoc/optparse/rdoc/OptionParser.html
4
6
 
5
- Signal.trap("INT"){ puts "\n"; exit 0 }
7
+ Signal.trap(:INT){ puts "\n(interrupted by SIGINT)"; exit 0 }
6
8
 
7
- puts "\tNakitools usage: naki file" || exit if !ARGV.first || ARGV.first[/^-*(v(ersion)?|h(elp)?)$/]
9
+ abort "\tCCU usage:\tccu <file[s]>" if !ARGV.first || ARGV.first[/^-*(v(ersion)?|h(elp)?)$/]
8
10
 
9
11
  expect = lambda do |command, expectation|
10
12
  output = `#{command}`
@@ -17,12 +19,32 @@ end
17
19
 
18
20
  # ARGV.first =~ /(?<basename>.*)\.(?<extension>.+)/
19
21
  filename = ARGV.first
20
- abort "ERROR: can't run without parameters"
21
22
  extension = File.extname filename
22
- ARGV.clear
23
- case extension.downcase
23
+ ARGV.clear # to stop #gets read from ARGF
24
+
25
+ # exit p [filename, File.expand_path(filename), File.exist?(filename), File.directory?(filename)]
26
+
27
+ # TODO: use Shellwords.escape
28
+ # TODO: chomp ?/
29
+
30
+ if File.directory? filename
31
+ puts "\tIt is a directory."
32
+ expect[ "file \"#{filename}\"", "#{filename}: directory\n" ]
33
+ puts "\tWhat would you like to do with it?"
34
+ newname = filename + ".tar.gz"
35
+ begin puts "\t[a] - archive to \"./%s\"" % newname end until gets == "a\n" || puts("WUT?")
36
+ expect[ "tar --version", /^bsdtar 2\.8\.3 -/ ]
37
+ abort "ERROR: file %p already exists" % newname if File.exist? newname
38
+ cmd = "tar czf \"#{newname}\" \"#{filename}\""
39
+ puts "\tPress Enter to proceed or ^C to cancel this shell command:\n\t\t#{cmd}"
40
+ gets
41
+ system cmd
42
+ system "file \"#{newname}\""
43
+ exit
44
+ end
24
45
 
25
- when ".zip"
46
+ case extension.downcase
47
+ when ".zip___"
26
48
  puts "\tAssuming it is a ZIP archive."
27
49
  expect[ "file \"#{filename}\"", "#{filename}: Zip archive data, at least v1.0 to extract\n" ]
28
50
  expect[ "unzip -v", /^UnZip 5\.52 / ]
@@ -37,7 +59,7 @@ when ".zip"
37
59
  gets
38
60
  system cmd
39
61
  system "ls -1 | grep \"^#{basename}\""
40
- when ".gif"
62
+ when ".gif___"
41
63
  puts "\tAssuming it is a GIF image."
42
64
  expect[ "file \"#{filename}\"", /^#{filename}: GIF image data, version 89a, \d+ x \d+\n$/ ]
43
65
  expect[ "sips --help", /^sips 10\.4\.4 / ]
@@ -65,5 +87,5 @@ when ".gif"
65
87
  system cmd
66
88
  system "sips -g all \"#{newname}\""
67
89
  else
68
- abort "idk"
90
+ abort "Unknown file extension %p" % extension
69
91
  end
@@ -6,7 +6,7 @@
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "ccu"
9
- spec.version = "0.0.1" # Ccu::VERSION
9
+ spec.version = "0.0.2" # Ccu::VERSION
10
10
  spec.authors = ["Victor Maslov"]
11
11
  spec.email = ["nakilon@gmail.com"]
12
12
  spec.summary = "Context Console Utility"
@@ -1,10 +1,107 @@
1
1
  # require 'spec_helper'
2
2
 
3
- describe "A" do
4
- it "should fail if no parameters were given" do
5
- Dir.chdir __dir__
6
- binary = Shellwords.escape File.join(__dir__, "../bin/ccu")
7
- `#{binary}`; process_status = $?
8
- expect(process_status).not_to be_success
3
+ # TODO: check for test files existence before and after
4
+
5
+ describe "ccu" do
6
+ require "open3"
7
+ let(:binary){ Shellwords.escape File.join __dir__, "../bin/ccu" }
8
+ # before(:suite){ Dir.chdir "#{__dir__}/files" }
9
+
10
+ # # around hook variable sharing hack (c) Nakilon
11
+ # let(:temp_dir_var){ [] }
12
+ # def temp_dir setting = nil
13
+ # temp_dir_var[0] = setting || temp_dir_var[0]
14
+ # end
15
+ around do |example|
16
+ require "tmpdir"
17
+ Dir.mktmpdir do |dir|
18
+ # temp_dir dir
19
+ Dir.chdir(dir) do
20
+ require "fileutils"
21
+ FileUtils.cp_r "#{__dir__}/files", "./† †"
22
+ expect(Dir.pwd).to match(/^\/private\/var\/folders\//)
23
+ expected_files = Dir.chdir(__dir__){ Dir["**/*"] }.map do |file|
24
+ file.sub! /^files(\/|$)/, '† †\1'
25
+ end.compact
26
+ expect(Dir["**/*"]).to eq(expected_files),
27
+ "didn't add `/files' directory to temp dir"
28
+ example.run
29
+ end
30
+ end
31
+ end
32
+
33
+ it "<ctrl> + C" do
34
+ # threads = Open3.pipeline_start "#{binary} files"
35
+ _, output, thread = Open3.popen2e "#{binary} ."
36
+ sleep 0.1 # waiting for Trap to be prepared
37
+ expect{ Process.kill "INT", thread.pid }.not_to raise_error,
38
+ ->{ "couldn't kill process, waiting got ^C because: %p" % output.read }
39
+ string, status = output.read, thread.value
40
+ expect(string).to include("interrupted"),
41
+ "didn't tell about interruption"
42
+ expect(string).not_to include("Interrupt"),
43
+ "didn't trap SIGINT"
44
+ expect(status).to be_success
45
+ end
46
+ it "no params" do
47
+ string, status = Open3.capture2e "#{binary}"
48
+ expect(string).to include("usage")
49
+ expect(status).not_to be_success
9
50
  end
51
+ it "unknown extension" do
52
+ # threads = Open3.pipeline "#{binary} unknown"
53
+ string, status = Open3.capture2e "#{binary} unknown"
54
+ expect(string).to include("Unknown file extension")
55
+ expect(status).not_to be_success
56
+ end
57
+
58
+ describe "directory" do
59
+ let( :input_var){ [] }; def input setting = nil; input_var[0] = setting || input_var[0]; end
60
+ let(:output_var){ [] }; def output setting = nil; output_var[0] = setting || output_var[0]; end
61
+ let(:pid_var){ [] }
62
+ def read_moar
63
+ sleep 1 # otherwise we need rescue Errno::EAGAIN
64
+ IO.select [output]
65
+ string = ""
66
+ expect{ output.read_nonblock 100500, string }.not_to raise_error,
67
+ "unexpected error -- probably end of communication"
68
+ # rescue EOFError
69
+ string
70
+ end
71
+ before do
72
+ i, o, t = Open3.popen2e "#{binary} \"† †\""
73
+ input i
74
+ output o
75
+ pid_var[0] = t.pid
76
+ expect(read_moar).to include("is a directory")
77
+ end
78
+ it "empty command" do
79
+ input.puts ""
80
+ expect(read_moar).to include("WUT?")
81
+ end
82
+ it "bullshit command" do
83
+ input.puts "bullshit"
84
+ expect(read_moar).to include("WUT?")
85
+ end
86
+ describe "[a]rchive" do
87
+ before do
88
+ skip "tar isn't installed" unless `tar --version`[/^bsdtar 2\.8\.3 -/]
89
+ input.puts "a"
90
+ string = read_moar
91
+ expect(string).to include("Press Enter to proceed")
92
+ expect(string).to include("tar czf")
93
+ end
94
+ it "<ctrl> + C" do
95
+ Process.kill "INT", pid_var[0]
96
+ sleep 1
97
+ expect(File.exist?("† †.tar.gz")).to be_falsy
98
+ end
99
+ it "Enter" do
100
+ input.puts ?\n
101
+ expect(read_moar).to include("gzip compressed data")
102
+ expect(File.exist?("† †.tar.gz")).to be_truthy
103
+ end
104
+ end
105
+ end
106
+
10
107
  end
@@ -1 +1,5 @@
1
- abort "ERROR: #{__dir__} has to be excluded from tests!"
1
+ describe "Files directory" do
2
+ it "should be excluded from rspec testing" do
3
+ raise __dir__
4
+ end
5
+ end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov
@@ -71,6 +71,7 @@ files:
71
71
  - ccu.gemspec
72
72
  - spec/_spec.rb
73
73
  - spec/files/_spec.rb
74
+ - spec/files/unknown
74
75
  homepage:
75
76
  licenses:
76
77
  - MIT
@@ -98,3 +99,4 @@ summary: Context Console Utility
98
99
  test_files:
99
100
  - spec/_spec.rb
100
101
  - spec/files/_spec.rb
102
+ - spec/files/unknown