diff --git a/spec/execute_spec.lua b/spec/execute_spec.lua index 8fc46a6..dfcd705 100644 --- a/spec/execute_spec.lua +++ b/spec/execute_spec.lua @@ -8,7 +8,6 @@ describe('cp.execute', function() mock_system_calls = {} temp_files = {} - local original_system = vim.system vim.system = function(cmd, opts) table.insert(mock_system_calls, { cmd = cmd, opts = opts }) if not cmd or #cmd == 0 then @@ -52,7 +51,6 @@ describe('cp.execute', function() end, }) - local original_uv = vim.uv vim.uv = vim.tbl_extend('force', vim.uv or {}, { hrtime = function() return 1000000000 @@ -135,7 +133,7 @@ describe('cp.execute', function() end) it('handles compilation errors gracefully', function() - vim.system = function(cmd, opts) + vim.system = function() return { wait = function() return { code = 1, stderr = 'error: undefined variable' } @@ -218,7 +216,7 @@ describe('cp.execute', function() end) it('captures stderr output', function() - vim.system = function(cmd, opts) + vim.system = function() return { wait = function() return { code = 1, stdout = '', stderr = 'runtime error\n' } @@ -278,16 +276,10 @@ describe('cp.execute', function() describe('language detection', function() it('detects cpp from extension', function() -- This tests get_language_from_file indirectly - local contest_config = { - default_language = 'python', - } -- Mock the file extension detection - vim.fn.fnamemodify = function(path, modifier) - if modifier == ':e' and path == 'test.cpp' then - return 'cpp' - end - return '' + vim.fn.fnamemodify = function() + return 'cpp' end -- The actual function is local, but we can test it indirectly diff --git a/spec/integration_spec.lua b/spec/integration_spec.lua index 60f97db..86b9063 100644 --- a/spec/integration_spec.lua +++ b/spec/integration_spec.lua @@ -166,7 +166,7 @@ describe('cp integration', function() } temp_files['test.run'] = {} - vim.system = function(cmd, opts) + vim.system = function(cmd) return { wait = function() return { code = 0, stdout = '3\n', stderr = '' } @@ -200,7 +200,7 @@ describe('cp integration', function() end) it('handles scraper communication properly', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if cmd[1] == 'uv' and vim.tbl_contains(cmd, 'metadata') then return { wait = function() @@ -231,7 +231,7 @@ describe('cp integration', function() end) it('processes scraper output correctly', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if vim.tbl_contains(cmd, 'metadata') then return { wait = function() @@ -338,7 +338,7 @@ describe('cp integration', function() end) it('recovers from interrupted operations', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if vim.tbl_contains(cmd, 'metadata') then return { wait = function() @@ -393,7 +393,7 @@ describe('cp integration', function() end) it('maintains system stability on errors', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if vim.tbl_contains(cmd, 'metadata') then return { wait = function() @@ -422,7 +422,7 @@ describe('cp integration', function() table.insert(large_problems, { id = string.char(96 + i % 26), name = 'Problem ' .. i }) end - vim.system = function(cmd, opts) + vim.system = function(cmd) if vim.tbl_contains(cmd, 'metadata') then return { wait = function() @@ -462,7 +462,7 @@ describe('cp integration', function() it('maintains responsiveness during operations', function() local call_count = 0 - vim.system = function(cmd, opts) + vim.system = function(cmd) call_count = call_count + 1 vim.wait(10) return { diff --git a/spec/scraper_spec.lua b/spec/scraper_spec.lua index 5614fd7..d6c5f1d 100644 --- a/spec/scraper_spec.lua +++ b/spec/scraper_spec.lua @@ -17,7 +17,6 @@ describe('cp.scrape', function() mock_system_calls = {} - local original_system = vim.system vim.system = function(cmd, opts) table.insert(mock_system_calls, { cmd = cmd, opts = opts }) @@ -26,7 +25,7 @@ describe('cp.scrape', function() if cmd[1] == 'ping' then result = { code = 0 } elseif cmd[1] == 'uv' and cmd[2] == 'sync' then - result = { code = 0 } + result = { code = 0, stdout = '', stderr = '' } elseif cmd[1] == 'uv' and cmd[2] == 'run' then if vim.tbl_contains(cmd, 'metadata') then result.stdout = '{"success": true, "problems": [{"id": "a", "name": "Test Problem"}]}' @@ -124,10 +123,7 @@ describe('cp.scrape', function() describe('system dependency checks', function() it('handles missing uv executable', function() vim.fn.executable = function(cmd) - if cmd == 'uv' then - return 0 - end - return 1 + return cmd == 'uv' and 0 or 1 end local result = scrape.scrape_contest_metadata('atcoder', 'abc123') @@ -137,7 +133,7 @@ describe('cp.scrape', function() end) it('handles python environment setup failure', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if cmd[1] == 'ping' then return { wait = function() @@ -169,7 +165,7 @@ describe('cp.scrape', function() end) it('handles network connectivity issues', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if cmd[1] == 'ping' then return { wait = function() @@ -228,7 +224,7 @@ describe('cp.scrape', function() end) it('handles subprocess execution failure', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if cmd[1] == 'ping' then return { wait = function() @@ -259,7 +255,7 @@ describe('cp.scrape', function() describe('json parsing', function() it('handles invalid json output', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if cmd[1] == 'ping' then return { wait = function() @@ -287,7 +283,7 @@ describe('cp.scrape', function() end) it('handles scraper-reported failures', function() - vim.system = function(cmd, opts) + vim.system = function(cmd) if cmd[1] == 'ping' then return { wait = function()