summaryrefslogtreecommitdiff
path: root/std/fs/copy_test.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-10-09 17:22:22 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-10-09 17:22:22 -0400
commit93f7f00c956c14620ef031626f124b57397ca867 (patch)
treec5a9f536e79d2c8d2d02897511a9138acaf35394 /std/fs/copy_test.ts
parent28293acd9c12a94f5d769706291032e844c7b92b (diff)
Run deno_std tests in github actions
Diffstat (limited to 'std/fs/copy_test.ts')
-rw-r--r--std/fs/copy_test.ts170
1 files changed, 89 insertions, 81 deletions
diff --git a/std/fs/copy_test.ts b/std/fs/copy_test.ts
index 347d2532c..a11838c4b 100644
--- a/std/fs/copy_test.ts
+++ b/std/fs/copy_test.ts
@@ -317,9 +317,11 @@ testCopySync(
(tempDir: string): void => {
const srcFile = path.join(testdataDir, "copy_file_not_exists_sync.txt");
const destFile = path.join(tempDir, "copy_file_not_exists_1_sync.txt");
- assertThrows((): void => {
- copySync(srcFile, destFile);
- });
+ assertThrows(
+ (): void => {
+ copySync(srcFile, destFile);
+ }
+ );
}
);
@@ -365,47 +367,50 @@ testCopySync(
}
);
-testCopySync("[fs] copy file synchronously", (tempDir: string): void => {
- const srcFile = path.join(testdataDir, "copy_file.txt");
- const destFile = path.join(tempDir, "copy_file_copy_sync.txt");
+testCopySync(
+ "[fs] copy file synchronously",
+ (tempDir: string): void => {
+ const srcFile = path.join(testdataDir, "copy_file.txt");
+ const destFile = path.join(tempDir, "copy_file_copy_sync.txt");
- const srcContent = new TextDecoder().decode(Deno.readFileSync(srcFile));
+ const srcContent = new TextDecoder().decode(Deno.readFileSync(srcFile));
- assertEquals(existsSync(srcFile), true);
- assertEquals(existsSync(destFile), false);
+ assertEquals(existsSync(srcFile), true);
+ assertEquals(existsSync(destFile), false);
- copySync(srcFile, destFile);
+ copySync(srcFile, destFile);
- assertEquals(existsSync(srcFile), true);
- assertEquals(existsSync(destFile), true);
+ assertEquals(existsSync(srcFile), true);
+ assertEquals(existsSync(destFile), true);
- const destContent = new TextDecoder().decode(Deno.readFileSync(destFile));
+ const destContent = new TextDecoder().decode(Deno.readFileSync(destFile));
- assertEquals(srcContent, destContent);
+ assertEquals(srcContent, destContent);
- // Copy again without overwrite option and it should throw an error.
- assertThrows(
- (): void => {
- copySync(srcFile, destFile);
- },
- Error,
- `'${destFile}' already exists.`
- );
+ // Copy again without overwrite option and it should throw an error.
+ assertThrows(
+ (): void => {
+ copySync(srcFile, destFile);
+ },
+ Error,
+ `'${destFile}' already exists.`
+ );
- // Modify destination file.
- Deno.writeFileSync(destFile, new TextEncoder().encode("txt copy"));
+ // Modify destination file.
+ Deno.writeFileSync(destFile, new TextEncoder().encode("txt copy"));
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(destFile)),
- "txt copy"
- );
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(destFile)),
+ "txt copy"
+ );
- // Copy again with overwrite option.
- copySync(srcFile, destFile, { overwrite: true });
+ // Copy again with overwrite option.
+ copySync(srcFile, destFile, { overwrite: true });
- // Make sure the file has been overwritten.
- assertEquals(new TextDecoder().decode(Deno.readFileSync(destFile)), "txt");
-});
+ // Make sure the file has been overwritten.
+ assertEquals(new TextDecoder().decode(Deno.readFileSync(destFile)), "txt");
+ }
+);
testCopySync(
"[fs] copy directory synchronously to its subdirectory",
@@ -445,54 +450,57 @@ testCopySync(
}
);
-testCopySync("[fs] copy directory synchronously", (tempDir: string): void => {
- const srcDir = path.join(testdataDir, "copy_dir");
- const destDir = path.join(tempDir, "copy_dir_copy_sync");
- const srcFile = path.join(srcDir, "0.txt");
- const destFile = path.join(destDir, "0.txt");
- const srcNestFile = path.join(srcDir, "nest", "0.txt");
- const destNestFile = path.join(destDir, "nest", "0.txt");
-
- copySync(srcDir, destDir);
-
- assertEquals(existsSync(destFile), true);
- assertEquals(existsSync(destNestFile), true);
-
- // After copy. The source and destination should have the same content.
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(srcFile)),
- new TextDecoder().decode(Deno.readFileSync(destFile))
- );
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(srcNestFile)),
- new TextDecoder().decode(Deno.readFileSync(destNestFile))
- );
-
- // Copy again without overwrite option and it should throw an error.
- assertThrows(
- (): void => {
- copySync(srcDir, destDir);
- },
- Error,
- `'${destDir}' already exists.`
- );
-
- // Modify the file in the destination directory.
- Deno.writeFileSync(destNestFile, new TextEncoder().encode("nest copy"));
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(destNestFile)),
- "nest copy"
- );
-
- // Copy again with overwrite option.
- copySync(srcDir, destDir, { overwrite: true });
-
- // Make sure the file has been overwritten.
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(destNestFile)),
- "nest"
- );
-});
+testCopySync(
+ "[fs] copy directory synchronously",
+ (tempDir: string): void => {
+ const srcDir = path.join(testdataDir, "copy_dir");
+ const destDir = path.join(tempDir, "copy_dir_copy_sync");
+ const srcFile = path.join(srcDir, "0.txt");
+ const destFile = path.join(destDir, "0.txt");
+ const srcNestFile = path.join(srcDir, "nest", "0.txt");
+ const destNestFile = path.join(destDir, "nest", "0.txt");
+
+ copySync(srcDir, destDir);
+
+ assertEquals(existsSync(destFile), true);
+ assertEquals(existsSync(destNestFile), true);
+
+ // After copy. The source and destination should have the same content.
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(srcFile)),
+ new TextDecoder().decode(Deno.readFileSync(destFile))
+ );
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(srcNestFile)),
+ new TextDecoder().decode(Deno.readFileSync(destNestFile))
+ );
+
+ // Copy again without overwrite option and it should throw an error.
+ assertThrows(
+ (): void => {
+ copySync(srcDir, destDir);
+ },
+ Error,
+ `'${destDir}' already exists.`
+ );
+
+ // Modify the file in the destination directory.
+ Deno.writeFileSync(destNestFile, new TextEncoder().encode("nest copy"));
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(destNestFile)),
+ "nest copy"
+ );
+
+ // Copy again with overwrite option.
+ copySync(srcDir, destDir, { overwrite: true });
+
+ // Make sure the file has been overwritten.
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(destNestFile)),
+ "nest"
+ );
+ }
+);
testCopySync(
"[fs] copy symlink file synchronously",