From 82b0dd36d682b1b11260e05e8a5c6aeccb65c255 Mon Sep 17 00:00:00 2001
From: Denis Bilenko <denis.bilenko@databricks.com>
Date: Mon, 27 Jan 2025 09:17:22 +0100
Subject: [PATCH] Add acceptance/selftest, showcasing basic features (#2229)

Also make TestInprocessMode use this test.
---
 acceptance/README.md              |  2 ++
 acceptance/acceptance_test.go     |  7 +------
 acceptance/selftest/out.hello.txt |  1 +
 acceptance/selftest/output.txt    | 30 ++++++++++++++++++++++++++++++
 acceptance/selftest/script        | 21 +++++++++++++++++++++
 acceptance/selftest/test.toml     | 11 +++++++++++
 6 files changed, 66 insertions(+), 6 deletions(-)
 create mode 100644 acceptance/selftest/out.hello.txt
 create mode 100644 acceptance/selftest/output.txt
 create mode 100644 acceptance/selftest/script
 create mode 100644 acceptance/selftest/test.toml

diff --git a/acceptance/README.md b/acceptance/README.md
index 42a37d253..75ac1d5fc 100644
--- a/acceptance/README.md
+++ b/acceptance/README.md
@@ -17,3 +17,5 @@ For more complex tests one can also use:
 - `errcode` helper: if the command fails with non-zero code, it appends `Exit code: N` to the output but returns success to caller (bash), allowing continuation of script.
 - `trace` helper: prints the arguments before executing the command.
 - custom output files: redirect output to custom file (it must start with `out`), e.g. `$CLI bundle validate > out.txt 2> out.error.txt`.
+
+See [selftest](./selftest) for a toy test.
diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go
index 11fd3f2ee..6b70c6a7f 100644
--- a/acceptance/acceptance_test.go
+++ b/acceptance/acceptance_test.go
@@ -60,12 +60,7 @@ func TestInprocessMode(t *testing.T) {
 	if InprocessMode {
 		t.Skip("Already tested by TestAccept")
 	}
-	if runtime.GOOS == "windows" {
-		// -  catalogs                               A catalog is the first layer of Unity Catalog’s three-level namespace.
-		// +  catalogs                               A catalog is the first layer of Unity Catalog�s three-level namespace.
-		t.Skip("Fails on CI on unicode characters")
-	}
-	require.NotZero(t, testAccept(t, true, "help"))
+	require.Equal(t, 1, testAccept(t, true, "selftest"))
 }
 
 func testAccept(t *testing.T, InprocessMode bool, singleTest string) int {
diff --git a/acceptance/selftest/out.hello.txt b/acceptance/selftest/out.hello.txt
new file mode 100644
index 000000000..e427984d4
--- /dev/null
+++ b/acceptance/selftest/out.hello.txt
@@ -0,0 +1 @@
+HELLO
diff --git a/acceptance/selftest/output.txt b/acceptance/selftest/output.txt
new file mode 100644
index 000000000..d1830e01f
--- /dev/null
+++ b/acceptance/selftest/output.txt
@@ -0,0 +1,30 @@
+=== Capturing STDERR
+>>> python3 -c import sys; sys.stderr.write("STDERR\n")
+STDERR
+
+=== Capturing STDOUT
+>>> python3 -c import sys; sys.stderr.write("STDOUT\n")
+STDOUT
+
+=== Capturing exit code
+>>> errcode python3 -c raise SystemExit(5)
+
+Exit code: 5
+
+=== Capturing exit code (alt)
+>>> python3 -c raise SystemExit(7)
+
+Exit code: 7
+
+=== Capturing pwd
+>>> python3 -c import os; print(os.getcwd())
+$TMPDIR
+
+=== Capturing subdir
+>>> mkdir -p subdir/a/b/c
+
+>>> withdir subdir/a/b/c python3 -c import os; print(os.getcwd())
+$TMPDIR/subdir/a/b/c
+
+=== Custom output files - everything starting with out is captured and compared
+>>> echo HELLO
diff --git a/acceptance/selftest/script b/acceptance/selftest/script
new file mode 100644
index 000000000..89201d925
--- /dev/null
+++ b/acceptance/selftest/script
@@ -0,0 +1,21 @@
+printf "=== Capturing STDERR"
+trace python3 -c 'import sys; sys.stderr.write("STDERR\n")'
+
+printf "\n=== Capturing STDOUT"
+trace python3 -c 'import sys; sys.stderr.write("STDOUT\n")'
+
+printf "\n=== Capturing exit code"
+trace errcode python3 -c 'raise SystemExit(5)'
+
+printf "\n=== Capturing exit code (alt)"
+errcode trace python3 -c 'raise SystemExit(7)'
+
+printf "\n=== Capturing pwd"
+trace python3 -c 'import os; print(os.getcwd())'
+
+printf "\n=== Capturing subdir"
+trace mkdir -p subdir/a/b/c
+trace withdir subdir/a/b/c python3 -c 'import os; print(os.getcwd())' | sed 's/\\/\//g'
+
+printf "\n=== Custom output files - everything starting with out is captured and compared"
+trace echo HELLO > out.hello.txt
diff --git a/acceptance/selftest/test.toml b/acceptance/selftest/test.toml
new file mode 100644
index 000000000..d867a4fd7
--- /dev/null
+++ b/acceptance/selftest/test.toml
@@ -0,0 +1,11 @@
+# Badness = "Brief description of what's wrong with the test output, if anything"
+
+#[GOOS]
+# Disable on Windows
+#windows = false
+
+# Disable on Mac
+#mac = false
+
+# Disable on Linux
+#linux = false