From c4b7bd52eff38ac241a7dfac3c06dcb21867979a Mon Sep 17 00:00:00 2001 From: stephann <3025661+stephannv@users.noreply.github.com> Date: Sat, 7 Sep 2024 10:42:21 -0300 Subject: [PATCH] Trying to debug tests on windows --- .github/workflows/ci.yml | 46 +++---- spec/file_watcher_spec.cr | 262 +++++++++++++++++++------------------- spec/spec_helper.cr | 2 +- 3 files changed, 158 insertions(+), 152 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f7cdf1..59f0126 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,32 +5,32 @@ 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 @@ -38,8 +38,8 @@ jobs: 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: diff --git a/spec/file_watcher_spec.cr b/spec/file_watcher_spec.cr index 38ba068..f4877ec 100644 --- a/spec/file_watcher_spec.cr +++ b/spec/file_watcher_spec.cr @@ -1,6 +1,6 @@ require "./spec_helper" -TMP_DIR = "spec/tmp" +TMP_DIR = File.join("spec", "tmp") describe FileWatcher do around_each do |example| @@ -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 diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index e1df126..d6b12a8 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -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