Skip to content

Commit

Permalink
Trying to debug tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Sep 7, 2024
1 parent 7ffae09 commit c4b7bd5
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 152 deletions.
46 changes: 23 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,41 @@ on:
- cron: 0 0 * * 1 # At 00:00 on Monday

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Download source
uses: actions/checkout@v4
# lint:
# name: Lint
# runs-on: ubuntu-latest
# steps:
# - name: Download source
# uses: actions/checkout@v4

- name: Install Crystal
uses: crystal-lang/install-crystal@v1
# - name: Install Crystal
# uses: crystal-lang/install-crystal@v1

- name: Cache Shards
uses: actions/cache@v3
with:
path: |
./lib
./bin
key: shards-${{ hashFiles('shard.yml') }}
# - name: Cache Shards
# uses: actions/cache@v3
# with:
# path: |
# ./lib
# ./bin
# key: shards-${{ hashFiles('shard.yml') }}

- name: Install shards
run: shards install
# - name: Install shards
# run: shards install

- name: Check code format
run: crystal tool format --check
# - name: Check code format
# run: crystal tool format --check

- name: Lint with ameba
run: bin/ameba
# - name: Lint with ameba
# run: bin/ameba

test:
name: Test
strategy:
fail-fast: false
matrix:
include:
- {os: ubuntu-latest}
- {os: macos-latest}
# - {os: ubuntu-latest}
# - {os: macos-latest}
- {os: windows-latest}
runs-on: ${{matrix.os}}
steps:
Expand Down
262 changes: 134 additions & 128 deletions spec/file_watcher_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./spec_helper"

TMP_DIR = "spec/tmp"
TMP_DIR = File.join("spec", "tmp")

describe FileWatcher do
around_each do |example|
Expand All @@ -19,140 +19,146 @@ describe FileWatcher do
it "notifies added files" do
spawn do
create_file(File.join(TMP_DIR, "example.txt"))
puts "Created file #{File.join(TMP_DIR, "example.txt")}"
puts File.read(File.join(TMP_DIR, "example.txt"))
puts "List files at #{Path[TMP_DIR, "**", "*"].to_posix.to_s}"
puts Dir[Path[TMP_DIR, "**", "*"].to_posix.to_s]
end

FileWatcher.watch(File.join(TMP_DIR, "**", "*"), interval: 0.01.seconds) do |event|
puts "EVENT"
puts event
event.type.added?.should be_true
event.path.should eq File.join(TMP_DIR, "example.txt")
break
end
end

it "notifies removed files" do
create_file(File.join(TMP_DIR, "example.txt"))

spawn do
File.delete(File.join(TMP_DIR, "example.txt"))
end

FileWatcher.watch(File.join(TMP_DIR, "**", "*"), interval: 0.01.seconds) do |event|
event.type.deleted?.should be_true
event.path.should eq File.join(TMP_DIR, "example.txt")
break
end
end

it "notifies changed files" do
create_file(File.join(TMP_DIR, "example.txt"))

spawn do
FileUtils.touch(File.join(TMP_DIR, "example.txt"))
end

FileWatcher.watch(File.join(TMP_DIR, "**", "*"), interval: 0.01.seconds) do |event|
event.type.changed?.should be_true
event.path.should eq File.join(TMP_DIR, "example.txt")
break
end
end

it "respects given pattern" do
spawn do
create_file(File.join(TMP_DIR, "code.cr"))
create_file(File.join(TMP_DIR, "data.json"))
create_file(File.join(TMP_DIR, "text.txt"))
end

FileWatcher.watch(File.join(TMP_DIR, "**", "*.json"), interval: 0.01.seconds) do |event|
event.type.added?.should be_true
event.path.should eq File.join(TMP_DIR, "data.json")
break
end
end

it "accepts Path pattern" do
spawn do
create_file(File.join(TMP_DIR, "example.txt"))
end

FileWatcher.watch(Path[TMP_DIR, "**", "*"], interval: 0.01.seconds) do |event|
event.type.added?.should be_true
event.path.should eq File.join(TMP_DIR, "example.txt")
break
end
end

it "accepts multiples patterns" do
spawn do
create_file(File.join(TMP_DIR, "folder_a", "foo.txt"))
create_file(File.join(TMP_DIR, "folder_b", "bar.txt"))
end

events = [] of FileWatcher::Event

FileWatcher.watch(
Path[TMP_DIR, "folder_a", "*.txt"],
File.join(TMP_DIR, "folder_b/*.txt"),
interval: 0.01.seconds
) do |event|
events << event

break if events.size == 2
end

events.should contain FileWatcher::Event.new(File.join(TMP_DIR, "folder_a/foo.txt"), :added)
events.should contain FileWatcher::Event.new(File.join(TMP_DIR, "folder_b/bar.txt"), :added)
end

it "accepts match_option" do
spawn do
create_file(File.join(TMP_DIR, ".dotfile"))
end

FileWatcher.watch(
Path[TMP_DIR, "**", "*"],
interval: 0.01.seconds,
match_option: File::MatchOptions::DotFiles
) do |event|
event.type.added?.should be_true
event.path.should eq File.join(TMP_DIR, ".dotfile")
break
end
end

it "allows following symlinks" do
FileUtils.mkdir_p(File.join(TMP_DIR, "original"))

FileUtils.cd(TMP_DIR) do
FileUtils.ln_s("original", "symlink")
end

spawn do
create_file(File.join(TMP_DIR, "original/example.txt"))
end

FileWatcher.watch("spec/tmp/**/*.txt", interval: 0.01.seconds, follow_symlinks: true) do |event|
event.type.added?.should be_true
event.path.should eq File.join(TMP_DIR, "symlink/example.txt")
break
end
end

it "allows customising polling interval" do
spawn do
create_file(File.join(TMP_DIR, "example.txt"))
end

started_at = Time.utc

FileWatcher.watch(File.join(TMP_DIR, "**", "*"), interval: 1.second) do |event|
event.type.added?.should be_true
event.path.should eq File.join(TMP_DIR, "example.txt")

now = Time.utc
now.should be_close(started_at + 1.second, 0.1.seconds)

break
end
end
# it "notifies removed files" do
# create_file(File.join(TMP_DIR, "example.txt"))

# spawn do
# File.delete(File.join(TMP_DIR, "example.txt"))
# end

# FileWatcher.watch(File.join(TMP_DIR, "**", "*"), interval: 0.01.seconds) do |event|
# event.type.deleted?.should be_true
# event.path.should eq File.join(TMP_DIR, "example.txt")
# break
# end
# end

# it "notifies changed files" do
# create_file(File.join(TMP_DIR, "example.txt"))

# spawn do
# FileUtils.touch(File.join(TMP_DIR, "example.txt"))
# end

# FileWatcher.watch(File.join(TMP_DIR, "**", "*"), interval: 0.01.seconds) do |event|
# event.type.changed?.should be_true
# event.path.should eq File.join(TMP_DIR, "example.txt")
# break
# end
# end

# it "respects given pattern" do
# spawn do
# create_file(File.join(TMP_DIR, "code.cr"))
# create_file(File.join(TMP_DIR, "data.json"))
# create_file(File.join(TMP_DIR, "text.txt"))
# end

# FileWatcher.watch(File.join(TMP_DIR, "**", "*.json"), interval: 0.01.seconds) do |event|
# event.type.added?.should be_true
# event.path.should eq File.join(TMP_DIR, "data.json")
# break
# end
# end

# it "accepts Path pattern" do
# spawn do
# create_file(File.join(TMP_DIR, "example.txt"))
# end

# FileWatcher.watch(Path[TMP_DIR, "**", "*"], interval: 0.01.seconds) do |event|
# event.type.added?.should be_true
# event.path.should eq File.join(TMP_DIR, "example.txt")
# break
# end
# end

# it "accepts multiples patterns" do
# spawn do
# create_file(File.join(TMP_DIR, "folder_a", "foo.txt"))
# create_file(File.join(TMP_DIR, "folder_b", "bar.txt"))
# end

# events = [] of FileWatcher::Event

# FileWatcher.watch(
# Path[TMP_DIR, "folder_a", "*.txt"],
# File.join(TMP_DIR, "folder_b/*.txt"),
# interval: 0.01.seconds
# ) do |event|
# events << event

# break if events.size == 2
# end

# events.should contain FileWatcher::Event.new(File.join(TMP_DIR, "folder_a/foo.txt"), :added)
# events.should contain FileWatcher::Event.new(File.join(TMP_DIR, "folder_b/bar.txt"), :added)
# end

# it "accepts match_option" do
# spawn do
# create_file(File.join(TMP_DIR, ".dotfile"))
# end

# FileWatcher.watch(
# Path[TMP_DIR, "**", "*"],
# interval: 0.01.seconds,
# match_option: File::MatchOptions::DotFiles
# ) do |event|
# event.type.added?.should be_true
# event.path.should eq File.join(TMP_DIR, ".dotfile")
# break
# end
# end

# it "allows following symlinks" do
# FileUtils.mkdir_p(File.join(TMP_DIR, "original"))

# FileUtils.cd(TMP_DIR) do
# FileUtils.ln_s("original", "symlink")
# end

# spawn do
# create_file(File.join(TMP_DIR, "original/example.txt"))
# end

# FileWatcher.watch("spec/tmp/**/*.txt", interval: 0.01.seconds, follow_symlinks: true) do |event|
# event.type.added?.should be_true
# event.path.should eq File.join(TMP_DIR, "symlink/example.txt")
# break
# end
# end

# it "allows customising polling interval" do
# spawn do
# create_file(File.join(TMP_DIR, "example.txt"))
# end

# started_at = Time.utc

# FileWatcher.watch(File.join(TMP_DIR, "**", "*"), interval: 1.second) do |event|
# event.type.added?.should be_true
# event.path.should eq File.join(TMP_DIR, "example.txt")

# now = Time.utc
# now.should be_close(started_at + 1.second, 0.1.seconds)

# break
# end
# end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def create_file(file_name : String | Path)

FileUtils.mkdir_p(dir) unless Dir.exists?(dir)

File.write(file_name, "")
File.write(file_name, "hello")
end

0 comments on commit c4b7bd5

Please sign in to comment.