diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-05-17 08:50:07 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-05-17 10:25:05 +0200 |
commit | 4ac26772681d74be2cbbf9376a02ebc395257c86 (patch) | |
tree | 16a140c9c245fbe1204c147ee6a6705dcb60601e | |
parent | c7930f132d1fff4fba0f8fbee6aa0edb38c40269 (diff) |
Initial test scripts and configuration
-rw-r--r-- | erebos-tester.yaml | 1 | ||||
-rw-r--r-- | minici.yaml | 10 | ||||
-rw-r--r-- | src/Command/Run.hs | 1 | ||||
-rw-r--r-- | src/Output.hs | 4 | ||||
-rw-r--r-- | test/asset/run/norepo-basic.yaml | 9 | ||||
-rw-r--r-- | test/asset/run/repo-basic.yaml | 7 | ||||
-rw-r--r-- | test/asset/run/repo-basic2.yaml | 15 | ||||
-rw-r--r-- | test/script/run.et | 73 |
8 files changed, 120 insertions, 0 deletions
diff --git a/erebos-tester.yaml b/erebos-tester.yaml new file mode 100644 index 0000000..2c75d7c --- /dev/null +++ b/erebos-tester.yaml @@ -0,0 +1 @@ +tests: test/script/**/*.et diff --git a/minici.yaml b/minici.yaml index a3f87f5..d08160d 100644 --- a/minici.yaml +++ b/minici.yaml @@ -1,3 +1,13 @@ job build: shell: - cabal build -fci + - mkdir build + - cp $(cabal list-bin minici) build/minici + artifact bin: + path: build/minici + +job test: + uses: + - build.bin + shell: + - EREBOS_TEST_TOOL='build/minici --test-output' erebos-tester --verbose diff --git a/src/Command/Run.hs b/src/Command/Run.hs index 6190236..09a814e 100644 --- a/src/Command/Run.hs +++ b/src/Command/Run.hs @@ -326,6 +326,7 @@ cmdRun (RunCommand RunOptions {..} args) = do loop [] =<< atomically (takeJobSource source) waitForJobs waitForJobs + outputEvent output $ TestMessage "run-finish" fitToLength :: Int -> Text -> Text diff --git a/src/Output.hs b/src/Output.hs index b4678f5..2dbaa3f 100644 --- a/src/Output.hs +++ b/src/Output.hs @@ -40,6 +40,7 @@ data OutputType data OutputEvent = OutputMessage Text + | TestMessage Text | JobStarted JobId | JobFinished JobId Text @@ -93,6 +94,9 @@ outputEvent out@Output {..} = liftIO . \case forM_ outLogs $ \h -> outStrLn out h msg forM_ outTest $ \h -> outStrLn out h ("msg " <> msg) + TestMessage msg -> do + forM_ outTest $ \h -> outStrLn out h msg + JobStarted jid -> do forM_ outLogs $ \h -> outStrLn out h ("Started " <> textJobId jid) forM_ outTest $ \h -> outStrLn out h ("job-start " <> textJobId jid) diff --git a/test/asset/run/norepo-basic.yaml b/test/asset/run/norepo-basic.yaml new file mode 100644 index 0000000..2000858 --- /dev/null +++ b/test/asset/run/norepo-basic.yaml @@ -0,0 +1,9 @@ +job success: + checkout: null + shell: + - "true" + +job failure: + checkout: null + shell: + - "false" diff --git a/test/asset/run/repo-basic.yaml b/test/asset/run/repo-basic.yaml new file mode 100644 index 0000000..82f5650 --- /dev/null +++ b/test/asset/run/repo-basic.yaml @@ -0,0 +1,7 @@ +job success: + shell: + - "true" + +job failure: + shell: + - "false" diff --git a/test/asset/run/repo-basic2.yaml b/test/asset/run/repo-basic2.yaml new file mode 100644 index 0000000..bcfac50 --- /dev/null +++ b/test/asset/run/repo-basic2.yaml @@ -0,0 +1,15 @@ +job success: + shell: + - "true" + +job third: + shell: + - "true" + +job failure: + shell: + - "false" + +job fourth: + shell: + - "true" diff --git a/test/script/run.et b/test/script/run.et new file mode 100644 index 0000000..4f4e016 --- /dev/null +++ b/test/script/run.et @@ -0,0 +1,73 @@ +module run + +asset scripts: + path: ../asset/run + +def expect_result from p of job result result: + let dummy = job == "" + expect from p: + /job-start $job/ + /job-finish $job ([a-z]+)/ capture done + guard (done == result) + + +test RunWithouRepo: + node n + spawn on n as p args [ "${scripts.path}/norepo-basic.yaml", "run", "success", "failure" ] + expect_result from p: + of "success" result "done" + of "failure" result "failed" + expect /(.*)/ from p capture done + guard (done == "run-finish") + + +test RunWithRepo: + node n + shell on n as git_init: + git -c init.defaultBranch=master init -q + git -c user.name=test -c user.email=test commit -q --allow-empty -m 'initial commit' + git rev-parse HEAD + cp "${scripts.path}/repo-basic.yaml" minici.yaml + git add minici.yaml + git -c user.name=test -c user.email=test commit -q -m 'basic1' + git rev-parse HEAD^{tree} + cp "${scripts.path}/repo-basic2.yaml" minici.yaml + git add minici.yaml + git -c user.name=test -c user.email=test commit -q -m 'basic1' + git rev-parse HEAD + git rev-parse HEAD^{tree} + + expect /([0-9a-f]+)/ from git_init capture c0 + expect /([0-9a-f]+)/ from git_init capture t1 + expect /([0-9a-f]+)/ from git_init capture c2 + expect /([0-9a-f]+)/ from git_init capture t2 + + local: + spawn on n as p args [ "run", "--range=$c0..$c2" ] + expect_result from p: + of "$t1.success" result "done" + of "$t1.failure" result "failed" + + of "$t2.success" result "done" + of "$t2.failure" result "failed" + of "$t2.third" result "done" + of "$t2.fourth" result "done" + + expect /(.*)/ from p capture done + guard (done == "run-finish") + + local: + spawn on n as p args [ "./minici.yaml", "run", "--range=$c0..$c2" ] + expect_result from p: + of "$t1.success" result "done" + of "$t1.failure" result "failed" + of "$t1.third" result "done" + of "$t1.fourth" result "done" + + of "$t2.success" result "done" + of "$t2.failure" result "failed" + of "$t2.third" result "done" + of "$t2.fourth" result "done" + + expect /(.*)/ from p capture done + guard (done == "run-finish") |