From c4252301bf0272433d9c22d8922b536e963f602c Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Thu, 22 Oct 2020 11:38:51 -0300
Subject: [PATCH 01/11] New tests for functions to manipulate directories

---
 scripts/app_fs.lua | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/scripts/app_fs.lua b/scripts/app_fs.lua
index ab2fa6235..e3e38949c 100644
--- a/scripts/app_fs.lua
+++ b/scripts/app_fs.lua
@@ -52,3 +52,26 @@ do
   assert(runTestsFound)
   assert(readmeFound)
 end
+
+-- Create directories
+do
+  assert(fs.makeDirectory("_tmp"))
+  assert(fs.isDirectory("_tmp"))
+
+  assert(fs.makeAllDirectories("_tmp/a/b"))
+  assert(fs.isDirectory("_tmp/a"))
+  assert(fs.isDirectory("_tmp/a/b"))
+
+  assert(fs.removeDirectory("_tmp/a/b"))
+  assert(not fs.isDirectory("_tmp/a/b"))
+  assert(fs.isDirectory("_tmp/a"))
+
+  assert(not fs.removeDirectory("_tmp")) -- Should fail
+  assert(fs.isDirectory("_tmp/a"))
+  assert(fs.isDirectory("_tmp"))
+
+  assert(fs.removeDirectory("_tmp/a"))
+  assert(fs.removeDirectory("_tmp"))
+  assert(not fs.isDirectory("_tmp/a"))
+  assert(not fs.isDirectory("_tmp"))
+end

From b7b4fd1f9763584606589254d307eebae9518a18 Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Mon, 8 Mar 2021 16:06:35 -0300
Subject: [PATCH 02/11] Update json.lua submodule

---
 .gitmodules      | 2 +-
 third_party/json | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitmodules b/.gitmodules
index c55277e57..cbba74050 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
 [submodule "third_party/json"]
 	path = third_party/json
-	url = https://github.com/rxi/json.lua
+	url = https://github.com/aseprite/json.lua
diff --git a/third_party/json b/third_party/json
index bee7ee343..dbf4b2dd2 160000
--- a/third_party/json
+++ b/third_party/json
@@ -1 +1 @@
-Subproject commit bee7ee3431133009a97257bde73da8a34e53c15c
+Subproject commit dbf4b2dd2eb7c23be2773c89eb059dadd6436f94

From 513d57a6b4db880f0cc1f908a24b0004c15e2e10 Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Mon, 8 Mar 2021 16:07:35 -0300
Subject: [PATCH 03/11] Include uname output in run-tests.sh

---
 run-tests.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/run-tests.sh b/run-tests.sh
index c04686469..4ad540d18 100755
--- a/run-tests.sh
+++ b/run-tests.sh
@@ -45,6 +45,7 @@ export ASEPRITE_USER_FOLDER=$t
 if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then
     echo ----------------------------------------------------------------------
     echo "Testing console..."
+    echo "uname=$(uname)"
 
     $ASEPRITE -b --script scripts/console_assert.lua >$t/tmp 2>$t/tmp_err
     ! grep -q "this should be in the output" $t/tmp && fail "print() text not found in output"

From 293f9170b6a1902939e2b3a7bda84f903174fbe8 Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Mon, 8 Mar 2021 16:28:55 -0300
Subject: [PATCH 04/11] Ignore MINGW64 uname

---
 run-tests.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/run-tests.sh b/run-tests.sh
index 4ad540d18..ca535ba20 100755
--- a/run-tests.sh
+++ b/run-tests.sh
@@ -33,7 +33,7 @@ if [[ "$filter" != "" ]]; then
 fi
 
 t=$(mktemp -d)
-if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then
+if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then
     PWDARG=-W
     t=$(cd "$t" && pwd $PWDARG)
 else
@@ -52,7 +52,7 @@ if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then
     ! grep -q "assertion failed" $t/tmp && fail "assert() text not found in output"
     grep -q "this should not be in the output" $t/tmp && fail "text that shouldn't be in the output is"
 
-    if [[ "$(uname)" =~ "MINGW32" ]] || [[ "$(uname)" =~ "MSYS_NT-10.0" ]] ; then
+    if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then
 	echo Ignore console tests on Windows
     else
 	$ASEPRITE -b --script scripts/console_print.lua >$t/tmp 2>$t/tmp_err

From 58235ac14dfd39b8879498049a7a84c9129de22e Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Mon, 8 Mar 2021 19:27:07 -0300
Subject: [PATCH 05/11] Try to fix comparing text lines on Windows

---
 run-tests.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/run-tests.sh b/run-tests.sh
index ca535ba20..c7f630de9 100755
--- a/run-tests.sh
+++ b/run-tests.sh
@@ -14,7 +14,7 @@ function fail() {
 }
 
 function expect() {
-    if [[ $1 != $($2) ]] ; then
+    if [[ $1 != "$($2 | tr -d "\r")" ]] ; then
 	echo "FAILED: $2"
 	echo "EXPECTED: $1"
 	echo "RESULT: $($2)"

From cb674e0bf25ca0b123f5bf4d20b9ffa10c0a3b49 Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Tue, 9 Mar 2021 09:20:28 -0300
Subject: [PATCH 06/11] Try to fix passing * as an argument in MINGW64 bash

It looks like '*' is being converted as a wildcard to list files in
the current dir, which doesn't happen in other platforms (?).
---
 cli/save-as.sh | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/cli/save-as.sh b/cli/save-as.sh
index a5f6ad8fe..3f54d99fd 100644
--- a/cli/save-as.sh
+++ b/cli/save-as.sh
@@ -1,5 +1,5 @@
 #! /bin/bash
-# Copyright (C) 2018-2019 Igara Studio S.A.
+# Copyright (C) 2018-2021 Igara Studio S.A.
 
 function list_files() {
     oldwd=$(pwd $PWDARG)
@@ -179,25 +179,25 @@ cd $oldwd
 
 d=$t/save-as-groups-and-hidden
 mkdir $d
-$ASEPRITE -b sprites/groups2.aseprite -layer '*' -save-as "$d/g2-all.png" || exit 1
-$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items -save-as "$d/g2-all-without-items.png" || exit 1
-$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer gun -save-as "$d/g2-all-without-gun1.png" || exit 1
-$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer sword -save-as "$d/g2-all-without-sword1.png" || exit 1
-$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items/gun -save-as "$d/g2-all-without-gun2.png" || exit 1
-$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer items/sword -save-as "$d/g2-all-without-sword2.png" || exit 1
-$ASEPRITE -b sprites/groups2.aseprite -layer '*' -ignore-layer player -save-as "$d/g2-all-without-player.png" || exit 1
+$ASEPRITE -b sprites/groups2.aseprite -layer \* -save-as "$d/g2-all.png" || exit 1
+$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer items -save-as "$d/g2-all-without-items.png" || exit 1
+$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer gun -save-as "$d/g2-all-without-gun1.png" || exit 1
+$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer sword -save-as "$d/g2-all-without-sword1.png" || exit 1
+$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer items/gun -save-as "$d/g2-all-without-gun2.png" || exit 1
+$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer items/sword -save-as "$d/g2-all-without-sword2.png" || exit 1
+$ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer player -save-as "$d/g2-all-without-player.png" || exit 1
 $ASEPRITE -b sprites/groups2.aseprite -layer player -save-as "$d/g2-player.png" || exit 1
 $ASEPRITE -b sprites/groups2.aseprite -layer items -save-as "$d/g2-items.png" || exit 1
-$ASEPRITE -b sprites/groups2.aseprite -layer 'items/*' -save-as "$d/g2-items-all.png" || exit 1
+$ASEPRITE -b sprites/groups2.aseprite -layer items/\* -save-as "$d/g2-items-all.png" || exit 1
 $ASEPRITE -b sprites/groups2.aseprite -layer sword -save-as "$d/g2-sword.png" || exit 1
 $ASEPRITE -b sprites/groups2.aseprite -layer gun -save-as "$d/g2-gun.png" || exit 1
 
 $ASEPRITE -b sprites/groups3abc.aseprite -layer a -save-as "$d/g3-a.png" || exit 1
 $ASEPRITE -b sprites/groups3abc.aseprite -layer b -save-as "$d/g3-b.png" || exit 1
 $ASEPRITE -b sprites/groups3abc.aseprite -layer c -save-as "$d/g3-c.png" || exit 1
-$ASEPRITE -b sprites/groups3abc.aseprite -layer 'a/*' -save-as "$d/g3-a-all.png" || exit 1
-$ASEPRITE -b sprites/groups3abc.aseprite -layer 'b/*' -save-as "$d/g3-b-all.png" || exit 1
-$ASEPRITE -b sprites/groups3abc.aseprite -layer 'c/*' -save-as "$d/g3-c-all.png" || exit 1
+$ASEPRITE -b sprites/groups3abc.aseprite -layer a/\* -save-as "$d/g3-a-all.png" || exit 1
+$ASEPRITE -b sprites/groups3abc.aseprite -layer b/\* -save-as "$d/g3-b-all.png" || exit 1
+$ASEPRITE -b sprites/groups3abc.aseprite -layer c/\* -save-as "$d/g3-c-all.png" || exit 1
 $ASEPRITE -b sprites/groups3abc.aseprite -layer a/a -save-as "$d/g3-aa.png" || exit 1
 $ASEPRITE -b sprites/groups3abc.aseprite -layer b/a -save-as "$d/g3-ba.png" || exit 1
 $ASEPRITE -b sprites/groups3abc.aseprite -layer c/a -save-as "$d/g3-ca.png" || exit 1

From eb8e12c94a9b1a9d2f70a8be630deb9bc729c3f3 Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Tue, 9 Mar 2021 09:59:02 -0300
Subject: [PATCH 07/11] Ignore failing test from save-as.sh on Windows

---
 cli/save-as.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cli/save-as.sh b/cli/save-as.sh
index 3f54d99fd..0063d13e0 100644
--- a/cli/save-as.sh
+++ b/cli/save-as.sh
@@ -177,6 +177,9 @@ cd $oldwd
 # --save-as group without showing hidden children
 # https://github.com/aseprite/aseprite/issues/2084#issuecomment-525835889
 
+if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then
+    # Ignore this test on Windows because we cannot give * as a parameter (?)
+else
 d=$t/save-as-groups-and-hidden
 mkdir $d
 $ASEPRITE -b sprites/groups2.aseprite -layer \* -save-as "$d/g2-all.png" || exit 1
@@ -249,3 +252,4 @@ expect_rendered_layers(img("g3-cb"), g3, { "c/b" })
 expect_rendered_layers(img("g3-cc"), g3, { "c/c" })
 EOF
 $ASEPRITE -b -script "$d/compare.lua" || exit 1
+fi

From 5018d156bdc87ec283494cdf2a1305cbe6cdc577 Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Tue, 9 Mar 2021 16:38:40 -0300
Subject: [PATCH 08/11] Fix syntax error in save-as.sh

---
 cli/save-as.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cli/save-as.sh b/cli/save-as.sh
index 0063d13e0..c8791ed36 100644
--- a/cli/save-as.sh
+++ b/cli/save-as.sh
@@ -179,6 +179,7 @@ cd $oldwd
 
 if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then
     # Ignore this test on Windows because we cannot give * as a parameter (?)
+    echo Do nothing
 else
 d=$t/save-as-groups-and-hidden
 mkdir $d

From 4bd7d8eb2168a0d8863f34773d0197fcacf5284f Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Wed, 7 Apr 2021 11:29:31 -0300
Subject: [PATCH 09/11] Update branch name of aseprite/aseprite repo

---
 README.md           | 6 +++---
 scripts/version.lua | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 5f0582a0f..0035a1783 100644
--- a/README.md
+++ b/README.md
@@ -4,14 +4,14 @@ Test suite for [Aseprite](https://github.com/aseprite/aseprite)
 to avoid breaking backward compatibility.
 
 This project is cloned by the
-[.travis.yml](https://github.com/aseprite/aseprite/blob/master/.travis.yml) file
+[build.yml](https://github.com/aseprite/aseprite/blob/main/.github/workflows/build.yml) file
 on Aseprite project to do several automated tests:
 
 * Save/load file formats correctly. For this we have `.aseprite`, `.png`,
-  `.gif`, etc. files [sprites](https://github.com/aseprite/tests/tree/master/sprites)
+  `.gif`, etc. files [sprites](https://github.com/aseprite/tests/tree/main/sprites)
   folder.
 * Test backward compatibility with [Aseprite CLI](https://www.aseprite.org/docs/cli/) options
-* Future [scripting API](https://github.com/aseprite/api) using [scripts](https://github.com/aseprite/tests/tree/master/scripts)
+* Future [scripting API](https://github.com/aseprite/api) using [scripts](https://github.com/aseprite/tests/tree/main/scripts)
 
 ## How to run tests?
 
diff --git a/scripts/version.lua b/scripts/version.lua
index 9137835c1..024b43b4b 100644
--- a/scripts/version.lua
+++ b/scripts/version.lua
@@ -1,4 +1,4 @@
--- Copyright (C) 2019  Igara Studio S.A.
+-- Copyright (C) 2019-2021  Igara Studio S.A.
 -- Copyright (C) 2018  David Capello
 --
 -- This file is released under the terms of the MIT license.
@@ -8,7 +8,7 @@ assert(string.sub(tostring(app.version), 1, 1) == "1")
 assert(string.sub(tostring(app.version), 2, 2) == ".")
 assert(app.version.major == 1)
 
--- We cannot test the specific app.version from the master branch
+-- We cannot test the specific app.version from the "main" branch
 -- because it's "1.x-dev" (which is converted to "1.0-dev" as Version object)
 --assert(app.version > Version("1.2.10-beta4"))
 

From ffb4397238344bd3d4844c11ce520b98e95d4ed9 Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Wed, 7 Apr 2021 12:57:24 -0300
Subject: [PATCH 10/11] Reset tool preferences just once when running from CLI

---
 LICENSE.txt                 |  2 +-
 scripts/app_preferences.lua | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/LICENSE.txt b/LICENSE.txt
index 73cdac56d..a1db71aea 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2018-2020 Igara Studio S.A.
+Copyright (c) 2018-2021 Igara Studio S.A.
 Copyright (c) 2018 David Capello
 
 Permission is hereby granted, free of charge, to any person obtaining
diff --git a/scripts/app_preferences.lua b/scripts/app_preferences.lua
index 9c2a96c4f..82cbe4286 100644
--- a/scripts/app_preferences.lua
+++ b/scripts/app_preferences.lua
@@ -1,10 +1,13 @@
--- Copyright (C) 2019  Igara Studio S.A.
+-- Copyright (C) 2019-2021  Igara Studio S.A.
 --
 -- This file is released under the terms of the MIT license.
 -- Read LICENSE.txt for more information.
 
 -- Preferences for tools
 do
+  -- The first time we get the tool preferences in CLI mode, we get
+  -- the default options for this tool (in GUI, we get the current
+  -- user-defined options).
   local t = app.preferences.tool('pencil')
   assert(t.opacity == 255)
   assert(t.tolerance == 0)
@@ -14,10 +17,10 @@ do
   t.brush.size = 2
   assert(t.brush.size == 2)
 
-  -- Getting the tool again will give us the default configuration
-  -- again in batch mode
+  -- Getting the tool again must give us the configuration that was
+  -- set inside the script
   t = app.preferences.tool('pencil')
-  assert(t.brush.size == 1)
+  assert(t.brush.size == 2)
 end
 
 -- Preferences for documents

From 3a63ec4cf013bca6f883e40f103039e967f4ba73 Mon Sep 17 00:00:00 2001
From: David Capello <david@igarastudio.com>
Date: Wed, 7 Apr 2021 13:02:27 -0300
Subject: [PATCH 11/11] Add tests for paint_bucket tool

---
 scripts/paint_bucket.lua | 55 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 scripts/paint_bucket.lua

diff --git a/scripts/paint_bucket.lua b/scripts/paint_bucket.lua
new file mode 100644
index 000000000..52276f617
--- /dev/null
+++ b/scripts/paint_bucket.lua
@@ -0,0 +1,55 @@
+-- Copyright (C) 2020-2021  Igara Studio S.A.
+--
+-- This file is released under the terms of the MIT license.
+-- Read LICENSE.txt for more information.
+
+dofile('./test_utils.lua')
+
+app.activeTool = 'paint_bucket'
+assert(app.activeTool.id == 'paint_bucket')
+assert(app.activeBrush.type == BrushType.CIRCLE)
+assert(app.activeBrush.size == 1)
+assert(app.activeBrush.angle == 0)
+assert(app.preferences.tool('paint_bucket').floodfill.pixel_connectivity == 0)
+
+local function test_paint_bucket(colorMode, a, b, c)
+  local spr = Sprite(4, 4, colorMode)
+  local img = app.activeImage
+
+  array_to_pixels({ a, a, a, a,
+                    a, b, b, a,
+                    a, a, b, a,
+                    a, a, a, b, }, img)
+
+  app.useTool{ points={Point(0, 0)}, color=b }
+  expect_img(img, { b, b, b, b,
+                    b, b, b, b,
+                    b, b, b, b,
+                    b, b, b, b, })
+
+  app.undo()
+  -- FOUR_CONNECTED=0
+  app.preferences.tool('paint_bucket').floodfill.pixel_connectivity = 0
+  assert(app.preferences.tool('paint_bucket').floodfill.pixel_connectivity == 0)
+  app.useTool{ points={Point(1, 1)}, color=c }
+  expect_img(img, { a, a, a, a,
+                    a, c, c, a,
+                    a, a, c, a,
+                    a, a, a, b, })
+
+  app.undo()
+  -- EIGHT_CONNECTED=1
+  app.preferences.tool('paint_bucket').floodfill.pixel_connectivity = 1
+  assert(app.preferences.tool('paint_bucket').floodfill.pixel_connectivity == 1)
+  app.useTool{ points={Point(1, 1)}, color=c }
+  expect_img(img, { a, a, a, a,
+                    a, c, c, a,
+                    a, a, c, a,
+                    a, a, a, c, })
+end
+
+local rgba = app.pixelColor.rgba
+local gray = app.pixelColor.graya
+test_paint_bucket(ColorMode.RGB, rgba(0, 0, 0), rgba(128, 128, 128), rgba(255, 255, 255))
+test_paint_bucket(ColorMode.GRAYSCALE, gray(0), gray(128), gray(255))
+test_paint_bucket(ColorMode.INDEXED, 1, 2, 3)