toBe('megabytes:579860 percent:97'); }); test('every filesystem is reported back to back without a path', function () { expect(ss_diskfree_parse(SS_DISKFREE_DF, false)) ->toBe('megabytes:579860 percent:97megabytes:815036 percent:1megabytes:45403568 percent:54'); }); test('df output without a filesystem line yields nothing', function () { expect(ss_diskfree_parse("Filesystem 1024-blocks Used Available Capacity Mounted on\n", true))->toBe('') ->and(ss_diskfree_parse('', false))->toBe(''); }); test('rejected paths return U instead of listing every filesystem', function (string $path) { expect(ss_diskfree_collect($path))->toBe(['megabytes:U percent:U', 1]) ->and(ss_diskfree($path))->toBe('megabytes:U percent:U'); })->with(['-h', '--total', '-', "/\0etc"]); test('shell metacharacters reach df as a plain path and match nothing', function (string $path) { expect(ss_diskfree_collect($path))->toBe(['', 1]) ->and(ss_diskfree($path))->toBe('megabytes:U percent:U'); })->with(['/nonexistent/;id', '/nonexistent/$(id)', '/nonexistent/a b', '/nonexistent/`id`']); test('a path with a space or colon is reported, as diskfree.sh reports it', function () { $dir = sys_get_temp_dir() . '/cacti df:' . getmypid() . ' +@'; mkdir($dir); try { [$output, $status] = ss_diskfree_collect($dir); expect($status)->toBe(0)->and($output)->toMatch('/^megabytes:\d+ percent:\d+$/'); } finally { rmdir($dir); } }); test('the root filesystem is reported on the running host', function () { [$output, $status] = ss_diskfree_collect('/'); expect($status)->toBe(0)->and($output)->toMatch('/^megabytes:\d+ percent:\d+$/'); }); test('a path that does not exist prints nothing, as the originals do', function () { expect(ss_diskfree_collect('/nonexistent/cacti/path'))->toBe(['', 1]) ->and(ss_diskfree('/nonexistent/cacti/path'))->toBe('megabytes:U percent:U'); });