diff --git a/.github/actions/automatic-test/action.yml b/.github/actions/automatic-test/action.yml new file mode 100644 index 00000000..4b5326cb --- /dev/null +++ b/.github/actions/automatic-test/action.yml @@ -0,0 +1,24 @@ +name: 'Automatic Test' +description: 'Check for obvious errors.' + +runs: + using: "composite" + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/build-love + with: + file-path: Techmino.love + - name: Download love + shell: bash + run: | + curl -L https://github.com/love2d/love/releases/download/11.3/love-11.3-linux-x86_64.tar.gz | tar xz + - name: Prepare PulseAudio + shell: bash + run: | + sudo apt-get update + sudo apt-get install pulseaudio pulseaudio-utils pavucontrol alsa-oss alsa-utils -y + - name: Run automated test + uses: GabrielBB/xvfb-action@v1 + with: + run: | + ./dest/love Techmino.love --test \ No newline at end of file diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 09f74b29..4fa0940d 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -27,6 +27,12 @@ jobs: echo "::set-output name=code::$(lua .github/workflows/getVersion.lua -code)" echo "::set-output name=commit::$(git rev-parse --short ${{ GITHUB.SHA }})" + automatic-test: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/automatic-test + build-windows: runs-on: windows-latest needs: get-info @@ -121,6 +127,7 @@ jobs: build-iOS: runs-on: macos-latest + if: (!startsWith( github.ref , 'refs/heads/ci-')) || startsWith( github.ref , 'refs/heads/ci-ios-') needs: get-info steps: - uses: actions/checkout@v2 diff --git a/Zframework/init.lua b/Zframework/init.lua index 665334e1..bf1594cc 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -9,6 +9,7 @@ TABLE= require'Zframework.tableExtend' STRING= require'Zframework.stringExtend' PROFILE= require'Zframework.profile' JSON= require'Zframework.json' +TESTING= require'Zframework.testing' do--Add pcall & MES for JSON lib local encode,decode=JSON.encode,JSON.decode JSON.encode=function(val) diff --git a/Zframework/testing.lua b/Zframework/testing.lua new file mode 100644 index 00000000..b7dd6a38 --- /dev/null +++ b/Zframework/testing.lua @@ -0,0 +1,13 @@ +--Utils for testing +local testing={} + +--Wait for the scene swapping animation to finish +function testing.switchSCN() + while SCN.swapping do YIELD()end +end + +function testing.sleep(frames) + for _=1,frames do YIELD()end +end + +return testing diff --git a/main.lua b/main.lua index bea20f93..ff4cbcff 100644 --- a/main.lua +++ b/main.lua @@ -590,24 +590,25 @@ for i=1,#_LOADTIMELIST_ do LOG(_LOADTIMELIST_[i])end if TABLE.find(arg,'--test')then TASK.new(function() + local switchSCN,sleep=TESTING.switchSCN,TESTING.sleep while not LOADED do YIELD()end print("\27[92m\27[1mAutomatic Test Started\27[0m") BGM.setVol(0)SFX.setVol(0) love.keypressed('space') - while SCN.swapping do YIELD()end + switchSCN() for k,mode in next,MODES do if k~='netBattle'then print("Scanning mode: "..mode.name) - loadGame(mode.name.."a",true) - while SCN.swapping do YIELD()end + loadGame(mode.name,true) + switchSCN() SCN.back() - while SCN.swapping do YIELD()end + switchSCN() end end print("\27[92m\27[1mAutomatic Test Passed :)\27[0m") - for _=1,60 do YIELD()end + sleep(60) love.event.quit(0) end) TASK.new(function() @@ -616,7 +617,7 @@ if TABLE.find(arg,'--test')then if ERRDATA[1]then break end end print("\27[91m\27[1mAutomatic Test Failed :(\27[0m\nThe error message is:\n"..table.concat(ERRDATA[1].mes,"\n").."\27[91m\nAborting\27[0m") - for _=1,60 do YIELD()end + TESTING.sleep(60) love.event.quit(1) end) end